Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
sell = max(t[1:])
val = sell - buy

for i in range(n-1):
    m = max(t[i+1:])
    val2 = m - t[i]
    if val2 > val:
        buy = t[i]
        sell = m
        val = val2

print(val)



Fixed submission:
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
val = t[-1] - buy

for i in range(1, n):
    if t[i] - buy > val:
        val = t[i] - buy
    if t[i] < buy:
        buy = t[i]

print(val)

Buggy python submission (verdict: Runtime Error):
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
prev_sell = max(t[1:])
val = sell - buy

for i in range(n-1):
    if i == 0 or t[i - 1] < t[i]:
        continue
    prev_sell = max(t[i+1:])
    val2 = prev_sell - t[i]
    if val2 > val:
        val = val2

print(val)



Fixed submission:
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
val = t[-1] - buy

for i in range(1, n):
    if t[i] - buy > val:
        val = t[i] - buy
    if t[i] < buy:
        buy = t[i]

print(val)

Buggy python submission (verdict: Runtime Error):
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
prev_sell = max(t[1:])
val = sell - buy

for i in range(n-1):
    if i == 0 or t[i - 1] < t[i]:
        continue
    prev_sell = max(t[i+1:])
    val2 = prev_sell - t[i]
    if val2 > val:
        val = val2

print(val)



Fixed submission:
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
val = t[-1] - buy

for i in range(1, n):
    if t[i] - buy > val:
        val = t[i] - buy
    if t[i] < buy:
        buy = t[i]

print(val)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
prev_sell = max(t[1:])
val = prev_sell - buy

for i in range(n-1):
    if i == 0 or t[i - 1] < t[i]:
        continue
    prev_sell = max(t[i+1:])
    val2 = prev_sell - t[i]
    if val2 > val:
        val = val2

print(val)



Fixed submission:
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
val = t[-1] - buy

for i in range(1, n):
    if t[i] - buy > val:
        val = t[i] - buy
    if t[i] < buy:
        buy = t[i]

print(val)
Buggy python submission (verdict: Runtime Error):
   N = int(input())
A = list(map(int, input().split()))

count = 0

flag = True
while flag:
    flag = False
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A[j-1], A[j] = A[j], A[j-1]
            flag = True
            count += 1

print(' '.join(map(str,A)))
print(count)



Fixed submission:
N = int(input())
A = list(map(int, input().split()))

count = 0

flag = True
while flag:
    flag = False
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A[j-1], A[j] = A[j], A[j-1]
            flag = True
            count += 1

print(' '.join(map(str,A)))
print(count)
Buggy python submission (verdict: Runtime Error):
arr = list(map(str, input().split()))

i = 0

operand = []

while i < len(arr):
    if arr[i] == '+':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b + a)
    elif arr[i] == '-':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b - a)
    elif arr[i] == '*':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b * a) 
   else:
        operand.append(int(arr[i]))
    i += 1

print(operand[0])



Fixed submission:
arr = list(map(str, input().split()))

i = 0

operand = []

while i < len(arr):
    if arr[i] == '+':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b + a)
    elif arr[i] == '-':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b - a)
    elif arr[i] == '*':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b * a)
    else:
        operand.append(int(arr[i]))
    i += 1

print(operand[0])

Buggy python submission (verdict: Runtime Error):
arr = list(map(str, input().split()))

i = 0

operand = []

while i < len(arr):
    if arr[i] == '+':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b + a)
    elif arr[i] == '-':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b - a)
    elif arr[i] == '*':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b * a) 
   else:
        operand.append(int(arr[i]))
    i += 1

print(operand[0])



Fixed submission:
arr = list(map(str, input().split()))

i = 0

operand = []

while i < len(arr):
    if arr[i] == '+':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b + a)
    elif arr[i] == '-':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b - a)
    elif arr[i] == '*':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b * a)
    else:
        operand.append(int(arr[i]))
    i += 1

