#K65337. Count Same Height Pairs
Count Same Height Pairs
Count Same Height Pairs
You are given a sequence of buildings with their respective heights. Your task is to determine the number of distinct pairs of buildings that have the same height.
Formally, given an integer \( N \) and a list of \( N \) integers \( h_1, h_2, \dots, h_N \), count the number of pairs \( (i, j) \) with \( 1 \leq i < j \leq N \) such that \( h_i = h_j \). This can be computed using the combination formula: if a certain height appears \( c \) times then it contributes \( \binom{c}{2} = \frac{c(c-1)}{2} \) pairs.
Input is provided via stdin and your answer should be printed to stdout.
inputFormat
The first line of input contains a single integer \( N \) representing the number of buildings. The second line contains \( N \) space-separated integers representing the heights of the buildings.
outputFormat
Output a single integer representing the number of distinct pairs of buildings that share the same height.
## sample6
3 3 3 2 2 1
4
</p>