P16249 [Lanqiao Cup 2026 NOI Qualifier Postgraduate Group] Evaluation Vulnerability
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 $x$ and $y$ 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, $a_i$ and $a_j$ (where $i < 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 $n$ test parameters from the current crashing testdata, and arranged them in the input order as $a_1, a_2, \ldots, a_n$. Now he needs you to help count how many index pairs $(i, j)$ in this sequence satisfy $1 \le i < j \le n$ and will trigger the above exception.
Input Format
The first line contains an integer $n$, which represents the total number of test parameters.
The second line contains $n$ integers $a_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.
Explanation/Hint
### Constraints and Notes
For $40\%$ of the test cases, $2 \le n \le 1000$.
For all test cases, $2 \le n \le 10^5$, $-10^9 \le a_i \le 10^9$.
Translated by ChatGPT 5