#include <iostream> #include <vector> #include <algorithm> using namespace std; struct student{ int id; int grade; student(int a,int b):id(a),grade(b){}; }; bool mcmp(student a,student b){ if(a.grade!=b.grade) return a.grade<b.grade; else return a.id<b.id; } vector<student> v; int main() { int n; cin>>n; int r=n; while(n>0){ n--; int a,b; cin>>a>>b; v.push_back(student(a,b)); } sort(v.begin(), v.end(), mcmp); for(int i=0;i<v.size();i++){ cout<<v[i].id<<' '<<v[i].grade<<endl; } }