print(operand[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

dlist = []

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = int(arr[1])
    if cmd == 'insert':
        dlist.insert(0, key)
    elif cmd == 'delete':
        if dlist.count(key) > 0:
            idx = dlist.index(key)
            if idx != -1:
                dlist.pop(idx)
    elif cmd == 'deleteFirst':
        dlist.pop(0)
    elif cmd == 'deleteLast':
        dlist.pop(-1)

print(' '.join(map(str, dlist)))



Fixed submission:
from collections import deque

n = int(input())

dlist = deque()

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.appendleft(key)
    elif cmd == 'delete':
        try:
            dlist.remove(key)
        except:
            continue
    elif cmd == 'deleteFirst':
        dlist.popleft()
    elif cmd == 'deleteLast':
        dlist.pop()

print(' '.join(dlist))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

dlist = []

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.insert(0, key)
    elif cmd == 'delete':
        if dlist.count(key) > 0:
            idx = dlist.index(key)
            if idx != -1:
                dlist.pop(idx)
    elif cmd == 'deleteFirst':
        dlist.pop(0)
    elif cmd == 'deleteLast':
        dlist.pop(-1)

print(' '.join(dlist))



Fixed submission:
from collections import deque

n = int(input())

dlist = deque()

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.appendleft(key)
    elif cmd == 'delete':
        try:
            dlist.remove(key)
        except:
            continue
    elif cmd == 'deleteFirst':
        dlist.popleft()
    elif cmd == 'deleteLast':
        dlist.pop()

print(' '.join(dlist))

Buggy python submission (verdict: Runtime Error):
from collections import deque

n = int(input())

dlist = deque()

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.appendleft(key)
    elif cmd == 'delete':
        try:
            dlist.remove(key)
        except:
            #
    elif cmd == 'deleteFirst':
        dlist.pop()
    elif cmd == 'deleteLast':
        dlist.popleft()

print(' '.join(dlist))



Fixed submission:
from collections import deque

n = int(input())

dlist = deque()

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.appendleft(key)
    elif cmd == 'delete':
        try:
            dlist.remove(key)
        except:
            continue
    elif cmd == 'deleteFirst':
        dlist.popleft()
    elif cmd == 'deleteLast':
        dlist.pop()

print(' '.join(dlist))
Buggy python submission (verdict: Runtime Error):

def visit(x, y, area):
    move = [(-1, 0), (0, 1), (1, 0), (0, -1), (1, -1), (1, 1), (-1, 1), (-1, -1)]
    for i in move:
        if 0 <= (x + i[0]) < w and  0 <= (y + i[1]) < h and area[y + i[1]][x + i[0]] == 1:
            area[y + i[1]][x + i[0]] = 0
            visit(x + i[0], y + i[1], area)

def solve():
    area = []
    ans = 0
    for i in range(h):
        area.append(map(int, raw_input().split()))

    #print 'w: ' + str(w) + ',h: ' + str(h)

    for i in range(h):
        for j in range(w):
            if area[i][j] == 1:
                ans += 1
                visit(j, i, area)

    print ans


if __name__ == "__main__":
    while True:
        w , h = 0, 0
        w, h = map(int, raw_input().split())

        if w == 0 and h == 0:
            break

        solve()

Fixed submission:
def solve_sub(x, y, area):
    stack = []
    stack.append((x, y))

    move = [(x, y) for x in range(-1, 2) for y in range(-1, 2) if not (x == 0 and y == 0)]

    while len(stack) != 0:
        now = stack.pop()
        x = now[0]
        y = now[1]
        area[y][x] = 0

        for dire in move:
            if 0 <= x + dire[0] < w and 0 <= y + dire[1] < h and area[y + dire[1]][x + dire[0]] == 1:
                stack.append((x + dire[0], y + dire[1]))
                area[y + dire[1]][x + dire[0]] = 2


def solve(area):
    ans = 0
    for y in range(h):
        for x in range(w):
            if area[y][x] == 1:
                ans += 1
                solve_sub(x, y, area)

    print ans

if __name__ ==  "__main__":
    while True:
        w, h = map(int, raw_input().split())
        if w == 0 and h == 0:
            break

        area = []
        for y in range(h):
            area.append(map(int, raw_input().split()))

        solve(area)
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    while True:
        n, m, a = map(int, raw_input().split())
        if n == 0 and m == 0 and a == 0:
            break

        now = a
        amida = [[] for i in range(1000)]

        for i in range(m):
            h, p, q = map(int, raw_input().split())
            amida[h].append((p, q))
        
        for height in range(1000 - 1, 0, -1):
            lines = amida[height]
            for l in lines:
                if l[0] == now:
                    now = l[1]
                elif l[1] == now:
                    now = l[0]

        print now

Fixed submission:
if __name__ == "__main__":
    while True:
        n, m, a = map(int, raw_input().split())
        if n == 0 and m == 0 and a == 0:
            break

        now = a
        amida = [[] for i in range(1001)]

        for i in range(m):
            h, p, q = map(int, raw_input().split())
            amida[h].append((p, q))
        
        for height in range(1000 - 1, 0, -1):
            lines = amida[height]
            for l in lines:
                if l[0] == now:
                    now = l[1]
                elif l[1] == now:
                    now = l[0]

        print now

Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    while True:
        n, m, a = map(int, raw_input().split())
        if n == 0 and m == 0 and a == 0:
            break

        now = a
        amida = [[] for i in range(1000)]

        for i in range(m):
            h, p, q = map(int, raw_input().split())
            amida[h].append((p, q))
        
        for height in range(1000 - 1, 0, -1):
            lines = amida[height]
            for l in lines:
                if l[0] == now:
                    now = l[1]
                elif l[1] == now:
                    now = l[0]

        print now

Fixed submission:
if __name__ == "__main__":
    while True:
        n, m, a = map(int, raw_input().split())
        if n == 0 and m == 0 and a == 0:
            break

        now = a
        amida = [[] for i in range(1001)]

        for i in range(m):
            h, p, q = map(int, raw_input().split())
            amida[h].append((p, q))
        
        for height in range(1000 - 1, 0, -1):
            lines = amida[height]
            for l in lines:
                if l[0] == now:
                    now = l[1]
                elif l[1] == now:
                    now = l[0]

        print now
Buggy python submission (verdict: Time Limit Exceeded):


def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -1000000000
    for i in xrange(n):
        for j in xrange(i + 1, n):
            if R[j] - R[i] > max_profit:
                max_profit = R[j] - R[i]


    print max_profit


if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    for i in xrange(n):
        for j in xrange(i + 1, n):
            if R[j] - R[i] > max_profit:
                max_profit = R[j] - R[i]


    print max_profit


if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    for i in xrange(n):
        for j in xrange(i + 1, n):
            if R[j] - R[i] > max_profit:
                max_profit = R[j] - R[i]


    print max_profit


if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
x = input()
print(x * x * x)


Fixed submission:
x = int(input())

ans = x * x * x

print(ans)

Buggy python submission (verdict: Runtime Error):
x = input()

ans = x * x * x

print(ans)


Fixed submission:
x = int(input())

ans = x * x * x

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys

coin = [1, 5, 10, 50, 100, 500]

def charge(remain):
	ch = [0] * 6
	index = 5
	while remain > 0:
		while remain >= coin[index]:
			ch[index] += 1
			remain -= coin[index]
		index -= 1
	return ch

def total_coins(n):
	sum = 0
	for i in range(6):
		sum += n[i] * coin[i]
	return sum
	
def compute(p, n):
	a = n
	remain = p
	
	pay = [0] * 6
	index = 5
	while remain > 0:
		while remain >= coin[index]:
			if a[index] > 0:
				pay[index] += 1
				a[index] -= 1
				remain -= coin[index]
		index -= 1
	ch = charge(remain)
	cand = [sum(pay)+sum(ch)]

	for i in range(5, 0, -1):
		b = a
		pay2 = pay
		if b[i] > 0:
			pay2[i] += 1
			for j in range(i):
				pay2[j] = 0
			total = total_coins(pay2)
			ch = charge(total - p)
			cand.append(sum(pay2) + sum(ch))
	
	return min(cand)

	
if __name__ == '__main__':
	for input in sys.stdin:
		input = map(int, input.split())
		p, n = input[0], input[1:]
		if p == 0:
			break
		print compute(p, n)
		

Fixed submission:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys

coin = [1, 5, 10, 50, 100, 500]

def charge(remain):
	if remain == 0:
		return [0] * 6
	ch = [0] * 6
	index = 5
	while remain > 0:
		while remain >= coin[index]:
			ch[index] += 1
			remain -= coin[index]
		index -= 1
	return ch

def compute(p, n):
	candidates = []
	for r in range(500):
		pay = [0] * 6
		q = p + r
		for i in range(5, -1, -1):
			m = q / coin[i]
			pay[i] = min(m, n[i])
			q -= pay[i] * coin[i]
		if q == 0:
			candidates.append(sum(pay) + sum(charge(r)))
	return min(candidates)
	
if __name__ == '__main__':
	for input in sys.stdin:
		input = map(int, input.split())
		p, n = input[0], input[1:]
		if p == 0:
			break
		print compute(p, n)
Buggy python submission (verdict: Runtime Error):
a=input()
b=a**3
print(b)

Fixed submission:
a=int(input())

b=a**3
print(b)
Buggy python submission (verdict: Runtime Error):
inl = list(map(str, input().split()))

stack = []
for n in inl:
    if n == '+':
        stack.append(stack.pop() + stack.pop())
    elif n == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif n == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(n))
print(stack.pop())u


Fixed submission:
inl = list(map(str, input().split()))

stack = []
for n in inl:
    if n == '+':
        stack.append(stack.pop() + stack.pop())
    elif n == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif n == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(n))
