Update frequency of A [ i ]
if ( frequency . ContainsKey ( A [ i ] ) ) { frequency [ A [ i ] ] = frequency [ A [ i ] ] + 1 ; } else { frequency . Add ( A [ i ] , 1 ) ; } } foreach ( KeyValuePair < int , int > it in frequency ) {