PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000241. Tổng độ tốt của mọi dãy con (GCD Goodness)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng độ tốt của mọi dãy con (GCD Goodness)

Tổng độ tốt của mọi dãy con (GCD Goodness)

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

For every nonempty subsequence selected by indices, define its goodness as (GCD of chosen elements) times (sum of chosen elements). Calculate the total goodness of all nonempty subsequences modulo 109+710^9+7.

Input

  • First line: integer nn.
  • Second line: nn array elements.

Output

Print the total goodness modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤20, 1≤ai≤1001\le n\le20,\ 1\le a_i\le100.
  • Subtask 2 (30 points): 1≤n≤3000, 1≤ai≤2⋅1041\le n\le3000,\ 1\le a_i\le2\cdot10^4.
  • Subtask 3 (50 points): 1≤n≤106, 1≤ai≤1061\le n\le10^6,\ 1\le a_i\le10^6.

Examples

Example 1

Input

4
2 4 6 9

Output

350

Explanation

Summing the goodness of all 15 nonempty subsequences gives 350.

Example 2

Input

1
5

Output

25

Explanation

The only nonempty subsequence is (5)(5), with goodness 5⋅5=255\cdot5=25.