#include<stdio.h> struct chengji { int xuehao; int score; }; int main() { int n,temp1,temp2; scanf("%d",&n); struct chengji paiming[n]; for(int i=0;i<n;i++) { scanf("%d",&paiming[i].xuehao); scanf("%d",&paiming[i].score); } for(int k=0;k<n;k++) { for(int j=n-1;j>0;j--) { if(paiming[j].score<paiming[j-1].score) { temp2=paiming[j].score; paiming[j].score=paiming[j-1].score; paiming[j-1].score=temp2; temp1=paiming[j].xuehao; paiming[j].xuehao=paiming[j-1].xuehao; paiming[j-1].xuehao=temp1; } } } for(int k=0;k<n;k++) { for(int j=n-1;j>0;j--) { if(paiming[j].score==paiming[j-1].score) { if(paiming[j].xuehao<paiming[j-1].xuehao) { temp2=paiming[j].xuehao; paiming[j].xuehao=paiming[j-1].xuehao; paiming[j-1].xuehao=temp2; } } } } for(int i=0;i<n;i++) { printf("%d ",paiming[i].xuehao); printf("%d",paiming[i].score); printf("\n"); } return 0; }