iterate through each element and increment the count ( Notice that every pair is counted twice )
for ( int i = 0 ; i < n ; i ++ ) { if ( hm [ sum - arr [ i ] ] != 0 ) { twice_count += hm [ sum - arr [ i ] ] ; }