#include <stdio.h>

#define N 2000000
#define M 1000000


void insert(int *, int);
int extractMax(int *);
void maxHeapify(int *, int);
void buildMaxHeap(int *);

int n=1;


int main(){

  int k,i,c=0;
  int S[M];
  char com[10];

  S[1]=NULL;

  while(1){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&k);
      insert(S,k);
    }
    else if(com[1]=='x') printf("%d\n",extractMax(S));
    else break;
  }

  return 0;
}


void insert(int *S, int k){

  int i;

    S[n]=k;
    n++;

    buildMaxHeap(S);
    
    printf("%d ",n-1);
    for(i=1 ; i<n ; i++){
      printf("%d ",S[i]);
    }
    printf("\n");
    
}


int extractMax(int *S){

  int val,i;

  val=S[1];

 for(i=1; i<n ; i++){
   S[i]=S[i+1];
 }
  
 n--;

  return val;

}

void maxHeapify(int *A, int i){
int l,r,largest,temp;

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

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

  if(r<n && A[r]>A[largest]) largest=r;

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;

    maxHeapify(A, largest);  
  }

}


void buildMaxHeap(int *A){
  int i;

  for(i=n/2 ; i>=1 ; i--){
    maxHeapify(A, i);
  }
}