Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(raw_input())
dic = []
for i in range(n):
    com, s = map(str, raw_input().split())
    if com == "insert":
        dic.append(s)
    elif com == "find":
        if s in dic:
            print "yes"
        else:
            print "no"

Fixed submission:
# -*- coding: utf-8 -*-

n = int(raw_input())
dic = set()
for i in range(n):
    com, s = map(str, raw_input().split())
    if com == "insert":
        dic.add(s)
    elif com == "find":
        if s in dic:
            print "yes"
        else:
            print "no"

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(raw_input())
dic = []
for i in range(n):
    com, s = map(str, raw_input().split())
    if com == "insert":
        dic.append(s)
    elif com == "find":
        if s in dic:
            print "yes"
        else:
            print "no"

Fixed submission:
# -*- coding: utf-8 -*-

n = int(raw_input())
dic = set()
for i in range(n):
    com, s = map(str, raw_input().split())
    if com == "insert":
        dic.add(s)
    elif com == "find":
        if s in dic:
            print "yes"
        else:
            print "no"
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n, k = map(int, raw_input().split())
baggages = []
weight_sum = 0
for i in range(n):
    baggages.append(int(raw_input()))
for i in baggages:
    weight_sum += i
P_min = int(weight_sum/k)
tmp = P_min
while True:
    flag = True
    trucks = k-1
    i = 0
    while i < n:
        baggage = baggages[i]
        if P_min < baggage:
            P_min = baggage-1
            flag = False
            break
        if tmp >= baggage:
            tmp -= baggage
            i += 1
        else:
            tmp = P_min
            if trucks > 0:
                trucks -= 1
            else:
                flag = False
                break
    if flag:
        break
    else:
        P_min += 1
        tmp = P_min
print P_min

Fixed submission:
# -*- coding: utf-8 -*-

def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in range(n)]
left = 1
right = sum(W)
while left < right:
    mid = (left+right)/2
    v = maxStack(k, mid, W)
    if v >= n:
        right = mid
    else:
        left = mid+1
print left

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n, k = map(int, raw_input().split())
baggages = []
weight_sum = 0
for i in range(n):
    baggages.append(int(raw_input()))
for i in baggages:
    weight_sum += i
P_min = int(weight_sum/k)
for i in baggages:
    P_min = max(P_min, i)
tmp = P_min
while True:
    flag = True
    trucks = k-1
    i = 0
    while i < n:
        baggage = baggages[i]
        if tmp >= baggage:
            tmp -= baggage
            i += 1
        else:
            tmp = P_min
            if trucks > 0:
                trucks -= 1
            else:
                flag = False
                break
    if flag:
        break
    else:
        P_min += 1
        tmp = P_min
print P_min

Fixed submission:
# -*- coding: utf-8 -*-

def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in range(n)]
left = 1
right = sum(W)
while left < right:
    mid = (left+right)/2
    v = maxStack(k, mid, W)
    if v >= n:
        right = mid
    else:
        left = mid+1
print left
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def func(i, m, A):
    if m == 0:
        return True
    elif m < 0 or i >= len(A):
        return False
    else:
        if func(i+1, m-A[i], A):
            return True
        if func(i+1, m, A):
            return True
    return False

n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
M = map(int, raw_input().split())
for i in range(q):
    if func(0, M[i], A):
        print "yes"
    else:
        print "no"

Fixed submission:
# -*- coding: utf-8 -*-

n = int(raw_input())
A = {0}
for c in raw_input().split():
    for i in A.copy():
        A.add(i+int(c))
q = int(raw_input())
M = map(int, raw_input().split())
for m in M:
    if m in A:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def func(i, m):
    if m == 0:
        return True
    elif m < 0 or i >= len(A):
        return False
    else:
        if func(i+1, m-A[i]):
            return True
        if func(i+1, m):
            return True
    return False

n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
M = map(int, raw_input().split())
for i in range(q):
    if func(0, M[i]):
        print "yes"
    else:
        print "no"

Fixed submission:
# -*- coding: utf-8 -*-

n = int(raw_input())
A = {0}
for c in raw_input().split():
    for i in A.copy():
        A.add(i+int(c))
q = int(raw_input())
M = map(int, raw_input().split())
for m in M:
    if m in A:
        print "yes"
    else:
        print "no"
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n = int(raw_input())
A = map(int, raw_input().split())
count = 0
for i in range(n):
    for j = in range(i, n):
        if A[i] > A[j]:
            count += 1
