#include<iostream> #include<algorithm> using namespace std; struct node { string id; int age; int number; }a[101]; bool cmp(node x,node y) { if(x.age==y.age) { if(x.number>y.number) return 1; else return 0; } else if(x.age>y.age) { if(x.age>=60) return 1; else { if(x.number>y.number) return 1; else return 0; } } else { if(y.age>=60) return 0; else { if(x.number>y.number) return 1; else return 0; } } } int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i].id>>a[i].age; a[i].number=i; } sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) { cout<<a[i].id<<'\n'; } return 0; }