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

#GL0000376. Bộ bốn GCD bằng LCM (GCD <-> LCM)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bộ bốn GCD bằng LCM (GCD <-> LCM)

GCD <-> LCM

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n, an ordered quadruple (i,j,k,l)(i,j,k,l) is valid if:

  • All four indices lie in [1,n][1,n] and are pairwise distinct.
  • gcd⁡(ai,aj)=lcm⁡(ak,al)\gcd(a_i,a_j)=\operatorname{lcm}(a_k,a_l).

Different index orders count separately: (1,2,3,4)(1,2,3,4) and (2,1,3,4)(2,1,3,4) represent two different quadruples. Equal values are permitted, but positions must never be reused within a quadruple.

Count all valid quadruples modulo 109+710^9+7.

PHOJ file convention: The original problem contains multiple test cases per execution. This edition places exactly one instance per .in file and removes the initial tt line; the online judge manages test files separately.

Input

The first line contains nn. The second line contains nn integers a1,…,ana_1,\ldots,a_n.

Output

Print the number of valid ordered quadruples modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 4≤n≤84\le n\le8, 1≤ai≤n1\le a_i\le n.

  • Subtask 2 (30 points): 4≤n≤3 0004\le n\le3\,000, 1≤ai≤n1\le a_i\le n.

  • Subtask 3 (50 points): 4≤n≤100 0004\le n\le100\,000, 1≤ai≤n1\le a_i\le n.

Examples

Example 1

Input

4
4 3 1 1

Output

4

Explanation

Only the pair of values 4,34,3 has GCD 11 while the other two positions 1,11,1 have LCM 11. Each ordered pair has two orientations, giving 2⋅2=42\cdot2=4.

Example 2

Input

6
2 2 2 2 3 5

Output

24

Explanation

The four occurrences of value 22 can be placed in the four ordered positions in 4!=244!=24 ways. The values 3,53,5 produce no additional valid quadruples.