/*
* @Description: 学生成绩排序
* @version:
* @Author:
* @Date: 2021-04-01 19:36:13
* @LastEditors: Please set LastEditors
* @LastEditTime: 2021-04-01 19:58:37
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
bool cmp(pair<string, int> a, pair<string, int> b)
{
if (a.second > b.second)
return true;
else if (a.second < b.second)
return false;
else if (a.second == b.second)
return a.first < b.first;
}
int main(void)
{
int n;
cin >> n;
vector<pair<string, int>> v;
for (int i = 0; i < n; i++)
{
string name;
int grade;
cin >> name >> grade;
v.push_back(pair<string, int>(name, grade));
}
sort(v.begin(), v.end(), cmp);
vector<int> count;
for (int i = 0; i < v.size(); i++)
{
if (i > 0 && v[i].second == v[i - 1].second)
{
count.push_back(v[i].second);
cout << i - count.size() + 1 << " " << v[i].first << endl;
continue;
}
else
count.erase(count.begin(), count.end());
cout << i + 1 << " " << v[i].first << endl;
}
system("pause");
return 0;
}