This page is still under construction.

Parts of this page are still being built. What you see may change.

CPU Benchmarking

Time limit1sMemory limit1024 MB

Summary
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 X,Y,ZX, Y, Z, if XX is aa times faster than YY and YY is bb times faster than ZZ, then XX is abab times faster than ZZ.

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 (i,j)(i, j) with 1≤i<j≤N1\le i<j\le N, he wrote how many times faster the jj-th CPU is than the ii-th CPU. Compute the sum of all the numbers Yun wrote in the table. The result can be large, so print it modulo 109+710^9+7.

Input

The first line gives the number of CPUs NN.

The second line gives N−1N-1 positive integers mim_i, separated by spaces. The (i+1)(i+1)-th CPU's performance is mim_i times the ii-th CPU's performance.

Output

Print the sum of the numbers Yun wrote in the benchmark table, modulo 109+710^9+7.

Constraints

  • 2≤N≤500,0002 \le N \le 500,000
  • 1≤mi<1091 \le m_i < 10^9

Examples3

  1. Example 1

    Input
    4
    1 2 3
    
    Expected output
    20
    
  2. Example 2

    Input
    4
    2 2 4
    
    Expected output
    36
    
  3. Example 3

    Input
    5
    973408385 513124519 802361288 816371495
    
    Expected output
    157603704