/**
 *  _           _                 __                            _   _ _   _                                 _                    _                  _
 * | |         | |               / /                           | | (_) | (_)                               | |                  (_)                | |
 * | |__   __ _| |_ ___   ___   / /__ ___  _ __ ___  _ __   ___| |_ _| |_ ___   _____ ______ _ __ _   _ ___| |_ ______ ___ _ __  _ _ __  _ __   ___| |_ ___
 * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __|
 * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) |  __/ |_| | |_| |\ V /  __/      | |  | |_| \__ \ |_       \__ \ | | | | |_) | |_) |  __/ |_\__ \
 * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___|      |_|   \__,_|___/\__|      |___/_| |_|_| .__/| .__/ \___|\__|___/
 *                                                  | |                                                                           | |   | |
 *                                                  |_|                                                                           |_|   |_|
 *
 * https://github.com/hatoo/competitive-rust-snippets
 */
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

#[derive(Debug, Clone)]
struct SkewHeapNode<T: Ord> {
    v: T,
    l: SkewHeap<T>,
    r: SkewHeap<T>,
    length: usize,
}
#[derive(Debug, Clone)]
pub struct SkewHeap<T: Ord>(Option<Box<SkewHeapNode<T>>>);
impl<T: Ord> SkewHeapNode<T> {
    fn swap(&mut self) {
        let &mut SkewHeapNode {
            ref mut l,
            ref mut r,
            ..
        } = self;
        std::mem::swap(l, r);
    }
    fn divide(self) -> (T, SkewHeap<T>, SkewHeap<T>) {
        let SkewHeapNode { v, l, r, .. } = self;
        (v, l, r)
    }
}
impl<T: Ord> SkewHeap<T> {
    pub fn new() -> SkewHeap<T> {
        SkewHeap(None)
    }
    pub fn is_empty(&self) -> bool {
        self.0.is_none()
    }
    pub fn len(&self) -> usize {
        self.0.as_ref().map(|n| n.length).unwrap_or(0)
    }
    pub fn meld(&mut self, mut other: SkewHeap<T>) {
        if other.0.is_none() {
            return;
        }
        if self.0.is_none() {
            *self = other;
            return;
        }
        if self.0.as_ref().unwrap().as_ref().v < other.0.as_ref().unwrap().as_ref().v {
            std::mem::swap(self, &mut other);
        }
        if let Some(ref mut node) = self.0.as_mut() {
            node.length += other.0.as_ref().unwrap().length;
            node.r.meld(other);
            node.swap();
        }
    }
    pub fn push(&mut self, x: T) {
        let n = SkewHeap(Some(Box::new(SkewHeapNode {
            v: x,
            l: SkewHeap::new(),
            r: SkewHeap::new(),
            length: 1,
        })));
        self.meld(n);
    }
    pub fn pop(&mut self) -> Option<T> {
        if let Some(node) = self.0.take() {
            let (v, mut l, r) = node.divide();
            l.meld(r);
            *self = l;
            Some(v)
        } else {
            None
        }
    }
    pub fn peek(&self) -> Option<&T> {
        self.0.as_ref().map(|node| &node.v)
    }
}

#[allow(dead_code)]
fn main() {
    let mut heap = SkewHeap::new();

    util::with_bufwriter(|mut out| {
        let mut line = String::new();
        loop {
            line.clear();
            stdin().read_line(&mut line).unwrap();
            let mut split = line.split_whitespace();
            let command = split.next();

            if command == Some("end") {
                break;
            } else if command == Some("extract") {
                writeln!(out, "{}", heap.pop().unwrap()).unwrap();
            } else {
                let x: u64 = split.next().unwrap().parse().unwrap();
                heap.push(x);
            }
        }
    });
}



Measured memory_bytes: 35752