#include <bits/stdc++.h>
using namespace std;
struct peo
{
string name;
int k;
peo(string s, int a)
{
name = s;
k = a;
}
};
struct cmp
{
bool operator()(const peo &p1, const peo &p2)
{
return p1.k < p2.k;
}
};
priority_queue<peo, vector<peo>, cmp> pq;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
string s, name;
cin >> n;
while (n--)
{
cin >> s;
if (s == "pop")
{
if (pq.empty())
cout << "none\n";
else
{
cout << pq.top().name << " " << pq.top().k << "\n";
pq.pop();
}
}
else
{
cin >> name >> k;
pq.push(peo(name, k));
}
}
return 0;
}