Create map for each element
Dictionary < int , int > map = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < MAXN ; ++ i ) map . Add ( i , 0 ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( map . ContainsKey ( arr [ i ] ) ) { map [ arr [ i ] ] = 1 ; } else { map . Add ( arr [ i ] , 1 ) ; } } int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int num = arr [ i ] ;