Get the unique values in list
for ( auto p : m ) { vals . push_back ( p . first ) ; } int res = INT_MAX ; for ( int i = 0 ; i < vals . size ( ) ; ++ i ) { vector < int > vec ( m [ vals [ i ] ] . begin ( ) , m [ vals [ i ] ] . end ( ) ) ;