#include<iostream> #include<algorithm> using namespace std; typedef struct { int number; int grade; }student; bool comp(student left,student right) { if (left.grade < right.grade) { return true; } else if (left.grade > right.grade) { return false; } else if (left.number < right.number) { return true; } else return false; } int main() { int n,p,q; cin >> n; student array[101]; for (int i =0; i <n; i++) { scanf("%d %d", &array[i].number, &array[i].grade); } sort(array,array+n,comp); for (int i = 0; i < n; i++) { printf("%d %d\n", array[i].number,array[i].grade); } return 0; }