CPU Benchmarking
Time limit1sMemory limit1024 MB
Given ratios between consecutive sorted CPUs, compute the sum over all pairs (i<j) of the product of ratios from i to j, modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Math, Prefix sum, Array
- Solved
- No attempts yet
Problem
Yun sells computer parts at Uni-COM. He carries CPUs of various performance levels and wants to make a benchmark table so that customers can compare CPU performance easily.
Comparing every pair of CPUs directly is tedious, so Yun sorted the CPUs from lowest to highest performance and measured the performance ratio between neighboring CPUs. Then the performance difference between any other pair of CPUs can be computed easily. For example, for CPUs , if is times faster than and is times faster than , then is times faster than .
Using the measured data, Yun computed the performance difference for every pair of CPUs and wrote them in the benchmark table. Specifically, for every ordered pair with , he wrote how many times faster the -th CPU is than the -th CPU. Compute the sum of all the numbers Yun wrote in the table. The result can be large, so print it modulo .
Input
The first line gives the number of CPUs .
The second line gives positive integers , separated by spaces. The -th CPU's performance is times the -th CPU's performance.
Output
Print the sum of the numbers Yun wrote in the benchmark table, modulo .