#K55462. Counting Good Pairs
Counting Good Pairs
Counting Good Pairs
You are given an array of n integers. A pair of indices \((i, j)\) is called good if \(i < j\) and \(a_i = a_j\). Your task is to count the total number of good pairs in the array.
Mathematical Formulation:
Find the number of pairs \((i, j)\) such that
$$i < j \quad \text{and} \quad a_i = a_j.$$
Example:
Input: 6 1 2 3 1 1 3 Output: 4
inputFormat
The first line contains a single integer n, the number of elements in the array.
The second line contains n space-separated integers representing the elements of the array.
outputFormat
Print a single integer representing the total number of good pairs in the array.
## sample6
1 2 3 1 1 3
4
</p>