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

#SP0000233. Ba chiếc ghế (Three Chairs)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ba chiếc ghế (Three Chairs)

Three Chairs

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Kira has nn friends. Friend ii has height aia_i, and all heights are distinct. Kira has only three chairs, so he wants to invite a group of exactly three different friends.

A group is valid if the smallest and largest heights in that group are coprime, that is, their greatest common divisor is 11. There is no additional restriction on the middle height.

Count the valid groups of exactly three friends. Groups are different if their sets of friends differ; seating order does not count.

Input

Line 1 contains nn. Line 2 contains exactly nn pairwise distinct integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the number of valid groups of three friends.

Subtasks

  • Subtask 1 (20 points): 3≤n≤93\le n\le9; 1≤ai≤301\le a_i\le30 for all ii; all aia_i distinct.

  • Subtask 2 (30 points): 3≤n≤20003\le n\le2000; 1≤ai≤1051\le a_i\le10^5 for all ii; all aia_i distinct.

  • Subtask 3 (50 points): 3≤n≤3⋅1053\le n\le3\cdot10^5; 1≤ai≤3⋅1051\le a_i\le3\cdot10^5 for all ii; all aia_i distinct.

Examples

Input

4
1 6 2 3

Output

3

Explanation

The heights 1,6,2,31,6,2,3 sorted are 1,2,3,61,2,3,6. The four triples are (1,2,3)(1,2,3), (1,2,6)(1,2,6), (1,3,6)(1,3,6), and (2,3,6)(2,3,6). Their extreme-height gcds are 1,1,1,21,1,1,2, respectively. Exactly three triples are valid, so print 33.