Buggy python submission (verdict: Time Limit Exceeded):
def get_item(L,i): return L[i] if len(L) > i else -2
def left(i): return i*2 + 1
def right(i): return (i+1)*2
def parent(i): return i//2 if i%2 == 1 else i//2 - 1

def maxHeapify(A,i):
    l = left(i)
    r = right(i)
    largest = i
    if get_item(A,l) > A[largest]: largest = l
    if get_item(A,r) > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        maxHeapify(A, largest)


def maxHeapInsert(A,i):
    if i==0: return
    p = parent(i)
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        maxHeapInsert(A,p)


def insert(A,k):
    A.append(k)
    maxHeapInsert(A,len(A)-1)


def extract(A):
    max_item, A[0] = A[0], -1
    maxHeapify(A,0)
    for i in range(A.index(-1),len(A)-1):
        A[i], A[i+1] = A[i+1], A[i]
        maxHeapInsert(A,i)
    A.pop()
    return max_item


if __name__=='__main__':
    hp = []
    while True:
        op = input().split() 
        if   op[0] == 'end': break
        if   op[0] == 'insert': insert(hp,int(op[1]))
        else: print(extract(hp))

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def get_item(L,i): return L[i] if len(L) > i else -2
def left(i): return i*2 + 1
def right(i): return (i+1)*2
def parent(i): return i//2 if i%2 == 1 else i//2 - 1

def dw_heap(A,i):
    l = left(i)
    r = right(i)
    largest = i
    if get_item(A,l) > A[largest]: largest = l
    if get_item(A,r) > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        dw_heap(A, largest)


def up_heap(A,i):
    if i==0: return
    p = parent(i)
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        up_heap(A,p)


def insert(A,k):
    A.append(k)
    up_heap(A,len(A)-1)


def extract(A):
    A[0],A[-1] = A[-1],A[0]
    max_item = A.pop()
    dw_heap(A,0)
    return max_item


if __name__=='__main__':
    hp = []
    while True:
        op = input().split() 
        if   op[0] == 'end': break
        if   op[0] == 'insert': insert(hp,int(op[1]))
        else: print(extract(hp))

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def get_item(L,i): return L[i] if len(L) > i else -2

def dw_heap(A,i):
    l = i*2 + 1
    r = (i+1)*2
    largest = i
    if get_item(A,l) > A[largest]: largest = l
    if get_item(A,r) > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        dw_heap(A, largest)


def up_heap(A,i):
    if i==0: return
    p = i//2 if i%2 == 1 else i//2 - 1
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        up_heap(A,p)


def insert(A,k):
    A.append(k)
    up_heap(A,len(A)-1)


def extract(A):
    A[0],A[-1] = A[-1],A[0]
    max_item = A.pop()
    dw_heap(A,0)
    return max_item


if __name__=='__main__':
    hp = []
    while True:
        op = input().split() 
        if   op[0] == 'end': break
        if   op[0] == 'insert': insert(hp,int(op[1]))
        else: print(extract(hp))

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def dw_heap(A,i):
    alen = len(A)
    l = i*2 + 1
    r = (i+1)*2
    largest = i
    if l < alen and A[l] > A[largest]: largest = l
    if r < alen and A[r] > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        dw_heap(A, largest)


def up_heap(A,i):
    if i==0: return
    p = i//2 if i%2 == 1 else i//2 - 1
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        up_heap(A,p)


def insert(A,k):
    A.append(k)
    up_heap(A,len(A)-1)


def extract(A):
    A[0],A[-1] = A[-1],A[0]
    max_item = A.pop()
    dw_heap(A,0)
    return max_item


if __name__=='__main__':
    hp = []
    while True:
        op = input().split() 
        if   op[0] == 'end': break
        if   op[0] == 'insert': insert(hp,int(op[1]))
        else: print(extract(hp))

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def dw_heap(A,i,length):
    l = i*2
    r = i*2 + 1
    largest = i
    if l < length and A[l] > A[largest]: largest = l
    if r < length and A[r] > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        dw_heap(A, largest, length)


def up_heap(A,i):
    if i==1: return
    p = i//2
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        up_heap(A,p)


def extract(A,last):
    max_item = A[1]
    A[1],A[last] = A[last],A[1]
    dw_heap(A,1,last)
    return max_item


