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