文件目录

/*#include <iostream>
#include <algorithm>
using namespace std;
struct student{
    string name;
    int score;
} s[50];
int n;
bool cmp(student a,student b){
    if(a.score==b.score) return a.name<b.name;
    return a.score>b.score;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>s[i].name>>s[i].score;
    sort(s+1,s+n+1,cmp);
    for(int i=1;i<=n;i++) cout<<s[i].name<<" "<<s[i].score<<endl;
    return 0;
}*/

#include <iostream>
using namespace std;
int main()
{
    string name[50];
    int score[50];
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> name[i] >> score[i];
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j < n; j++)
        {
            if (score[j] < score[j + 1] || name[j] > name[j + 1] && score[j] == score[j + 1])
            {
                swap(name[j], name[j + 1]);
                swap(score[j], score[j + 1]);
            }
        }
    }
    for (int i = 1; i <= n; i++)
        cout << name[i] << " " << score[i] << endl;
    return 0;
}