Element Swapping
Time Limit: 1 Second Memory Limit: 65536 KB
DreamGrid has an integer sequence a 1 , a 2 , a 3 , … , a n a_1,a_2,a_3,\dots,a_n a1,a2,a3,…,an and he likes it very much. Unfortunately, his naughty roommate BaoBao swapped two elements a i a_i ai and a j a_j aj ( 1 ≤ i < j ≤ n ) (1 \le i < j \le n) (1≤i<j≤n) in the sequence when DreamGrid wasn’t at home. When DreamGrid comes back, he finds with dismay that his precious sequence has been changed into a 1 , a 2 , … , a i − 1 , a j , a i + 1 , … , a j − 1 , a i , a j + 1 , … , a n a_1,a_2,\dots,a_{i-1},a_j,a_{i+1},\dots,a_{j-1},a_i,a_{j+1},\dots,a_n a1,a2,…,ai−1,aj,ai+1,…,aj−1,ai,aj+1,…,an
What’s worse is that DreamGrid cannot remember his precious sequence. What he only remembers are the two values
x = ∑ k = 1 n k a k and y = ∑ k = 1 n k a k 2 \ x = \sum_{k=1}^nka_k \qquad \text{and} \qquad y = \sum_{k=1}^nka_k^2 x=∑k=1nkakandy=∑k=1nkak2
Given the sequence after swapping and the two values DreamGrid remembers, please help DreamGrid count the number of possible element pairs ( a i , a j ) (a_i,a_j) (ai,aj) BaoBao swaps.
Note that as DreamGrid is poor at memorizing numbers, the value of or might not match the sequence, and no possible element pair can be found in this situation.
Two element pairs ( a i , a j ) ( 1 ≤ i < j ≤ n ) (a_i,a_j)(1 \le i < j \le n) (ai,aj)(1≤i<j≤n) and