Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
INF = -10**10
queue = [-1]


def insert(queue, key):
    h = len(queue) - 1
    queue.append(INF)
    heap_increase_key(queue, h + 1, key)


def heap_increase_key(queue, i, key):
    if key < queue[i]:
        raise ValueError('The new key is smaller than the present key')
    queue[i] = key
    while i > 1 and queue[i // 2] < queue[i]:
        queue[i], queue[i // 2] = queue[i // 2], queue[i]
        i = i // 2


def extract_max(queue):
    h = len(queue) - 1
    if h < 1:
        raise TypeError('Heap underflowed')
    max = queue[1]
    queue[1] = queue.pop()
    max_heapify(queue, 1)

    return max


def max_heapify(queue, i):
    h = len(queue) - 1
    l = 2 * i
    r = 2 * i + 1
    if l <= h and queue[l] > queue[i]:
        largest = l
    else:
        largest = i
    if r <= h and queue[r] > queue[largest]:
        largest = r

    if largest != i:
        queue[i], queue[largest] = queue[largest], queue[i]
        max_heapify(queue, largest)


if __name__ == '__main__':
    import sys
    ords = [line.strip().split() for line in sys.stdin]

    for ord in ords:
        if len(ord) > 1:
            ord, key = ord

        if ord[0] == 'i':
            insert(queue, key)
        elif len(ord) == 7:
            extract_max(queue)
        else:
            break



Fixed submission:
# -*- coding: utf-8 -*-
import sys
from heapq import *

q = []
while True:
    cmd = sys.stdin.readline().split()
    if cmd[0] == 'end':
        break
    elif cmd[0] == 'insert':
        heappush(q, -int(cmd[1]))
    else:
        print(-heappop(q))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
INF = -10**10
queue = [-1]


def insert(queue, key):
    h = len(queue) - 1
    queue.append(INF)
    heap_increase_key(queue, h + 1, key)


def heap_increase_key(queue, i, key):
    if key < queue[i]:
        raise ValueError('The new key is smaller than the present key')
    queue[i] = key
    while i > 1 and queue[i // 2] < queue[i]:
        queue[i], queue[i // 2] = queue[i // 2], queue[i]
        i = i // 2


def extract_max(queue):
    h = len(queue) - 1
    if h < 1:
        raise TypeError('Heap underflowed')
    max = queue[1]
    queue[1] = queue.pop()
    max_heapify(queue, 1)

    return max


def max_heapify(queue, i):
    h = len(queue) - 1
    l = 2 * i
    r = 2 * i + 1
    if l <= h and queue[l] > queue[i]:
        largest = l
    else:
        largest = i
    if r <= h and queue[r] > queue[largest]:
        largest = r

    if largest != i:
        queue[i], queue[largest] = queue[largest], queue[i]
        max_heapify(queue, largest)


if __name__ == '__main__':
    import sys
    ords = [line.strip().split() for line in sys.stdin]

    for ord in ords:
        if len(ord) > 1:
            ord, key = ord[0], int(ord[1])
        else:
            ord = ord[0]
        if ord[0] == 'i':
            insert(queue, key)
        elif len(ord) == 7:
            print(extract_max(queue))
        else:
            break



Fixed submission:
# -*- coding: utf-8 -*-
import sys
from heapq import *

q = []
while True:
    cmd = sys.stdin.readline().split()
    if cmd[0] == 'end':
        break
    elif cmd[0] == 'insert':
        heappush(q, -int(cmd[1]))
    else:
        print(-heappop(q))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
INF = -10**10
queue = [-1]


def insert(queue, key):
    h = len(queue) - 1
    queue.append(INF)
    heap_increase_key(queue, h + 1, key)


def heap_increase_key(queue, i, key):
    if key < queue[i]:
        raise ValueError('The new key is smaller than the present key')
    queue[i] = key
    while i > 1 and queue[i // 2] < queue[i]:
        queue[i], queue[i // 2] = queue[i // 2], queue[i]
        i = i // 2


def extract_max(queue):
    h = len(queue) - 1
    if h < 1:
        raise TypeError('Heap underflowed')
    max = queue[1]
    queue[1] = queue.pop()
    h -= 1

    i = 1
    while True:
        l = 2 * i
        r = 2 * i + 1
        if l <= h and queue[l] > queue[i]:
            largest = l
        else:
            largest = i
        if r <= h and queue[r] > queue[largest]:
            largest = r

        if largest != i:
            queue[i], queue[largest] = queue[largest], queue[i]
            i = largest
        else:
            break

    return max


if __name__ == '__main__':
    import sys
    ords = [line.strip().split() for line in sys.stdin]

    for ord in ords:
        if len(ord) > 1:
            ord, key = ord[0], int(ord[1])
        else:
            ord = ord[0]
        if ord[0] == 'i':
            insert(queue, key)
        elif len(ord) == 7:
            print(extract_max(queue))
        else:
            break



Fixed submission:
# -*- coding: utf-8 -*-
import sys
from heapq import *

q = []
while True:
    cmd = sys.stdin.readline().split()
    if cmd[0] == 'end':
        break
    elif cmd[0] == 'insert':
        heappush(q, -int(cmd[1]))
    else:
        print(-heappop(q))