stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const long long MAXN=200005,INF=2000000005,MOD=1e9+7;

long long n,X,Y;

long long a[MAXN],w[MAXN],c[MAXN],d[MAXN];

long long jc[MAXN],Inv[MAXN];

long long ksm(long long x,long long y)

{

	long long k=1;

	while(y)

	{

		if(y&1)

			k=(k*x)%MOD;

		x=(x*x)%MOD;

		y>>=1;

	}

	return k;

}

void Init()

{

	jc[0]=1;

	for(long long i=1;i<MAXN;i++)

		jc[i]=(jc[i-1]*i)%MOD;

	Inv[MAXN-1]=ksm(jc[MAXN-1],MOD-2);

	for(long long i=MAXN-2;i>=0;i--)

		Inv[i]=(Inv[i+1]*(i+1))%MOD;

}

int main()

{

	//freopen("colorball.in","r",stdin);

	//freopen("colorball.out","w",stdout);

	Init();

	scanf("%lld %lld %lld",&n,&X,&Y);

	for(long long i=0;i<=n;i++)

		c[i]=INF;

	for(long long i=1;i<=n;i++)

	{

		scanf("%lld %lld",&a[i],&w[i]);

		c[a[i]]=min(c[a[i]],w[i]);

	}

	long long MI=c[1]<c[2]?1:2,MC=c[1]<c[2]?2:1;

	for(long long i=3;i<=n;i++)

	{

		if(c[i]<c[MI])

		{

			MC=MI;

			MI=i;

		}

		else if(c[i]<c[MC])

			MC=i;

	}

	for(long long i=1;i<=n;i++)

		if(w[i]+c[a[i]]<=X)

			w[i]=c[a[i]];

	long long o=0;

	for(long long i=1;i<=n;i++)

		if((w[i]+c[MI]<=Y&&MI!=a[i])||(w[i]+c[MC]<=Y&&MC!=a[i]))

		{

			o++;

			d[a[i]]++;

		}

	long long ans=jc[o];

	for(long long i=1;i<=n;i++)

	{

		if(d[i])

			ans=(ans*Inv[d[i]])%MOD;

	}

	printf("%lld\n",ans);

	fclose(stdin);

	fclose(stdout);

}

// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cstdio>

#include <cstring>



typedef long long LL;



const int MAXN = 200000;

const int MOD = 1000000007;

const int INF = 1000000001;



int N, X, Y, C[MAXN + 5], W[MAXN + 5];



int Min[MAXN + 5], Cnt[MAXN + 5];



int Fac[MAXN + 5], Inv[MAXN + 5];



int Pow(int x, int y) {

	int ret = 1;

	while (y) {

		if (y & 1)

			ret = (LL)ret * x % MOD;

		y >>= 1;

		x = (LL)x * x % MOD;

	}

	return ret;

}