print(stack.pop())
Buggy python submission (verdict: Runtime Error):
import math
p = raw_input().split()
x = math.fabs(int(p[0]) - int(p[2]))
y = math.fabs(int(p[1]) - int(p[3]))
print '%.8f' % math.sqrt(x**2 + y**2)

Fixed submission:
import math
p = raw_input().split()
x = math.fabs(float(p[0]) - float(p[2]))
y = math.fabs(float(p[1]) - float(p[3]))
print '%.8f' % math.sqrt(x**2 + y**2)
Buggy python submission (verdict: Runtime Error):
__author__ = 'admin'

while True:
    count_shima=input()
    if count_shima==0: break

    A = [list(map(int,raw_input().split())) for i in xrange(count_shima)]

    A.sort()

    weight=0
    frg=0
    for takara,turi in A:
        weight +=takara
        if turi < weight:
            print "NO"
            frg=1
            break
    if frg==0:
        print "YES"

Fixed submission:
def solve(info):
    have = 0
    for m, w in info:
        have += w
        if m < have:
            return "No"
    return "Yes"

while True:
    shima_count = input()
    if shima_count == 0: break
    info = []
    for i in range(shima_count):
        lu, w = map(int, raw_input().split())
        info.append((w, lu))
    info.sort()
    print solve(info)

