Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint


def max_heapify(a, i, heap_size):
    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest, heap_size)


def max_heap_insert(a, key, heap_size):
    heap_size[0] += 1
    a[heap_size[0]] =  -1-maxint
    heap_increase_key(a, key, heap_size[0])


def heap_increase_key(a, key, i):
    if key < a[i]:
        raise ValueError('new key less current key')
    a[i] = key
    while i > 1 and a[i//2] < a[i]:
        a[i], a[i//2] = a[i//2], a[i]
        i = i // 2


def heap_extract_max(a, heap_size):
    if heap_size[0] < 1:
        raise ValueError('heap under flow')
    max = a[1]
    a[1] = a[heap_size[0]]
    heap_size[0] -= 1
    max_heapify(a, 1, heap_size[0])
    return max


heap = [-1-maxint] * 2000001
heap_size = [1]
for cmd in stdin:
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert 0 <= key <= 2000000000
        max_heap_insert(heap, key, heap_size)
    elif cmd.startswith('ex'):
        print(heap_extract_max(heap, heap_size))
    elif cmd.startswith('en'):
        break

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def max_heapify(a, i):
    heap_size = a[0]

    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest)


def main():
    heap = [-1] * 2000001
    heap[0] = 1
    for cmd in stdin:
        if cmd[0] == 'i':
            heap[0] += 1
            i = heap[0]
            heap[i] = int(cmd[7:])

            half = i // 2
            while i > 1 and heap[half] < heap[i]:
                heap[i], heap[half] = heap[half], heap[i]
                i //= 2
                half = i // 2
        elif cmd[1] == 'x':
            print(heap[1])
            heap[1] = heap[heap[0]]
            heap[0] -= 1
            max_heapify(heap, 1)
        elif cmd[1] == 'n':
            exit(0)


main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint

MININT = -1 - maxint


def max_heapify(a, i, heap_size):
    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest, heap_size)


def max_heap_insert(a, key, heap_size):
    heap_size[0] += 1
    a[heap_size[0]] = MININT
    heap_increase_key(a, key, heap_size[0])


def heap_increase_key(a, key, i):
    #if key < a[i]:
        #raise ValueError('new key less current key')
    a[i] = key
    half = i // 2
    while i > 1 and a[half] < a[i]:
        a[i], a[half] = a[half], a[i]
        i = i // 2
        half = i // 2


def heap_extract_max(a, heap_size):
    #if heap_size[0] < 1:
        #raise ValueError('heap under flow')
    max = a[1]
    a[1] = a[heap_size[0]]
    heap_size[0] -= 1
    max_heapify(a, 1, heap_size[0])
    return max


heap = [MININT] * 2000001
heap_size = [1]
for cmd in stdin:
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert 0 <= key <= 2000000000
        max_heap_insert(heap, key, heap_size)
    elif cmd.startswith('ex'):
        print(heap_extract_max(heap, heap_size))
    elif cmd.startswith('en'):
        break

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def max_heapify(a, i):
    heap_size = a[0]

    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest)


def main():
    heap = [-1] * 2000001
    heap[0] = 1
    for cmd in stdin:
        if cmd[0] == 'i':
            heap[0] += 1
            i = heap[0]
            heap[i] = int(cmd[7:])

            half = i // 2
            while i > 1 and heap[half] < heap[i]:
                heap[i], heap[half] = heap[half], heap[i]
                i //= 2
                half = i // 2
        elif cmd[1] == 'x':
            print(heap[1])
            heap[1] = heap[heap[0]]
            heap[0] -= 1
            max_heapify(heap, 1)
        elif cmd[1] == 'n':
            exit(0)


main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint
from array import array

MININT = -1 - maxint


def max_heapify(a, i, heap_size):
    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest, heap_size)


def max_heap_insert(a, key, heap_size):
    heap_size[0] += 1
    a[heap_size[0]] = MININT
    heap_increase_key(a, key, heap_size[0])


def heap_increase_key(a, key, i):
    #if key < a[i]:
        #raise ValueError('new key less current key')
    a[i] = key
    half = i // 2
    while i > 1 and a[half] < a[i]:
        a[i], a[half] = a[half], a[i]
        i = i // 2
        half = i // 2


def heap_extract_max(a, heap_size):
    #if heap_size[0] < 1:
        #raise ValueError('heap under flow')
    max = a[1]
    a[1] = a[heap_size[0]]
    heap_size[0] -= 1
    max_heapify(a, 1, heap_size[0])
    return max


heap = array('i', [MININT] * 2000001)
heap_size = [1]
for cmd in stdin:
    if cmd[0] == 'i':
        key = int(cmd[7:])
        #assert 0 <= key <= 2000000000
        max_heap_insert(heap, key, heap_size)
    elif cmd[1] == 'x':
        print(heap_extract_max(heap, heap_size))
    elif cmd[1] == 'n':
        break

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def max_heapify(a, i):
    heap_size = a[0]

    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest)


def main():
    heap = [-1] * 2000001
    heap[0] = 1
    for cmd in stdin:
        if cmd[0] == 'i':
            heap[0] += 1
            i = heap[0]
            heap[i] = int(cmd[7:])

            half = i // 2
            while i > 1 and heap[half] < heap[i]:
                heap[i], heap[half] = heap[half], heap[i]
                i //= 2
                half = i // 2
        elif cmd[1] == 'x':
            print(heap[1])
            heap[1] = heap[heap[0]]
            heap[0] -= 1
            max_heapify(heap, 1)
        elif cmd[1] == 'n':
            exit(0)


main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint

MININT = -1 - maxint


def max_heapify(a, i, heap_size):
    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest, heap_size)


def max_heap_insert(a, key, heap_size):
    heap_size[0] += 1
    a[heap_size[0]] = MININT
    heap_increase_key(a, key, heap_size[0])


def heap_increase_key(a, key, i):
    #if key < a[i]:
        #raise ValueError('new key less current key')
    a[i] = key
    half = i // 2
    while i > 1 and a[half] < a[i]:
        a[i], a[half] = a[half], a[i]
        i = i // 2
        half = i // 2


def heap_extract_max(a, heap_size):
    #if heap_size[0] < 1:
        #raise ValueError('heap under flow')
    max = a[1]
    a[1] = a[heap_size[0]]
    heap_size[0] -= 1
    max_heapify(a, 1, heap_size[0])
    return max


heap = [MININT] * 2000001
heap_size = [1]
for cmd in stdin:
    if cmd[0] == 'i':
        key = int(cmd[7:])
        #assert 0 <= key <= 2000000000
        max_heap_insert(heap, key, heap_size)
    elif cmd[1] == 'x':
        print(heap_extract_max(heap, heap_size))
    elif cmd[1] == 'n':
        break

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def max_heapify(a, i):
    heap_size = a[0]

    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest)


def main():
    heap = [-1] * 2000001
    heap[0] = 1
    for cmd in stdin:
        if cmd[0] == 'i':
            heap[0] += 1
            i = heap[0]
            heap[i] = int(cmd[7:])

            half = i // 2
            while i > 1 and heap[half] < heap[i]:
                heap[i], heap[half] = heap[half], heap[i]
                i //= 2
                half = i // 2
        elif cmd[1] == 'x':
            print(heap[1])
            heap[1] = heap[heap[0]]
            heap[0] -= 1
            max_heapify(heap, 1)
        elif cmd[1] == 'n':
            exit(0)


main()