print count

Fixed submission:
# -*- coding: utf-8 -*-

import sys

def merge(A, left, mid, right):
    global count
    n1 = mid-left
    n2 = right-mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left+i]
    for i in range(n2):
        R[i] = A[mid+i]
    L[n1] = R[n2] = sys.maxint
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            count += n1-i

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left+right)/2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(raw_input())
S = map(int, raw_input().split())
count = 0
mergeSort(S, 0, n)
print count

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(raw_input())
A = map(int, raw_input().split())
count = 0
for i in range(n):
    for j in range(i, n):
        if A[i] > A[j]:
            count += 1
print count

Fixed submission:
# -*- coding: utf-8 -*-

import sys

def merge(A, left, mid, right):
    global count
    n1 = mid-left
    n2 = right-mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left+i]
    for i in range(n2):
        R[i] = A[mid+i]
    L[n1] = R[n2] = sys.maxint
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            count += n1-i

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left+right)/2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(raw_input())
S = map(int, raw_input().split())
count = 0
mergeSort(S, 0, n)
print count
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def countSort(A, m):
    count = [0]*(m+1)
    n = len(A)
    B = [0]*m
    j = 0
    for i in range(n):
        count[A[i]] += 1
    for i in range(1, m):
        count[i] += count[i-1]
    for i in range(n-1, -1, -1):
        j = count[A[i]]
        B[j] = A[i]
        count[A[i]] = j-1
    for i in range(n):
        A[i] = B[i+1]
    return A

n = int(raw_input())
A = map(int, raw_input().split())
B = countSort(A, 10000)
print " ".join(map(str, B))

Fixed submission:
# -*- coding: utf-8 -*-

def countSort(A, m):
    count = [0]*(m+1)
    n = len(A)
    B = [0]*2000001
    j = 0
    for i in range(n):
        count[A[i]] += 1
    for i in range(1, m):
        count[i] += count[i-1]
    for i in range(n-1, -1, -1):
        j = count[A[i]]
        B[j] = A[i]
        count[A[i]] = j-1
    for i in range(n):
        A[i] = B[i+1]
    return A

n = int(raw_input())
A = map(int, raw_input().split())
B = countSort(A, 10000)
print " ".join(map(str, B))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def countSort(A, m):
    count = [0]*(m+1)
    n = len(A)
    B = [0]*2000000
    j = 0
    for i in range(n):
        count[A[i]] += 1
    for i in range(1, m):
        count[i] += count[i-1]
    for i in range(n-1, -1, -1):
        j = count[A[i]]
        B[j] = A[i]
        count[A[i]] = j-1
    for i in range(n):
        A[i] = B[i+1]
    return A

n = int(raw_input())
A = map(int, raw_input().split())
B = countSort(A, 10000)
print " ".join(map(str, B))

Fixed submission:
# -*- coding: utf-8 -*-

def countSort(A, m):
    count = [0]*(m+1)
    n = len(A)
    B = [0]*2000001
    j = 0
    for i in range(n):
        count[A[i]] += 1
    for i in range(1, m):
        count[i] += count[i-1]
    for i in range(n-1, -1, -1):
        j = count[A[i]]
        B[j] = A[i]
        count[A[i]] = j-1
    for i in range(n):
        A[i] = B[i+1]
    return A

n = int(raw_input())
A = map(int, raw_input().split())
B = countSort(A, 10000)
print " ".join(map(str, B))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

class Node_Class():
    def __init__(self, c_list):
        self.c_list = c_list

n = int(raw_input())
node_dic = {}
p_list = [0]*n
d_list = [0]*n
t_list = ['']*n
for i in range(n):
    line = map(str, raw_input().split())
    if int(line[1]) > 0:
        node_dic[int(line[0])] = Node_Class(map(int, line[2:]))
    else:
        node_dic[int(line[0])] = Node_Class([])
#parent
for i in range(n):
    flag = False
    for j in range(n):
        if i in node_dic[j].c_list:
            p_list[i] = j
            flag = True
            break
    if not flag:
        p_list[i] = -1
#depth
for i in range(n):
    j = i
    while p_list[j] > -1:
        j = p_list[j]
        d_list[i] += 1
#type
for i in range(n):
    if p_list[i] == -1:
        t_list[i] = t_list[i] + "root"
    else:
        if len(node_dic[i].c_list):
            t_list[i] = t_list[i] + "internal node"
        else:
            t_list[i] = t_list[i] + "leaf"
