Be Geeks!

Time limit2sMemory limit512 MB

Summary
Sum gcd(a_i..a_j) * max(a_i..a_j) over all subarrays, modulo 1e9+7, with N up to 2e5.
Level

Hard9 of 10

Topics
Math, Number theory, Divide and conquer, Dynamic programming
Solved
No attempts yet

Problem

The musical band Be Geeks! did not get its name by accident, since every member is a genuine math geek. Among other things, they love examining various properties of number sequences. Here is one example of a subject that interests them.

  • Let AA be a nonempty sequence of positive integers, A=(a1,a2,…,aN)A = (a_1, a_2, \ldots, a_N).
  • Let G(i,j)=gcd⁡(ai,ai+1,…,aj)G(i, j) = \gcd(a_i, a_{i+1}, \ldots, a_j), where 1≤i≤j≤N1 \le i \le j \le N.
  • Let M(i,j)=max⁡(ai,ai+1,…,aj)M(i, j) = \max(a_i, a_{i+1}, \ldots, a_j), where 1≤i≤j≤N1 \le i \le j \le N.
  • Let P(i,j)=G(i,j)⋅M(i,j)P(i, j) = G(i, j) \cdot M(i, j), where 1≤i≤j≤N1 \le i \le j \le N.
  • Let F(A)=∑P(i,j)F(A) = \sum P(i, j), where the sum runs over all integer pairs 1≤i≤j≤N1 \le i \le j \le N.

The function gcd⁡\gcd stands for the greatest common divisor of the given values. The greatest common divisor of a nonempty sequence of integers is the largest integer that divides every integer in the sequence evenly.

Input

The first line contains one integer NN (1≤N≤2⋅1051 \le N \le 2 \cdot 10^5). The next line contains NN integers a1,a2,…,aNa_1, a_2, \ldots, a_N (1≤ai≤1091 \le a_i \le 10^9).

Output

Print the value of F(A)F(A) modulo 1 000 000 0071\,000\,000\,007.

Examples2

  1. Example 1

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

    Input
    5
    2 4 6 12 3
    
    Expected output
    457