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

