#include <bits/stdc++.h> using namespace std; typedef struct PIS{ int mo; int b; string in_num; friend bool operator<(PIS s1, PIS s2){ if (s1.mo < s2.mo){ return true; } else if(s1.mo == s2.mo){ if (s1.b > s2.b){ return true; } else{ return false; } } else{ return false; } } }PIS; priority_queue<PIS> num_i; int main(){ int n; while (cin >> n){ while (n --){ string str; cin >> str; if (str == "Pop") { if (num_i.empty()){ puts("empty"); continue; } auto t = num_i.top(); num_i.pop(); cout << t.in_num << endl; printf("SIZE = %d\n", num_i.size()); } else if (str == "Insert"){ string in_num; vector<int> t_mo; int res = 0; cin >> in_num; for (int i=0; i<in_num.size(); i++){ if (isdigit(in_num[i])){ int j=i, x=0; while (j < in_num.size() && isdigit(in_num[j])){ x = x * 10 + (in_num[j]-'0'); j++; } i = j - 1; // cout << x << endl; t_mo.push_back(x); } } for (auto item: t_mo){ res += item * item; } num_i.push({res, t_mo[1], in_num}); printf("SIZE = %d\n", num_i.size()); } } } return 0; }