Map is used to store the count of elements present in the array
for ( int i = 0 ; i < n ; i ++ ) if ( m . ContainsKey ( a [ i ] ) ) { var v = m [ a [ i ] ] ; m . Remove ( a [ i ] ) ; m . Add ( a [ i ] , v + 1 ) ; } else m . Add ( a [ i ] , 1 ) ;