Function to return the count of valid pairs
int countPairs ( int a [ ] , int n ) { int count = 0 ; unordered_map < int , int > m ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) {