#include <stdio.h>
#include <stdlib.h>

int left(int);
int right(int);
void maxHeapify(int*,int);
void buildMaxHeap(int*);
void insert(int*,int);
void extract(int*);

int h=0;

int main(){
  int i,k,*A;
  char s[10];

  A = (int *)malloc(sizeof(int)*2000000);

  while(1){
    scanf("%s",s);
    if(s[0]=='e'){
      if(s[1]=='n') break;
      else if(s[1]=='x') extract(A);
    }
    else if(s[0]=='i'){
      scanf("%d",&k);
      insert(A,k);
    }
    
    buildMaxHeap(A);
    for(i=1;i<=h;i++) printf(" %d",A[i]);
    printf("\n");
  }


  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

void maxHeapify(int* A,int i){
  int l,r,largest,tmp;
  
  l = left(i);
  r = right(i);

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

  if(r<=h && A[r]>A[largest]) largest = r;
  
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A,largest);
  }

  return;
}

void buildMaxHeap(int* A){
  int i;
  
  for(i=h/2;i>0;i--) maxHeapify(A,i);
  return;
}

void insert(int* A,int k){
  h++;
  A[h]=k;
  return;
}

void extract(int* A){
  int max;
  printf("%d\n",A[1]);
  A[1]=A[h];
  h--;
  return;
}