def build_heap(A,length):
    for i in range(length//2,0,-1): dw_heap(A,i,length)


if __name__=='__main__':
    hp = [None]*2*10**6
    i = 1
    while True:
        op = input().split() 
        if   op[0] != 'insert': break
        hp[i] = int(op[1])
        i += 1
    if op[0] != 'end': build_heap(hp,i)
    while True:
        if   op[0] == 'end': break
        if   op[0] == 'insert':
            hp[i] = int(op[1])
            up_heap(hp,i)
            i += 1
        else:
            print(extract(hp,i-1))
            i -= 1
        op = input().split() 

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def dw_heap(A,i,length):
    l = i*2
    r = i*2 + 1
    largest = i
    if l < length and A[l] > A[largest]: largest = l
    if r < length and A[r] > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        dw_heap(A, largest, length)


def up_heap(A,i):
    if i==1: return
    p = i//2
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        up_heap(A,p)


def extract(A,last):
    max_item = A[1]
    A[1],A[last] = A[last],A[1]
    dw_heap(A,1,last)
    return max_item


def build_heap(A,length):
    for i in range(length//2,0,-1): dw_heap(A,i,length)


if __name__=='__main__':
    hp = [None]*(2*10**6)
    i = 1
    j = -1 
    while True:
        op = input() 
        if   op[0] != 'i': break
        hp[i] = int(op[7:])
        i += 1
    if op[2] != 'd': build_heap(hp,i)
    while True:
        if   op[2] == 'd': break
        if   op[0] == 'i':
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        else:
            hp[j] = extract(hp,i-1)
            i -= 1
            j -= 1
        op = input() 
    print(*hp[:j:-1],sep='\n')

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def dw_heap(A,i,length):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if l < length and A[l] > A[largest]: largest = l
        if r < length and A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest


def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2


def extract(A,last):
    max_item = A[1]
    A[1],A[last] = A[last],A[1]
    dw_heap(A,1,last)
    return max_item


def build_heap(A,length):
    for i in range(length//2,0,-1): dw_heap(A,i,length)


if __name__=='__main__':
    hp = [None]*(2*10**6)
    hp[0] = 2*10**9 + 1
    i = 1
    j = -1 
    while True:
        op = input() 
        if   op[0] != 'i': break
        hp[i] = int(op[7:])
        i += 1
    if op[2] != 'd': build_heap(hp,i)
    while True:
        if   op[2] == 'd': break
        if   op[0] == 'i':
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        else:
            hp[j] = extract(hp,i-1)
            i -= 1
            j -= 1
        op = input() 
    print(*hp[:j:-1],sep='\n')

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def dw_heap(A,i,length):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if l < length and A[l] > A[largest]: largest = l
        if r < length and A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest


def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2


def build_heap(A,length):
    for i in range(length//2,0,-1): dw_heap(A,i,length)


if __name__=='__main__':
    hp = [None]*(2*10**6)
    hp[0] = 2*10**9 + 1
    i = 1
    j = -1 
    while True:
        op = input() 
        if   op[0] != 'i': break
        hp[i] = int(op[7:])
        i += 1
    if op[2] != 'd': build_heap(hp,i)
    while True:
        if   op[2] == 'd': break
        if   op[0] == 'i':
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        else:# extract
            hp[j] = hp[1]
            hp[1],hp[i-1] = hp[i-1],hp[1]
            dw_heap(hp,1,i-1)
            i -= 1
            j -= 1
        op = input() 
    print(*hp[:j:-1],sep='\n')

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
def dw_heap(A,i,length):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if l < length and A[l] > A[largest]: largest = l
        if r < length and A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest


def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2


if __name__=='__main__':
    hp = [None]*(2*10**6)
    hp[0] = 2*10**9 + 1
    i = 1
    j = -1 
    while True:
        op = input() 
        if   op[0] != 'i': break
        hp[i] = int(op[7:])
        i += 1
    if op[2] != 'd':
        for k in range(i//2,0,-1): dw_heap(hp,k,i)
    while True:
        if   op[2] == 'd': break
        if   op[0] == 'i':
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        else:# extract
            hp[j] = hp[1]
            hp[1],hp[i-1] = hp[i-1],hp[1]
            dw_heap(hp,1,i-1)
            i -= 1
            j -= 1
        op = input() 
    print(*hp[:j:-1],sep='\n')

Fixed submission:
from sys import stdin

def dw_heap(A,i):
    largest = i
    while True:
        l = i*2
        r = l + 1
        if A[l] > A[largest]: largest = l
        if A[r] > A[largest]: largest = r
        if largest == i: return
        A[i], A[largest] = A[largest], A[i] 
        i = largest

def up_heap(A,i):
    p = i//2
    while A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        i = p
        p = i//2

if __name__=='__main__':
    hp = [-1]*(4000000)
    hp[0] = 2000000001
    i = 1
    j = -1 
    for op in stdin:
        if op[0] == 'i':# insert
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        elif op[1] == 'x':# extract
            hp[j],hp[1],hp[i-1] = hp[1],hp[i-1],-1
            dw_heap(hp,1)
            i -= 1
            j -= 1
        else:# end
            break
    print(*hp[:j:-1],sep='\n')