package main
import (
"strconv"
"bufio"
"container/heap"
"os"
"fmt"
)
type MaxHeap []int
func (h MaxHeap) Len() int {
return len(h)
}
func (h MaxHeap) Less(i,j int) bool {
return h[i] > h[j]
}
func (h MaxHeap) Swap(i,j int) {
h[i],h[j] = h[j],h[i]
}
func (h *MaxHeap) Push(x interface{}) {
*h = append(*h, x.(int))
}
func (h *MaxHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
(*h) = old[:n-1]
return x
}
func (h *MaxHeap) Top() interface{} {
return (*h)[0]
}
func main() {
h := &MaxHeap{}
heap.Init(h)
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
var n int
fmt.Fscan(in, &n)
for i := 1;i<=n;i++{
var op string
var val int
fmt.Fscan(in, &op)
switch op {
case "push":
fmt.Fscan(in, &val)
heap.Push(h, val)
case "pop":
if len(*h) == 0 {
out.WriteString("empty")
} else {
str := strconv.Itoa(heap.Pop(h).(int))
out.WriteString(str)
}
out.WriteRune('\n')
case "top":
if len(*h) == 0 {
out.WriteString("empty")
} else {
str := strconv.Itoa(h.Top().(int))
out.WriteString(str)
}
out.WriteRune('\n')
}
}
out.Flush()
}