We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Trees
- Array Pairs
Array Pairs
Array Pairs
Consider an array of integers, . Find and print the total number of pairs such that where .
Input Format
The first line contains an integer, , denoting the number of elements in the array.
The second line consists of space-separated integers describing the respective values of .
Constraints
Scoring
- for of the test cases.
- for of the test cases.
- for of the test cases.
Output Format
Print a long integer denoting the total number pairs satisfying where .
Sample Input
5
1 1 2 4 2
Sample Output
8
Explanation
There are eight pairs of indices satisfying the given criteria: , , , , , , , and . Thus, we print as our answer.