$heap = []
def max_heapify(index)
  left = index * 2
  right = index * 2 + 1
  if left < $heap.length && $heap[left] > $heap[index]
    largest = left
  else
    largest = index
  end
  largest = right if right < $heap.length && $heap[right] > $heap[largest]

  unless largest == index
    $heap[index], $heap[largest] = $heap[largest], $heap[index]
    max_heapify largest
  end
end

def extract_max
  max = $heap[0]
  $heap[0] = $heap.pop
  max_heapify 1
  max
end

def insert(key)
  $heap << key
  i = $heap.length
  while i > 1 && !$heap[i / 2 - 1].nil? && $heap[i / 2 - 1] < $heap[i - 1]
    $heap[i / 2 - 1] , $heap[i - 1] = $heap[i - 1] , $heap[i / 2 - 1]
    i /= 2
  end
end

loop do
  input = gets.split ' '
  case input[0]
  when 'insert'
    insert input[1].to_i
  when 'extract'
    puts extract_max
  when 'end'
    break
  end
end