int main() {

	scanf("%d%d%d", &N, &X, &Y);

	Fac[0] = 1;

	for (int i = 1; i <= N; i++)

		Fac[i] = (LL)Fac[i - 1] * i % MOD;

	Inv[N] = Pow(Fac[N], MOD - 2);

	for (int i = N - 1; i >= 0; i--)

		Inv[i] = (LL)Inv[i + 1] * (i + 1) % MOD;

	for (int i = 0; i <= N; i++)

		Min[i] = INF;

	for (int i = 1; i <= N; i++) {

		scanf("%d%d", &C[i], &W[i]);

		Cnt[C[i]]++;

		Min[C[i]] = std::min(Min[C[i]], W[i]);

	}

	int fir = std::min_element(Min + 1, Min + N + 1) - Min, sec = 0;

	for (int i = 1; i <= N; i++)

		if (i != fir && Min[i] < Min[sec])

			sec = i;

	for (int i = 1; i <= N; i++) { // 对于每个球

		if (W[i] != Min[C[i]] && W[i] + Min[C[i]] <= X) // 内部就可以交换

			continue;

		if (C[i] != fir && W[i] + Min[fir] <= Y) // 可交换出去

			continue;

		if (C[i] == fir && W[i] + Min[sec] <= Y) // 可交换出去

			continue;

		Cnt[C[i]]--; // 该球无法移动

	}

	int tot = 0, Ans = 1;

	for (int i = 1; i <= N; i++) // 合并每个颜色的连通块

		if (Min[i] + Min[fir] <= Y)

			Ans = (LL)Ans * Inv[Cnt[i]] % MOD, tot += Cnt[i];

	printf("%d", (LL)Ans * Fac[tot] % MOD);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;



typedef struct P {

	int p, d;

	bool operator<(const P &r) {

		return d < r.d;

	}

} P;

int n, d[10001];

vector<P> v;



int main(){

	int p, d1, d2;

	while (cin >> n && n != 0) {

		v = vector<P>();

		for (int i = 0; i < n; i++) {

			cin >> p >> d1 >> d2;

			v.push_back({ p,d1 + d2 });

		}

		P m = v[0];

		for (int i = 1; i < v.size(); i++) {

			if (m < v[i]) {

				m = v[i];

			}

		}

		cout << m.p << " " << m.d << endl;

	}



	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <vector>

using namespace std;



typedef struct P {

	int p, d;

	bool operator<(const P &r) {

		return d < r.d;

	}

} P;

int n;;



int main(){

	int p, d1, d2;

	while (true) {

		scanf("%d", &n);

		if (n == 0) break;

		P m = { 0,-1 };

		P t;

		for (int i = 0; i < n; i++) {

			scanf("%d %d %d", &p, &d1, &d2);

			t = { p,d1 + d2 };

			if (m < t) {

				m = t;

			}

		}

		printf("%d %d\n", m.p, m.d);

	}



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;



typedef struct P {

	int p, d;

	bool operator<(const P &r) {

		return d < r.d;

	}

} P;

int n, d[10001], vm;

P v[10001];



int main(){

	int p, d1, d2;

	while (cin >> n && n != 0) {

		vm = 0;

		for (int i = 0; i < n; i++) {

			cin >> p >> d1 >> d2;

			v[vm++] = { p,d1 + d2 };

		}

		P m = v[0];

		for (int i = 1; i < vm; i++) {

			if (m < v[i]) {

				m = v[i];

			}

		}

		cout << m.p << " " << m.d << endl;

	}



	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <vector>

using namespace std;



typedef struct P {

	int p, d;

	bool operator<(const P &r) {

		return d < r.d;

	}

} P;

int n;;



int main(){

	int p, d1, d2;

	while (true) {

		scanf("%d", &n);

		if (n == 0) break;

		P m = { 0,-1 };

		P t;

		for (int i = 0; i < n; i++) {

			scanf("%d %d %d", &p, &d1, &d2);

			t = { p,d1 + d2 };

			if (m < t) {

				m = t;

			}

		}

		printf("%d %d\n", m.p, m.d);

	}



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;



typedef struct P {

	int p, d;

	bool operator<(const P &r) {

		return d < r.d;

	}

} P;

int n;;



int main(){

	int p, d1, d2;

	while (cin >> n && n != 0) {

		P m = { 0,-1 };

		P t;

		for (int i = 0; i < n; i++) {

			cin >> p >> d1 >> d2;

			t = { p,d1 + d2 };

			if (m < t) {

				m = t;

			}

		}

		cout << m.p << " " << m.d << endl;

	}



	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <vector>

using namespace std;



typedef struct P {

	int p, d;

	bool operator<(const P &r) {

		return d < r.d;

	}

} P;

int n;;



int main(){

	int p, d1, d2;

	while (true) {

		scanf("%d", &n);

		if (n == 0) break;

		P m = { 0,-1 };

		P t;

		for (int i = 0; i < n; i++) {

			scanf("%d %d %d", &p, &d1, &d2);

			t = { p,d1 + d2 };

			if (m < t) {

				m = t;

			}

		}

		printf("%d %d\n", m.p, m.d);

	}



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



int main(){

	int n;

	while(std::cin >> n, n){

		int max_p, max_d = 0;

		for(;n;n--){

			int p, d1, d2;

			std::cin >> p >> d1 >> d2;

			if(d1 + d2 > max_d)

				max_p = p, max_d = d1 + d2;

		}

		std::cout << max_p << " " << max_d << std::endl;

	}

}

// Optimized solution to the same problem (faster):
#include <cstdio>

main(){int n;while(scanf("%d", &n), n){int t, m = 0, p, a, b;for(;n;n--){scanf("%d%d%d",&p,&a,&b);if(a+b>m)t=p,m=a+b;}printf("%d %d\n",t,m);}}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



#define int long long



const int N=1e5+5;

int n,pset[N],lazy[N],ans[N];

vector<int> child[N];

vector< pair<int, pair<int,int> > > edge;



void joinset(int u, int v, int w){

    if(child[ pset[u] ].size() > child[ pset[v] ].size()) swap(u, v);

    int pau = pset[u];

    lazy[ pset[v] ] += w * (child[ pset[u] ].size());

    for(int cu : child[ pset[u] ]){

        ans[cu] += lazy[ pset[u] ] + w * child[ pset[v] ].size() - lazy[ pset[v] ];

    }

    for(int cu : child[ pset[u] ]) child[ pset[v] ].push_back(cu), pset[cu] = pset[v];

    child[ pau ].clear();

}



signed main(){

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>n;

    for(int i=1;i<n;++i){

        int u,v,w; cin>>u>>v>>w;

        edge.push_back(make_pair(w,make_pair(u,v)));

    }

    sort(edge.begin(), edge.end());



    for(int i=1;i<=n; ++i) pset[i] = i, child[i].push_back(i);



    for(int i = edge.size()-1; i >= 0; --i){

        joinset(edge[i].second.first, edge[i].second.second, edge[i].first);

    }



    for(int i = 1; i <= n; ++i) cout << ans[i] + lazy[ pset[i] ] << "\n";



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

struct edge{

	int u,v;

	long long w;

	edge(int a,int b,long long c):u(a),v(b),w(c){}

};

long long lazy[N],res[N];

int n,p[N];

vector<vector<int> > sets;

vector<edge> E;

bool cmp(edge &a,edge &b){

	return a.w<b.w;

}

void dsu(int i,int j,long long w){

	for(int k=0;k<sets[i].size();k++){

		res[sets[i][k]]+=lazy[i]-lazy[j]+w*sets[j].size();

		p[sets[i][k]]=j;

	}

	for(int k=0;k<sets[i].size();k++){

		sets[j].push_back(sets[i][k]);

	}

	sets[i].clear();

}

int main(){

	scanf("%d",&n);

	sets.assign(n+1,vector<int>());

	for(int i=1;i<=n;i++){

		p[i]=i;

		sets[i].push_back(i);

	}

	for(int i=1;i<n;i++){

		int u,v;

		long long w;

		cin>>u>>v>>w;

		E.push_back(edge(u,v,w));

	}

	sort(E.begin(),E.end(),cmp);

	reverse(E.begin(),E.end());

	for(int i=0;i<E.size();i++){

		int u=p[E[i].u];

		int v=p[E[i].v];

		int w=E[i].w;

		if(sets[u].size()>sets[v].size()){

			swap(u,v);

		}

		lazy[v]+=w*sets[u].size();

		dsu(u,v,w);

	}

	for(int i=1;i<=n;i++){

		cout<<res[i]+lazy[p[i]]<<"\n";

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<queue>

#include<cstring>

#include<string>

using namespace std;



int main()

{

	string op;

	int num;

	priority_queue<int>pq;

	while (cin >> op)

	{

		if (op == "end") break;

		if (op == "insert")

		{

			cin >> num;

			pq.push(num);

		}

		else if (op == "extract")

		{

			cout << pq.top() << endl;

			pq.pop();

		}

	}

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define N 2000005

#define INF 2000000010

int n = 0;

int a[N];

void swap(int *a, int *b){

    int t;

    t = *a;

    *a= *b;

    *b = t;

}

void maxHeapify(int i){

    int l = 2*i;

    int r = 2*i+1;

    int maxi = i;

    if(l <= n && a[l] > a[maxi]){

        maxi = l;

    }

    if(r <= n && a[r] > a[maxi]){

        maxi = r;

    }

    if(maxi != i){

        swap(&a[i], &a[maxi]);

        maxHeapify(maxi);

    }

}

void insert(int key){

    a[++n] = key;

    int temp = n;

    while(temp > 1 && a[temp/2] < key){

        swap(&a[temp], &a[temp/2]);

        temp /= 2;

    }

}

int extract(){

    if(n < 1) return 0;

    int res = a[1];

    a[1] = a[n--];

    maxHeapify(1);

    return res;

}

int main(){

    char s[10];

    int k;

    while(scanf("%s", s), strcmp(s, "end")){

        if(s[0] == 'i'){

            scanf("%d", &k);

            insert(k);

        }else if(s[0] == 'e'){

            int p = extract();

            printf("%d\n", p);

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstring>

#include <cstdio>

#include <algorithm>

using namespace  std;

const int N=2e6+5;

#define INFTY (1<<30)

int h,a[N];

void maxheapify(int i){

    int l,r,largest;

    l=2*i;

    r=2*i+1;

    if(l<=h&&a[l]>a[i]) largest=l;

    else largest=i;

    if(r<=h&&a[r]>a[largest]) largest=r;

    if(largest!=i){

        swap(a[i],a[largest]);

        maxheapify(largest);

    }

}

int extract(){

    int maxv;

    if(h<1) return -INFTY;

    maxv=a[1];

    a[1]=a[h--];

    maxheapify(1);

    return maxv;

}

void increasekey(int i,int key){

    if(key<a[i]) return;

    a[i]=key;

    while(i>1&&a[i/2]<a[i]){

        swap(a[i],a[i/2]);

        i/=2;

    }

}

void insert(int key){

    h++;

    a[h]=-INFTY;

    increasekey(h, key);

}

int main(){

    int key;

    char com[10];

    while(1){

        scanf("%s",com);

        if(com[0]=='e'&&com[1]=='n') break;

        if(com[0]=='i'){

            scanf("%d",&key);

            insert(key);

        }

        else

            printf("%d\n",extract());

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define N 2000005

#define INF 2000000010

int n = 0;

int a[N];

void swap(int *a, int *b){

    int t;

    t = *a;

    *a= *b;

    *b = t;

}

void maxHeapify(int i){

    int l = 2*i;

    int r = 2*i+1;

    int maxi = i;

    if(l <= n && a[l] > a[maxi]){

        maxi = l;

    }

    if(r <= n && a[r] > a[maxi]){

        maxi = r;

    }

    if(maxi != i){

        swap(&a[i], &a[maxi]);

        maxHeapify(maxi);

    }

}

void insert(int key){

    a[++n] = key;

    int temp = n;

    while(temp > 1 && a[temp/2] < key){

        swap(&a[temp], &a[temp/2]);

        temp /= 2;

    }

}

int extract(){

    if(n < 1) return 0;

    int res = a[1];

    a[1] = a[n--];

    maxHeapify(1);

    return res;

}

int main(){

    char s[10];

    int k;

    while(scanf("%s", s), strcmp(s, "end")){

        if(s[0] == 'i'){

            scanf("%d", &k);

            insert(k);

        }else if(s[0] == 'e'){

            int p = extract();

            printf("%d\n", p);

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <cmath>

#include <cstdlib>

using namespace std;



#define par(x) ((x)>>(1))

#define lc(x) ((x)<<(1))

#define rc(x) ((x)<<(1)|1)



const int MAX = 2000010;

int heap[MAX];

int len;

char cmd[10];



void shiftUp(int p) {

    int parent = par(p);

    if (parent>=1 && heap[parent]<heap[p]) {

        swap(heap[parent], heap[p]);

        shiftUp(parent);

    }

}



void shiftDown(int p) {

    int l = lc(p);

    int r = rc(p);

    int largest = p;

    if (l <= len && heap[l] > heap[p]) {

        largest = l;

    }

    if (r <= len && heap[r] > heap[largest]) {

        largest = r;

    }

    if (largest != p) {

        swap(heap[largest], heap[p]);

        shiftDown(largest);

    }

}



void insert(int x) {

    heap[++len] = x;

    shiftUp(len);

}



int pop() {

    int x = heap[1];

    swap(heap[1], heap[len]);

    len--;

    if (len > 0) {

        shiftDown(1);

    }

    return x;

}



int main() {

    //freopen("in.txt", "r", stdin);

    //freopen("out.txt", "w", stdout);

    len = 0;

    while (~scanf("%s", cmd)) {

        if (strcmp(cmd, "insert") == 0) {

            int num = 0;

            scanf("%d", &num);

            insert(num);

        } else if (strcmp(cmd, "extract") == 0) {

            printf("%d\n", pop());

        } else if (strcmp(cmd, "end") == 0) {

            break;

        }

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define N 2000005

#define INF 2000000010

int n = 0;

int a[N];

void swap(int *a, int *b){

    int t;

    t = *a;

    *a= *b;

    *b = t;

}

void maxHeapify(int i){

    int l = 2*i;

    int r = 2*i+1;

    int maxi = i;

    if(l <= n && a[l] > a[maxi]){

        maxi = l;

    }

    if(r <= n && a[r] > a[maxi]){

        maxi = r;

    }

    if(maxi != i){

        swap(&a[i], &a[maxi]);

        maxHeapify(maxi);

    }

}

void insert(int key){

    a[++n] = key;

    int temp = n;

    while(temp > 1 && a[temp/2] < key){

        swap(&a[temp], &a[temp/2]);

        temp /= 2;

    }

}

int extract(){

    if(n < 1) return 0;

    int res = a[1];

    a[1] = a[n--];

    maxHeapify(1);

    return res;

}

int main(){

    char s[10];

    int k;

    while(scanf("%s", s), strcmp(s, "end")){

        if(s[0] == 'i'){

            scanf("%d", &k);

            insert(k);

        }else if(s[0] == 'e'){

            int p = extract();

            printf("%d\n", p);

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#if debug

#include<iostream>



using namespace std;

int H=0;

int A[2000000+2];



void maxHeapify(int i){

	int l=2*i;

	int r=2*i+1;

	int largest;

	if(l<=H&&A[l]>A[i]){

		largest=l;

	}

	else

		largest=i;

	if(r<=H&&A[r]>A[i])

			largest=i;

	if(largest!=i){

		swap(A[largest],A[i]);

		maxHeapify(largest);

	}

}



int extract(){

	int maxv;

	if(H<1) return -1e9;

	maxv=A[1];

	A[1]=A[H--];

	maxHeapify(1);

	return maxv;

}



void increaseKey(int i,int key){

	if(key<A[i]) return;

	A[i]=key;

	while(i>1&&A[i/2]<A[i]){

		swap(A[i/2],A[i]);

		i/=2;

	}

}



void insert(int key){

	H++;

	A[H]=-1e9;

	increaseKey(H,key);	

}

#include<string>

int main(){

	int key;

	string s;

	while(cin>>s){

		if(s=="insert"){

			cin>>key;

			insert(key);

		}

		else if(s=="extract"){

			cout<<extract()<<endl;

		}

		else 

			break;

	}

	return 0;

}

#endif



#include<iostream>

#include<queue>

using namespace std;



int main(){

	char s[20];

	priority_queue<int> que;

	while(1){

		cin>>s;

		if(s[0]=='e'&&s[1]=='n') break;

		if(s[0]=='i'){

			int key;

			cin>>key;

			que.push(key);

		}

		else if(s[0]=='e'){

			cout<<que.top()<<endl;

			que.pop();

		}

	}

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define N 2000005

#define INF 2000000010

int n = 0;

int a[N];

void swap(int *a, int *b){

    int t;

    t = *a;

    *a= *b;

    *b = t;

}

void maxHeapify(int i){

    int l = 2*i;

    int r = 2*i+1;

    int maxi = i;

    if(l <= n && a[l] > a[maxi]){

        maxi = l;

    }

    if(r <= n && a[r] > a[maxi]){

        maxi = r;

    }

    if(maxi != i){

        swap(&a[i], &a[maxi]);

        maxHeapify(maxi);

    }

}

void insert(int key){

    a[++n] = key;

    int temp = n;

    while(temp > 1 && a[temp/2] < key){

        swap(&a[temp], &a[temp/2]);

        temp /= 2;

    }

}

int extract(){

    if(n < 1) return 0;

    int res = a[1];

    a[1] = a[n--];

    maxHeapify(1);

    return res;

}

int main(){

    char s[10];

    int k;

    while(scanf("%s", s), strcmp(s, "end")){

        if(s[0] == 'i'){

            scanf("%d", &k);

            insert(k);

        }else if(s[0] == 'e'){

            int p = extract();

            printf("%d\n", p);

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int maxn=2*1e6+5;

#define INF (1<<30)

int H,a[maxn];



void maxHeapify(int i)

{

    int l,r,tmp;

    l=i*2,r=l+1;

    if(l<=H&&a[l]>a[i]) tmp=l;

    else tmp=i;

    if(r<=H&&a[r]>a[tmp]) tmp=r;

    if(tmp!=i){

        swap(a[tmp],a[i]);

        maxHeapify(tmp);

    }

}



int extract()

{

    int maxv;

    if(H<1) return -INF;

    maxv=a[1];

    a[1]=a[H--];

    maxHeapify(1);

    return maxv;

}

void increaseKey(int i,int key)

{

    if(key<a[i]) return;

    a[i]=key;

    while(i>1&&a[i/2]<a[i]){

        swap(a[i],a[i/2]);

        i=i/2;

    }

}



void insert(int key)

{

    H++;

    a[H]=-INF;

    increaseKey(H,key);

}



int main()

{

    H=0;

    int key;

    char com[10];

    while(1){

        scanf("%s",com);

        if(com[0]=='e'&&com[1]=='n') break;

        if(com[0]=='i'){

            cin>>key;

            insert(key);

        }else{

            cout<<extract()<<endl;

        }

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define N 2000005

#define INF 2000000010

int n = 0;

int a[N];

void swap(int *a, int *b){

    int t;

    t = *a;

    *a= *b;

    *b = t;

}

void maxHeapify(int i){

    int l = 2*i;

    int r = 2*i+1;

    int maxi = i;

    if(l <= n && a[l] > a[maxi]){

        maxi = l;

    }

    if(r <= n && a[r] > a[maxi]){

        maxi = r;

    }

    if(maxi != i){

        swap(&a[i], &a[maxi]);

        maxHeapify(maxi);

    }

}

void insert(int key){

    a[++n] = key;

    int temp = n;

    while(temp > 1 && a[temp/2] < key){

        swap(&a[temp], &a[temp/2]);

        temp /= 2;

    }

}

int extract(){

    if(n < 1) return 0;

    int res = a[1];

    a[1] = a[n--];

    maxHeapify(1);

    return res;

}

int main(){

    char s[10];

    int k;

    while(scanf("%s", s), strcmp(s, "end")){

        if(s[0] == 'i'){

            scanf("%d", &k);

            insert(k);

        }else if(s[0] == 'e'){

            int p = extract();

            printf("%d\n", p);

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include<queue>

#include<cstdio>

using namespace std;

int main()

{

    int key;

    char s[1001];

    priority_queue<int>PQ;

    while(1){

            scanf("%s",s);

        if(s[0]=='i'){

            scanf("%d\n",&key);

            PQ.push(key);

        }else if(s[0]=='e'&&s[1]=='x'){

            printf("%d\n",PQ.top());

            PQ.pop();

        }else{

        break;

        }

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define N 2000005

#define INF 2000000010

int n = 0;

int a[N];

void swap(int *a, int *b){

    int t;

    t = *a;

    *a= *b;

    *b = t;

}

void maxHeapify(int i){

    int l = 2*i;

    int r = 2*i+1;

    int maxi = i;

    if(l <= n && a[l] > a[maxi]){

        maxi = l;

    }

    if(r <= n && a[r] > a[maxi]){

        maxi = r;

    }

    if(maxi != i){

        swap(&a[i], &a[maxi]);

        maxHeapify(maxi);

    }

}

void insert(int key){

    a[++n] = key;

    int temp = n;

    while(temp > 1 && a[temp/2] < key){

        swap(&a[temp], &a[temp/2]);

        temp /= 2;

    }

}

int extract(){

    if(n < 1) return 0;

    int res = a[1];

    a[1] = a[n--];

    maxHeapify(1);

    return res;

}

int main(){

    char s[10];

    int k;

    while(scanf("%s", s), strcmp(s, "end")){

        if(s[0] == 'i'){

            scanf("%d", &k);

            insert(k);

        }else if(s[0] == 'e'){

            int p = extract();

            printf("%d\n", p);

        }

    }

    return 0;

}


// Fastest known solution for this problem: