#P16249. [蓝桥杯 2026 省研究生组] 评测漏洞

[蓝桥杯 2026 省研究生组] 评测漏洞

Problem Description

"The judge is stuck again!" Xiao Lan frowned and stared at the evaluation error log on the screen.

After careful investigation, he found a hidden vulnerability in the checking logic of the judging system: when the system reads two parameters xx and yy in order, if the combination of these two numbers satisfies a certain arithmetic property, it will cause a memory overflow and then trigger an abnormal termination.

Specifically, if two parameters that appear in order, aia_i and aja_j (where i<ji < j), satisfy the following equation, the system will crash:

$$\begin{aligned} (a_i + a_j)^2 = a_i + a_j \end{aligned}$$

To fix this vulnerability, Xiao Lan exported all nn test parameters from the current crashing testdata, and arranged them in the input order as a1,a2,…,ana_1, a_2, \ldots, a_n. Now he needs you to help count how many index pairs (i,j)(i, j) in this sequence satisfy 1≤i<j≤n1 \le i < j \le n and will trigger the above exception.

Input Format

The first line contains an integer nn, which represents the total number of test parameters.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, which represent the parameter values read in order.

Output Format

Output one integer, which represents the number of parameter pairs that can trigger the exception.

4
-1 0 1 2
3

Hint

Constraints and Notes

For 40%40\% of the test cases, 2≤n≤10002 \le n \le 1000.

For all test cases, 2≤n≤1052 \le n \le 10^5, −109≤ai≤109-10^9 \le a_i \le 10^9.

Translated by ChatGPT 5