map count stores count of s .
map < int , int > count ; for ( int i = 0 ; i < n ; i ++ ) count [ arr [ i ] ] ++ ; vector < pair < int , int > > count_vector ; map < int , int > :: iterator it ; for ( it = count . begin ( ) ; it != count . end ( ) ; it ++ ) { count_vector . pb ( mp ( it -> first , it -> second ) ) ; }