This page is still under construction.

Parts of this page are still being built. What you see may change.

Making a Square

Interview

Time limit2sMemory limit512 MB

Summary
Given n distinct positive integers, count ordered pairs (i, j) such that a_i^2 + a_j is a perfect square.
Level

Medium6 of 10

Topics
Math, Number theory, Hash map, Brute force
Solved
No attempts yet

Problem

You are given an array aa of nn distinct positive integers. Find the number of pairs (i,j)(i, j) with 1≤i,j≤n1 \le i, j \le n for which ai2+aja_i^2 + a_j is a square of an integer.

Input

The first line of the input contains a single integer nn (1≤n≤1061 \le n \le 10^6), the size of the array.

The second line of the input contains nn distinct positive integers a1,…,ana_1, \ldots, a_n (1≤ai≤1061 \le a_i \le 10^6).

Output

Output a single integer: the answer to the problem.

Hint

In the example, there are two such pairs, corresponding to 12+3=4=221^2 + 3 = 4 = 2^2 and 22+5=9=322^2 + 5 = 9 = 3^2.

Examples1

  1. Example 1

    Input
    5
    1 2 3 4 5
    
    Expected output
    2