// set::key_comp
#include <iostream>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main ()
{
  std::set<int> myset;
  int highest1, highest2, highest3;
  typedef map<int, int> MyMap;
  MyMap mymap;
  
  std::set<int>::key_compare   myCompKeyForSet = myset.key_comp();
  std::set<int>::value_compare myCompValForSet = myset.value_comp();
  
  MyMap::key_compare   myCompKeyForMap = mymap.key_comp();
  MyMap::value_compare myCompValForMap = mymap.value_comp();

  
  for (int i=0; i<=5; i++) {
      myset.insert(i);
      mymap.insert(make_pair(i, 2*i));
  }

  //////SET///////

  highest1=*myset.rbegin();
  std::set<int>::iterator it=myset.begin();
  while ( myCompKeyForSet(*it, highest1) ) it++;
  std::cout << "\nhighest1 is " << highest1;
  
  
  highest2 = *myset.rbegin();
  it=myset.begin();
  while ( myCompValForSet(*it, highest2) ) it++;
  std::cout << "\nhighest2 is " << highest2;

  //////MAP///////
  
  MyMap::iterator it2 = mymap.begin();
  highest3 = mymap.rbegin()->first;
  while ( myCompKeyForMap((it2->first), highest3) ) it2++;
  std::cout << "\nhighest3 is " << highest3;
  
  std::pair<int,int> highest4 = *mymap.rbegin();
  it2 = mymap.begin();
  while ( myCompValForMap(*(it2), highest4) ) it2++;
  std::cout << "\nhighest4 is " << highest4.second;

  return 0;
}