#print
for i in range(n):
    s = "node %d: parent = %d, depth = %d, %s," %(i, p_list[i], d_list[i], t_list[i])
    print s, node_dic[i].c_list

Fixed submission:
# -*- coding: utf-8 -*-

class Node_Class():
    def __init__(self, c_list):
        self.c_list = c_list

n = int(raw_input())
node_dic = {}
p_list = [0]*n
d_list = [0]*n
t_list = ['']*n
root = 0
for i in range(n):
    root += i
for i in range(n):
    line = map(str, raw_input().split())
    if int(line[1]) > 0:
        node_dic[int(line[0])] = Node_Class(map(int, line[2:]))
    else:
        node_dic[int(line[0])] = Node_Class([])
#parent
for i in range(n):
    for j in node_dic[i].c_list:
        p_list[j] = i
        root -= j
p_list[root] = -1
#depth
for i in range(n):
    j = i
    while p_list[j] > -1:
        j = p_list[j]
        d_list[i] += 1
#type
for i in range(n):
    if p_list[i] == -1:
        t_list[i] = t_list[i] + "root"
    else:
        if len(node_dic[i].c_list):
            t_list[i] = t_list[i] + "internal node"
        else:
            t_list[i] = t_list[i] + "leaf"
#print
for i in range(n):
    s = "node %d: parent = %d, depth = %d, %s," %(i, p_list[i], d_list[i], t_list[i])
    print s, node_dic[i].c_list
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n = int(raw_input())
l = map(int, raw_input().split())
A = [0]
for i in range(n):
    A.append(l[i])
print "node %d: key = %d, left key = %d, right key = %d, " %(1, A[1], A[2*1], A[2*1+1])
for i in range(2, int(n/2+1)):
    print "node %d: key = %d, parent key = %d, left key = %d, right key = %d, " %(i, A[i], A[int(i/2)], A[2*i], A[2*i+1])
for i in range(int(n/2+1), n+1):
    print "node %d: key = %d, parent key = %d, " %(i, A[i], A[int(i/2)])

Fixed submission:
# -*- coding: utf-8 -*-

n = int(raw_input())
l = map(int, raw_input().split())
A = [0]
for i in range(n):
    A.append(l[i])
print "node %d: key = %d, left key = %d, right key = %d, " %(1, A[1], A[2*1], A[2*1+1])
for i in range(2, int((n+1)/2)):
    print "node %d: key = %d, parent key = %d, left key = %d, right key = %d, " %(i, A[i], A[int(i/2)], A[2*i], A[2*i+1])
if not n%2:
    i = n/2
    print "node %d: key = %d, parent key = %d, left key = %d, " %(i, A[i], A[int(i/2)], A[2*i])
for i in range(int(n/2)+1, n+1):
    print "node %d: key = %d, parent key = %d, " %(i, A[i], A[int(i/2)])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

s = input()
h = s/3600
s = s%3600
m = s/60
s = s%60
print h +":"+ m +":"+ s

Fixed submission:
# -*- coding: utf-8 -*-

s = input()
h = s/3600
s = s%3600
m = s/60
s = s%60
print str(h) +":"+ str(m) +":"+ str(s)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

list = map(int, raw_input().split())
a = list[0]
b = list[1]
c = list[2]

if a < b && b < c:
    print "Yes"
else:
    print "No"

Fixed submission:
# -*- coding: utf-8 -*-

list = map(int, raw_input().split())
a = list[0]
b = list[1]
c = list[2]

if a < b and b < c:
    print "Yes"
else:
    print "No"
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a, b = map(int, raw_input().split())
print "%d %d %f" %(a/b, a%b, (float)a/b)

Fixed submission:
# -*- coding: utf-8 -*-

a, b = map(int, raw_input().split())
print "%d %d %f" %(a/b, a%b, float(a)/b)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

r = input()
print "%f %f" %(r*r*math.pi, 2*r*mat.pi)

Fixed submission:
# -*- coding: utf-8 -*-

import math

r = float(raw_input())
print "%f %f" %(r*r*math.pi, 2*r*math.pi)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

r = float(raw_input())
print "%f %f" %(r*r*math.pi, 2*r*mat.pi)

Fixed submission:
# -*- coding: utf-8 -*-

import math

r = float(raw_input())
print "%f %f" %(r*r*math.pi, 2*r*math.pi)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

