#K74592. Count Equal Pairs
Count Equal Pairs
Count Equal Pairs
In this problem, you are given an integer array (a) of length (n). Your task is to count the number of pairs ((i,j)) such that (i < j) and (a_i = a_j). In other words, for every pair of indices where the first index is strictly less than the second, check if the corresponding elements are equal. The answer is the sum over each unique value of (\binom{\text{frequency}}{2}), computed as (\frac{frequency \times (frequency-1)}{2}).
inputFormat
The first line contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers representing the array elements.
outputFormat
Output a single integer representing the number of pairs ((i,j)) where (i < j) and (a_i = a_j).## sample
4
1 2 3 1
1