cswork / OAOpen practice workspace

AmazonOA #383

Rice Bags

Estimated MediumJudge-ready

Topics (AI-labelled)HashingBits & Math

All bags have pairwise distinct rice counts. Choose at least two bags such that, after sorting in ascending order, the square of each item equals exactly the next item. Return the maximum number of bags that can be chosen, or −1 if there is no solution.

Input

The first line contains n, and the second line contains n distinct integers. The original bounds 1≤n≤200000 and 2≤riceBags[i]≤10^6 are restored; the incorrect constraint spliced together by HTML cleanup must not be used.

Output

Output a single integer answer.

Example 1

Input:

3
2 4 16

Output:

3

Example 2

Input:

3
2 3 5

Output:

-1

Example 3

Input:

2
1000 1000000

Output:

2

Example notes

The outputs of the three public examples are, in order: 3; -1; 2. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…