A priority queue is a data structure which maintains a set $S$ of elements, each of with an associated value (key), and supports the following operations:

* $insert(S, k)$: insert an element $k$ into the set $S$
* $extractMax(S)$: remove and return the element of $S$ with the largest key



Write a program which performs the $insert(S, k)$ and $extractMax(S)$ operations to a priority queue $S$. The priority queue manages a set of integers, which are also keys for the priority.

Constraints

* The number of operations $\leq 2,000,000$
* $0 \leq k \leq 2,000,000,000$

Input

Multiple operations to the priority queue $S$ are given. Each operation is given by "insert $k$", "extract" or "end" in a line. Here, $k$ represents an integer element to be inserted to the priority queue.

The input ends with "end" operation.

Output

For each "extract" operation, print the element extracted from the priority queue $S$ in a line.

Example

Input

insert 8
insert 2
extract
insert 10
extract
insert 11
extract
extract
end


Output

8
10
11
2
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by zhangrunfeng on 2/19/20
 */
public class Main {
    class PriorityQueue {
        private int len;
        private List<Long> queArr;

        public PriorityQueue() {
            len = 0;
            queArr = new ArrayList<>();
        }

        public void insert(long val) {
            len++;
            queArr.add(val);

            int currIx = len - 1;
            while (currIx > 0) {
                int parIx = (currIx - 1) / 2;
                if (queArr.get(parIx) < val) {
                    queArr.set(currIx, queArr.get(parIx));
                    currIx = parIx;
                } else {
                    break;
                }
            }
            queArr.set(currIx, val);
        }

        public long extract() {
            long ans = queArr.get(0);
            queArr.set(0, queArr.get(len - 1));
            queArr.remove(len - 1);
            len--;

            if (len == 0) return ans;

            int currIx = 0;
            long desVal = queArr.get(0);
            while (currIx * 2 + 1 < len) {
                int leftChild = currIx * 2 + 1, rightChild = currIx * 2 + 2;
                if (rightChild < len && queArr.get(rightChild) > queArr.get(leftChild)) {
                    leftChild = rightChild;
                }

                if (desVal >= queArr.get(leftChild)) break;

                queArr.set(currIx, queArr.get(leftChild));
                currIx = leftChild;
            }
            queArr.set(currIx, desVal);
            return ans;
        }
    }

    public Main(Scanner sc) {
        PriorityQueue que = new PriorityQueue();
        while (true) {
            String str = sc.next();
            if (str.equals("insert")) {
                long val = sc.nextLong();
                que.insert(val);
            } else if (str.equals("extract")) {
                long val = que.extract();
                System.out.println(val);
            } else if (str.equals("end")) {
                break;
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
    }
}