while True:
    line = map(str, raw_input().split())
    H = int(line[0])
    W = int(line[1])
    if H+W:
        for i in range(H):
            if i == 0 or i == (H-1):
                print "#"*W
            elif:
                print "#" + "."*(W-2) +"#"
        print ""
    else:
        break

Fixed submission:
# -*- coding: utf-8 -*-

while True:
    line = map(str, raw_input().split())
    H = int(line[0])
    W = int(line[1])
    if H+W:
        for i in range(H):
            if i == 0 or i == (H-1):
                print "#"*W
            else:
                print "#" + "."*(W-2) +"#"
        print ""
    else:
        break
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

dic = {}
for i in range(ord('a'), ord('z')+1):
    dic[chr(i)] = 0

while True:
    buf = str(raw_input())
    buf = buf.lower()
    if not buf:
        break
    for i in range(len(buf)):
        if buf[i].isalpha():
            dic[buf[i]] += 1

for i in range(ord('a'), ord('z')+1):
    print "%s : %d" %(chr(i), dic[chr(i)])

Fixed submission:
# -*- coding: utf-8 -*-

sen = ''
while True:
    try:
        buf = raw_input()
    except:
        break
    sen += buf.lower()
for i in range(ord('a'), ord('z')+1):
    print "%s : %d" %(chr(i), sen.count(chr(i)))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

dic = {}
for i in range(ord('a'), ord('z')+1):
    dic[chr(i)] = 0

while True:
    buf = str(raw_input()).lower()
    if not buf:
        break
    for i in range(len(buf)):
        if buf[i].isalpha():
            dic[buf[i]] += 1

for i in range(ord('a'), ord('z')+1):
    print "%s : %d" %(chr(i), dic[chr(i)])

Fixed submission:
# -*- coding: utf-8 -*-

sen = ''
while True:
    try:
        buf = raw_input()
    except:
        break
    sen += buf.lower()
for i in range(ord('a'), ord('z')+1):
    print "%s : %d" %(chr(i), sen.count(chr(i)))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

s = str(raw_input())
q = int(raw_input())
for i in range(q):
    line = map(str, raw_input().split())
    com = line[0]
    a = int(line[1])
    b = int(line[2])
    if com == "print":
        print s[a:b+1]
    elif com == "reverse":
        len = len(s)
        s = s[0:a] + s[-len+b:-len+a-1:-1] + s[b+1:]
    elif com == "replace":
        p = line[3]
        s = s.replace(s[a:b+1], p)
    else:
        print "Error"

Fixed submission:
# -*- coding: utf-8 -*-

s = str(raw_input())
q = int(raw_input())
for i in range(q):
    line = map(str, raw_input().split())
    com = line[0]
    a = int(line[1])
    b = int(line[2])
    if com == "print":
        print s[a:b+1]
    elif com == "reverse":
        tmp = s[::-1]
        s = s[:a] + tmp[len(tmp)-b-1:len(tmp)-a] + s[b+1:]
    elif com == "replace":
        p = line[3]
        s = s[:a] + p + s[b+1:]
    else:
        print "Error"
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = []
ns = sys.stdin.readlines()
for n in ns:
    N.append(int(n))
ml = max(N)
P = [2]
for x in range(2, ml+1):
    flag = True
    for d in P:
        flag = flag and (x % d != 0)
    if flag == True:
        P = P + [x]
for m in N:
    print(len([p for p in P if p<=m]))

Fixed submission:
import sys
MAX = 1000000

A = tuple(range(2, MAX))
B = tuple()
while True:
    if (A[0])**2 > MAX:
        break
    B = B + (A[0],)
    A = tuple(x for x in A if x % A[0] != 0)
B = B + A

Lines = sys.stdin.readlines()
for line in Lines:
    print(len([x for x in B if x <= int(line)]))

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

N = []
ns = sys.stdin.readlines()
for n in ns:
    N.append(int(n))
ml = max(N)
P = [2]
for x in range(3, ml+1):
    flag = True
    for d in [p for p in P if (p < int(math.sqrt(x))+1)]:
        flag = flag and (x % d != 0)
    if flag == True:
        P = P + [x]
for m in N:
    print(len([p for p in P if p<=m]))

Fixed submission:
import sys
MAX = 1000000

A = tuple(range(2, MAX))
B = tuple()
while True:
    if (A[0])**2 > MAX:
        break
    B = B + (A[0],)
    A = tuple(x for x in A if x % A[0] != 0)
