/**************************************************
 *
 *
 *
 *
 *
 **************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void swapNode(int H[], int i, int j){
  int tmp=H[i];
  H[i]=H[j];
  H[j]=tmp;
}
void maxHeapify(int H[], int size, int node){
  int left=2*node, right=2*node+1;
  int largest;  
  if((left<=size)&&(H[left]>H[node]))
	largest=left;
  else 
	largest=node;
  if((right<=size)&&(H[right]>H[largest]))
	largest=right;
  if(largest!=node){
	swapNode(H, largest, node);
	maxHeapify(H, size, largest);
  }
}
void buildMaxheap(int H[], int size){
  int i;
  for(i=size/2; i>0; --i){
	maxHeapify(H, size, i);
  }
}
void increseKey(int Q[], int size, int x, int key){
  if(Q[x]>key)
	return;
  else{
	Q[x]=key;
	while((x>1)&&(Q[x/2]<Q[x])){
	  swapNode(Q, x, x/2);
	  x=x/2;
	}
  }
}
void insert(int Q[], int *size, int key){
  ++(*size);
  Q[*size]=-1;
  increseKey(Q, *size, *size, key);
}
int extractMax(int Q[], int *size){
  int max=Q[1];
  swapNode(Q, 1, *size);
  --(*size);
  maxHeapify(Q, *size, 1);
  return max;
}
void print(int Q[], int size){
  int i;
  printf("queue: ");
  for(i=1; i<=size; ++i){
	printf("%d ", Q[i]);
  }
  
  printf("\n");
  printf("size: %d\n", size);
}
int main(){
  char line[100];
  int key;
  char *str_ptr;
  int priorityQueue[2000005];
   int queueSize=0;
   int max;
   while(1){
	fgets(line, sizeof(line), stdin);
	if(	line[strlen(line)-1]=='\n')
	  line[strlen(line)-1]='\0';
	str_ptr=strtok(line, " ");
	if(strcmp(str_ptr, "end")==0)
	  break;
	if(strcmp(str_ptr, "extract")==0){
	  max=extractMax(priorityQueue, &queueSize);
	  printf("%d\n", max);
	}
	if(strcmp(str_ptr, "insert")==0){
	  str_ptr=strtok(NULL, " ");
	  sscanf(str_ptr, "%d", &key);
	  insert(priorityQueue, &queueSize, key);
	}
	if(strcmp(str_ptr, "print")==0)
	  print(priorityQueue, queueSize);
  }
  return 0;
}

