All possible third elements
for ( k = j + 1 ; k < n ; k ++ ) if ( m . containsKey ( a [ k ] ) ) { m . put ( a [ k ] , m . get ( a [ k ] ) + 1 ) ; } else { m . put ( a [ k ] , 1 ) ; } int twice_count = 0 ;