B = B + A

Lines = sys.stdin.readlines()
for line in Lines:
    print(len([x for x in B if x <= int(line)]))
Buggy python submission (verdict: Runtime Error):
while True:
    N, M = map(int, input().split())
    if N == M == 0:
        break

    L = []
    C = []
    for i in range(N):
        L.append(int(input()))
    for i in range(M):
        C.append(int(input()))
    for i in range(2, N+1):
        sL = []
        for j in range(N + 1 - i):
            sL.append(sum(L[j:i+j]))
        L += sL
    for i in range(2, M+1):
        sC = []
        for j in range(M +1 - i):
            sC.append(sum(C[j:i+j]))
        C += sC
    count = 0
    for x in C:
        for y in L:
            if x == y:
                count += 1
    print(count)

Fixed submission:
from itertools import combinations
from collections import Counter

while True:
    N, M = map(int, input().split())
    if N == M == 0:
        break

    L = [0]
    C = [0]
    x = 0
    y = 0
    count = 0
    
    for i in range(N):
        l = int(input())
        x += l
        L.append(x)

    dL = Counter([max(x1, x2) - min(x1 ,x2) for (x1, x2) in combinations(L, 2)])

    for i in range(M):
        c = int(input())
        y += c
        C.append(y)
    for y1, y2 in combinations(C, 2):
        dy = max(y1,y2)-min(y1,y2)
        if dy in dL:
            count += dL[dy]


    print(count)

Buggy python submission (verdict: Runtime Error):
while True:
    N, M = map(int, input().split())
    if N == M == 0:
        break

    L = []
    C = []
    dL = {}
    count = 0
    
    for i in range(N):
        l = int(input())
        L.append(l)
        if not l in dL:
            dL[l] = 1
        else:
            dL[l] += 1

    sL = []
    for i in range(2, N+1):
        
        for j in range(N + 1 - i):
            l = sum(L[j:i+j])
            if not l in dL:
                dL[l] = 1
            else:
                dL[l] += 1
    for i in range(M):
        c = int(input())
        C.append(c)
        if c in dL:
            count += dL[c]
        
    for i in range(2, M+1):
        for j in range(M +1 - i):
            c = sum(C[j:i+j])
            if c in dL:
                count += dL[c]

    print(count)
        

Fixed submission:
from itertools import combinations
from collections import Counter

while True:
    N, M = map(int, input().split())
    if N == M == 0:
        break

    L = [0]
    C = [0]
    x = 0
    y = 0
    count = 0
    
    for i in range(N):
        l = int(input())
        x += l
        L.append(x)

    dL = Counter([max(x1, x2) - min(x1 ,x2) for (x1, x2) in combinations(L, 2)])

    for i in range(M):
        c = int(input())
        y += c
        C.append(y)
    for y1, y2 in combinations(C, 2):
        dy = max(y1,y2)-min(y1,y2)
        if dy in dL:
            count += dL[dy]


    print(count)
Buggy python submission (verdict: Time Limit Exceeded):
x, y = map(int, input().split())
m = max(x, y) % min(x, y)

if m == 0:
    print(min(x, y))
else:
    for d in range(m-1, 0, -1):
        if min(x, y) % d ==0 and m % d ==0:
            print(d)
            break

Fixed submission:
def gcd(b, s):
    mod = b % s
    if mod != 0:
        return gcd(s, mod)
        
    else:
        return s

x, y = map(int, input().split())
b = max(x, y)
s = min(x, y)
a = gcd(b, s)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
S = tuple(A)
Smax = ((S[i]-min(S[:i])) for i in range(1, N))
print(max(Smax))

Fixed submission:
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
R = tuple(A)

Dmax = R[1] -R[0]
Rmin = R[0]

for i in range(1, N):
    if R[i] >= R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
    if R[i] < Rmin:
        Rmin = R[i]
#    print(R[i], Dmax, Rmin)

print(Dmax)

Buggy python submission (verdict: Runtime Error):
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
S = tuple(A)
Smax = ((S[i]-min(S[:i])) for i in range(1, N) if S[i] > S[i-1])
print(max(Smax))

Fixed submission:
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
R = tuple(A)

Dmax = R[1] -R[0]
Rmin = R[0]

for i in range(1, N):
    if R[i] >= R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
    if R[i] < Rmin:
        Rmin = R[i]
#    print(R[i], Dmax, Rmin)

print(Dmax)