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

#GL0000232. Đếm cặp có tích là số chính phương (Square Pair)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm cặp có tích là số chính phương (Square Pair)

Đếm cặp có tích là số chính phương (Square Pair)

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given nonnegative integers, count pairs i<ji<j for which the product aiaja_i a_j is a perfect square. Zero is a perfect square.

Input

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

Output

Print the number of qualifying pairs.

Subtasks

  • Subtask 1 (20 points): 2≤n≤20, 0≤ai≤1002\le n\le20,\ 0\le a_i\le100.
  • Subtask 2 (30 points): 2≤n≤3000, 0≤ai≤50002\le n\le3000,\ 0\le a_i\le5000.
  • Subtask 3 (50 points): 2≤n≤2⋅105, 0≤ai≤2⋅1052\le n\le2\cdot10^5,\ 0\le a_i\le2\cdot10^5.

Examples

Example 1

Input

5
0 3 2 8 12

Output

6

Explanation

Four valid pairs contain zero, and the other two satisfy 3⋅12=363\cdot12=36 and 2⋅8=162\cdot8=16.

Example 2

Input

8
2 2 4 6 3 100 100 25

Output

7

Explanation

Pairs with equal squarefree kernels, taking zero into account, contribute the answer.