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

#GL0000237. Tổng ƯCLN của hai số nhỏ nhất (Small GCD)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng ƯCLN của hai số nhỏ nhất (Small GCD)

Tổng ƯCLN của hai số nhỏ nhất (Small GCD)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

For each triple of distinct indices i<j<ki<j<k, sort the three values, take the GCD of the two smallest, and sum over all triples. No modulus is applied.

Input

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

Output

Print the exact sum without a modulus.

Subtasks

  • Subtask 1 (20 points): 3≤n≤20, 1≤ai≤1003\le n\le20,\ 1\le a_i\le100.
  • Subtask 2 (30 points): 3≤n≤3000, 1≤ai≤50003\le n\le3000,\ 1\le a_i\le5000.
  • Subtask 3 (50 points): 3≤n≤8⋅104, 1≤ai≤1053\le n\le8\cdot10^4,\ 1\le a_i\le10^5.

Examples

Example 1

Input

5
2 3 6 12 17

Output

24

Explanation

Summing the GCD of the two smallest numbers over all ten triples gives 24.

Example 2

Input

3
2 4 8

Output

2

Explanation

The only triple has two smallest values 2 and 4, whose GCD is 2.