#C10777. Count Good Pairs
Count Good Pairs
Count Good Pairs
You are given an array of integers. Your task is to count the number of good pairs in the array. A pair of indices \( (i, j) \) is called a good pair if:
- \( nums[i] = nums[j] \)
- \( i < j \)
For example, consider the array [1, 2, 3, 1, 1, 3]
. There are 4 good pairs: \( (0, 3) \), \( (0, 4) \), \( (3, 4) \), and \( (2, 5) \). Your program should output the total number of such pairs.
inputFormat
The input is given from stdin
and consists of two lines:
- The first line contains an integer \( n \), the number of elements in the array.
- The second line contains \( n \) integers separated by spaces.
If \( n = 0 \), then the second line will be empty.
outputFormat
Output to stdout
a single integer representing the number of good pairs in the array.
6
1 2 3 1 1 3
4