Buggy python submission (verdict: Runtime Error):
while True:
    count_shima=input()
    if count_shima==0: break

    A = [list(map(int,raw_input().split())) for i in xrange(count_shima)]

    A.sort()

    weight=0
    frg=0
    for takara,turi in A:
        weight +=takara
        if turi < weight:
            print "NO"
            frg=1
            break
    if frg==0:
        print "YES"

Fixed submission:
def solve(info):
    have = 0
    for m, w in info:
        have += w
        if m < have:
            return "No"
    return "Yes"

while True:
    shima_count = input()
    if shima_count == 0: break
    info = []
    for i in range(shima_count):
        lu, w = map(int, raw_input().split())
        info.append((w, lu))
    info.sort()
    print solve(info)
Buggy python submission (verdict: Time Limit Exceeded):
def fib(n):
    return 1 if n == 0 or n == 1 else fib(n - 1) + fib(n - 2)

print(fib(int(input())))

Fixed submission:
def fib(n):
    n1 = n2 = tmp = 1
    for _ in range(n - 1):
        tmp = n1 + n2
        n1, n2 = n2, tmp
    return tmp

print(fib(int(input())))

Buggy python submission (verdict: Runtime Error):
def fib(n):
    n1 = n2 = 1
    for _ in range(n - 1):
        tmp = n1 + n2
        n1, n2 = n2, tmp
    return tmp

print(fib(int(input())))

Fixed submission:
def fib(n):
    n1 = n2 = tmp = 1
    for _ in range(n - 1):
        tmp = n1 + n2
        n1, n2 = n2, tmp
    return tmp

print(fib(int(input())))
Buggy python submission (verdict: Time Limit Exceeded):
def lcs(X, Y):
    m, n = len(X), len(Y)
    memo = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if X[i - 1] == Y[j - 1]:
                memo[i][j] = memo[i - 1][j - 1] + 1
            else:
                memo[i][j] = max(memo[i][j - 1], memo[i - 1][j])
    return memo[m][n]

n = int(input())
for _ in range(n):
    X, Y = input(), input()
    print(lcs(X, Y))

Fixed submission:
def lcs(X, Y):
    costs = [0]
    for c in Y:
        for i in range(len(costs) - 1, -1, -1):
            tmp = X.find(c, costs[i])
            if tmp + 1:
                if i + 1 < len(costs):
                    costs[i + 1] = min(costs[i + 1], tmp + 1)
                else:
                    costs.append(tmp + 1)
    return len(costs) - 1

n = int(input())
for _ in range(n):
    X, Y = (input() for _ in range(2))
    print(lcs(X, Y))

Buggy python submission (verdict: Time Limit Exceeded):
def lcs(X, Y):
    m, n = len(X), len(Y)
    cost = [[0] * (n+1) for _ in range(m+1)]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if X[i - 1] == Y[j - 1]:
                cost[i][j] = cost[i - 1][j - 1] + 1
            else:
                cost[i][j] = max(cost[i][j - 1], cost[i - 1][j])
    return cost[m][n]

n = int(input())
for _ in range(n):
    X, Y = input(), input()
    print(lcs(X, Y))

Fixed submission:
def lcs(X, Y):
    costs = [0]
    for c in Y:
        for i in range(len(costs) - 1, -1, -1):
            tmp = X.find(c, costs[i])
            if tmp + 1:
                if i + 1 < len(costs):
                    costs[i + 1] = min(costs[i + 1], tmp + 1)
                else:
                    costs.append(tmp + 1)
    return len(costs) - 1

n = int(input())
for _ in range(n):
    X, Y = (input() for _ in range(2))
    print(lcs(X, Y))