Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

N = int(input())
H = list(map(int,input().split()))

sabun = [H[i+1]-H[i] for i in range(N-1)]
sei = [i+1 for i in range(N-1) if sabun[i] <= 0]
if N == 1:
    print("0")
    exit()
if min(sabun) >= 0:
    print("0")
    exit()

sa = [sei[i+1]-sei[i] for i in range(len(sei)-1)]
sa.append(0)
index = [i+1 for i in range(len(sa)) if sa[i] != 1]
ans = [index[i+1]-index[i] for i in range(len(index)-1)]
# print(sabun)
# print(sei)
# print(sa)
# print(index)
print(max(ans))


Fixed submission:

N = int(input())
H = list(map(int,input().split()))

sabun = [H[i+1]-H[i] for i in range(N-1)]
sei = [i+1 for i in range(N-1) if sabun[i] <= 0]

# print(sabun)
# print(sei)

if N == 1:
    print("0")
    exit()
if min(sabun) > 0:
    print("0")
    exit()

sa = [sei[i+1]-sei[i] for i in range(len(sei)-1)]
sa.append(0)
sa.insert(0,0)
index = [i for i in range(len(sa)) if sa[i] != 1]
ans = [index[i+1]-index[i] for i in range(len(index)-1)]

# print(sa)
# print(index)
if ans == []:
    print(N-1)
    exit()
print(max(ans))

Buggy python submission (verdict: Runtime Error):

N = int(input())
H = list(map(int,input().split()))

sabun = [H[i+1]-H[i] for i in range(N-1)]
sei = [i+1 for i in range(N-1) if sabun[i] > 0]
if N == 1:
    print("0")
    exit()
if min(sabun) >= 0:
    print("0")
    exit()
sei.append(N-1)
sa = [sei[i+1]-sei[i] for i in range(len(sei)-1)]
# print(H)
# print(sabun)
# print(sei)
print(max(sa))


Fixed submission:

N = int(input())
H = list(map(int,input().split()))

sabun = [H[i+1]-H[i] for i in range(N-1)]
sei = [i+1 for i in range(N-1) if sabun[i] <= 0]

# print(sabun)
# print(sei)

if N == 1:
    print("0")
    exit()
if min(sabun) > 0:
    print("0")
    exit()

sa = [sei[i+1]-sei[i] for i in range(len(sei)-1)]
sa.append(0)
sa.insert(0,0)
index = [i for i in range(len(sa)) if sa[i] != 1]
ans = [index[i+1]-index[i] for i in range(len(index)-1)]

# print(sa)
# print(index)
if ans == []:
    print(N-1)
    exit()
print(max(ans))
Buggy python submission (verdict: Runtime Error):
N,X = map(int,input().split())
L = list(map(int,input().split()))
count = 0
var = 0
for i in range(X):
    count += 1
    var +=L [i]
    if var > X:
        break
print(count)


Fixed submission:
N,X = map(int,input().split())
L = list(map(int,input().split()))
count = 1
var = 0
for i in range(N):
    if i >= N:
        break
    var += L[i]
    if var > X:
        break
    count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

minA = min(A)
C = [[j]*i for i,j in BC if j > minA]
for i in range(len(C)):
    A = A[:N]
    if C[i][0] > min(A):
        A.extend(C[i])
        A.sort(reverse=True)


print(sum(A[:N]))


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)

idx = 0
for b, c in BC:
  for j in range(idx, min(N, idx + b)):
    if A[j] < c:
      A[j] = c
  idx += b
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

minA = min(A)
C = [[j]*i for i,j in BC if j > minA]
for i in range(len(C)):
    A.extend(C[i])

A.sort(reverse=True)
print(sum(A[:N]))


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)

idx = 0
for b, c in BC:
  for j in range(idx, min(N, idx + b)):
    if A[j] < c:
      A[j] = c
  idx += b
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int, input().split())
r_n = n//r
g_n = n//g
b_n = n//b
# print(r_n)
# print(g_n)
# print(b_n)
count = 0
ans = len([0 for rr in range(r_n+1) for gg in range(g_n+1) for bb in range(b_n+1) if rr*r + gg*g + bb*b == n])
# for rr in range(r_n+1):
#     for gg in range(g_n+1):
#         for bb in range(b_n+1):
#             if rr*r + gg*g + bb*b == n:
#                 count += 1
print(ans)


Fixed submission:
r, g, b, n = map(int, input().split())

count = 0
for i in range(n//r + 1):
    for j in range((n-r*i)//g + 1):
        if (n-r*i-g*j) % b == 0:
            count += 1


print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans  = [i for i in range(1,n) if n//i == n%i]
print(sum(ans))


Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
div  = make_divisors(n)

l = []
for i in div:
    var = i - 1
    if var != 0 :
        if n//var == n%var:
            l.append(var)

print(sum(l))
Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a_list = list(map(int,input().split()))


ans = 0
for i in range(n):
    init = a_list[:]
    init.pop(i)
    gcd = gcd_list(init)
    if ans < gcd:
        ans = gcd

print(ans)

Fixed submission:
a,b,t = map(int,input().split())

ans = [i for i in range(1,30) if i%a == 0 and i<t+0.5]
print(len(ans)*b)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a_list = list(map(int,input().split()))


ans = 0
for i in range(n):
    init = a_list[:]
    init.pop(i)
    gcd = gcd_list(init)
    if ans < gcd:
        ans = gcd

print(ans)

Fixed submission:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))

rs, ls = [0], [0]
for i in range(n-1):
  rs.append(gcd(rs[i], a[i]))
  ls.append(gcd(ls[i], a[-i-1]))

gcd_list = [gcd(r,l) for r, l in zip(rs, ls[::-1])]
print(max(gcd_list))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


n = int(input())
a_list = list(map(int,input().split()))

ans = 0
for i in range(n):
    init = a_list[:]
    init.pop(i)
    gcd = gcd_list(init)
    if ans < gcd:
        ans = gcd

print(ans)


Fixed submission:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))

rs, ls = [0], [0]
for i in range(n-1):
  rs.append(gcd(rs[i], a[i]))
  ls.append(gcd(ls[i], a[-i-1]))

gcd_list = [gcd(r,l) for r, l in zip(rs, ls[::-1])]
print(max(gcd_list))
Buggy python submission (verdict: Time Limit Exceeded):
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

e = [i + j for i in a for j in b]
e.sort(reverse=True)
e = e[:k]
ans = [i + j for i in e for j in c]
ans.sort(reverse=True)

for i in range(k):
    print(ans[i])


Fixed submission:
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

e = [i + j for i in a[:k] for j in b[:k]]
e.sort(reverse=True)
e = e[:k]
ans = [i + j for i in e for j in c[:k]]
ans.sort(reverse=True)

for i in range(k):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

e = [i + j for i in a for j in b]
e.sort(reverse=True)
e = e[:k]
ans = [i + j for i in e for j in c]
ans.sort(reverse=True)
ans = ans[:k]

for i in range(k):
    print(ans[i])


Fixed submission:
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

e = [i + j for i in a[:k] for j in b[:k]]
e.sort(reverse=True)
e = e[:k]
ans = [i + j for i in e for j in c[:k]]
ans.sort(reverse=True)

for i in range(k):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = [p+q+r for p in a for q in b for r in c]

ans.sort(reverse=True)
for i in range(k):
    print(ans[i])


Fixed submission:
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

e = [i + j for i in a[:k] for j in b[:k]]
e.sort(reverse=True)
e = e[:k]
ans = [i + j for i in e for j in c[:k]]
ans.sort(reverse=True)

for i in range(k):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = []
for p in a:
    for q in b:
        for r in c:
            ans.append(p+q+r)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Fixed submission:
x , y ,z , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

e = [i + j for i in a[:k] for j in b[:k]]
e.sort(reverse=True)
e = e[:k]
ans = [i + j for i in e for j in c[:k]]
ans.sort(reverse=True)

for i in range(k):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())

yakusuu_array = []

for ab in [a,b]:
    yakusuu_array_ab = []
    for i in range(1,ab):
        if ab % i == 0:
            yakusuu_array_ab.append(i)
    yakusuu_array.append(yakusuu_array_ab)

kouyakusuu = list(set(yakusuu_array[0]) & set(yakusuu_array[1]))

if len(kouyakusuu) == 0:
    print(1)
else:
    print(kouyakusuu[k-1])


Fixed submission:
a,b,c = map(int,input().split())
oto = b//a
if oto >= c:
    oto = c
print(oto)
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(min([i for i in range(100,999) if i >= n and i//100 == (i//10)%10 and i//100 == i%10]))


Fixed submission:
n = int(input())
print(min([i for i in range(100,1000) if i >= n and i//100 == (i//10)%10 and i//100 == i%10]))
Buggy python submission (verdict: Runtime Error):
n=int(input())
li = list(map(int,input().split()))
count=0

for i in range(100):
  for j in range(n):
    if i == j:pass
    elif li[i]%li[j] == 0:break
    elif j == n-1:count +=1

print(count)

Fixed submission:
x,n = map(int,input().split())
if n == 0:print(x)
else:
  li = list(map(int,input().split()))

  for i in range(100):
    plus = (x+i)  in li
    minus = (x-i)  in li
  
    if plus == 1 and minus == 1:
      pass  
    elif plus == 1 and minus == 0:
      print(x-i)
      break
    elif plus == 0 and minus == 1:
      print(x+i)
      break
    else:
      print(x-i)
      break
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
i_list = list(map(int,input().split()))

for x in range(k-1):
  d_list = [0]*n
  
  for x in range(n-1):
    
    d_list[x-i_list[x]:x+i_list[x]] = map(lambda y: y+1, d_list[x-i_list[x]:x+i_list[x]])
    
    
  i_list = [x + y for (x, y) in zip(i_list, d_list)]
  
print(i_list)

Fixed submission:
str = input()
print(str[0:3])
Buggy python submission (verdict: Runtime Error):
a,b=input().split()
print(int(a)*round((float(b)*100)//100)

Fixed submission:
a,b=input().split()
print(int(a)*round(float(b)*100)//100)

Buggy python submission (verdict: Runtime Error):
a,b=input().split()
print(int(a)*int(float(b)*100//100)
      

Fixed submission:
a,b=input().split()
print(int(a)*round(float(b)*100)//100)

Buggy python submission (verdict: Runtime Error):
a,b=input().split()
print(a*round(b*100)//100)

Fixed submission:
a,b=input().split()
print(int(a)*round(float(b)*100)//100)
Buggy python submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**8:print(a-b)
elif k%2 != 0 abs(b-a)<=10**8:print(b-a)
else:print("Unfair")

Fixed submission:
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")

Buggy python submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and ans(b-a)<=10**18:print(b-a)
else:print("Unfair")

Fixed submission:
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")

Buggy python submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())

if k%2 == 0:
  if abs(a-b)<=10**18:print(a-b)
elif ans(b-a)<=10**18:print(b-a)
else:print("Unfair")   

Fixed submission:
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")

Buggy python submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())

if k%2 == 0:
  if abs(a-b)<=10**18:print(a-b)
elif ans(b-a)<=10*18:print(b-a)
else:print("Unfair")   

Fixed submission:
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")

Buggy python submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())

if k%2 == 0:
  if abs(a-b)<=10**18:print(a-b)
  else:print("Unfair")
else:
    if ans(b-a)<=10*18:print(b-a)
    else:print("Unfair")

Fixed submission:
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")

Buggy python submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())

if k%2 == 0:
  if abs(a-b)<=10**18:print(a-b)
  else:print("Unfair")
   
else:
    if ans(b-a)<=10*18:print(b-a)
    else:print("Unfair")

Fixed submission:
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k=map(int,input().split())

for i in range(k):
  shifta = b+c; shiftb = a+c; shiftc = a+b
  a=shifta; b=shiftb; c=shiftc
  
  if abs(a-b)>10**18:print("Unfair");exit

print(a-b)

Fixed submission:
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")
Buggy python submission (verdict: Runtime Error):
k,s=map(int,input().split())

asn=o

for i in range(k+1):
  for j in range(k+1):
    if 0<=s-i-j<=k: ans+=1

print(ans)

Fixed submission:
K,S=map(int, input().split())
ans=0

for i in range(K+1):
  for j in range(K+1):
    if 0<=S-i-j<=K :
      ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())

if a >= 0 and c >= 0:
  print(b*d)
elif b <= 0 and d <= 0:
  print(a*c)
elif a < 0 and c < 0:
  if b<=0 or d<=0:
    print(a*c)  
  elif abs(a)>=abs(b) and abs(c)>=abs(d):
    print(a*c)
  else:
    print(b*d)
elif (b<0 and c>=0):
  print(b*c)
elif (a>=0 and d<0):
  print(a*d)
else:
  print(b*d)

Fixed submission:
MOD = 10 ** 9 + 7

N = int(input())

ans = pow(10, N, MOD)
ans -= 2 * pow(9, N, MOD)
ans += pow(8, N, MOD)
ans %= MOD # 最後にMODを取り忘れないように気をつけましょう

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = input()
count = 0

if a == "R" and b == "R" and c == "R":
  count = 3
elif (a == "R" and b == "R") or(b == "R" and c == "R"):
  count = 2
elif a == "R"or b =="R" or C == "R":
  count = 1
else:
  count = 0
  
print(count)

Fixed submission:
a,b,c = input()
count = 0

if a == "R" and b == "R" and c == "R":
  count = 3
elif (a == "R" and b == "R") or(b == "R" and c == "R"):
  count = 2
elif a == "R"or b =="R" or c == "R":
  count = 1
else:
  count = 0
  
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
seven = '7'
sevens ='7'
cnt = 1

if k % 2 ==0:
    print(-1)
else:
    while len(sevens) < 10**6:
        if int(sevens) % k ==0:
            print(cnt)
            break
        else:
            sevens += seven
            cnt += 1

Fixed submission:
k = int(input())
sevens = 7 % k

if k % 2 ==0:
    print(-1)
else:
    for i in range(k):
        if sevens % k ==0:
            print(i+1)
            break
        else:
            sevens = (sevens*10 + 7) % k
    else:
        print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
ans = 0

while c.find('WR') != -1:
    c = c[c.find('W')+1:c.rfind('R')]
    ans += 1
print(ans)

Fixed submission:
n = int(input())
c = input()

w = 0
r = c.count('R')
i = 0
ans = max(w, r)
while i <= n - 1:
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
    i += 1
print(ans)

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

while c.find('WR') != -1:
    leftW = c.find('W')
    rightR = c.rfind('R')
    c = c[leftW+1:rightR]
    ans += 1
print(ans)

Fixed submission:
n = int(input())
c = input()

w = 0
r = c.count('R')
i = 0
ans = max(w, r)
while i <= n - 1:
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
    i += 1
print(ans)

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

while c.find('WR') != -1:
    leftW = c.find('W')
    rightR = c.rfind('R')
    c = c[leftW+1:rightR]
    ans += 1
print(ans)

Fixed submission:
n = int(input())
c = input()

w = 0
r = c.count('R')
i = 0
ans = max(w, r)
while i <= n - 1:
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
    i += 1
print(ans)

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

while c.count('WR') >= 1:
    leftW = c.find('W')
    rightR = c.rfind('R')
    if leftW != -1 and rightR != -1:
        c = c[leftW+1:rightR]
        ans += 1
print(ans)

Fixed submission:
n = int(input())
c = input()

w = 0
r = c.count('R')
i = 0
ans = max(w, r)
while i <= n - 1:
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
cc = c
ans = 0

while cc.count('WR') >= 1:
    leftW = cc.find('W')
    rightR = cc.rfind('R')
    if leftW != -1 and rightR != -1:
        cc = cc[:leftW] + 'R' + cc[leftW+1:rightR] + 'W' + cc[rightR+1:]
        ans += 1
print(ans)

Fixed submission:
n = int(input())
c = input()

w = 0
r = c.count('R')
i = 0
ans = max(w, r)
while i <= n - 1:
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
    i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = a.copy()
bb = b.copy()

aa = [sum(a[:s+1]) for s in range(n)]
bb = [sum(b[:s+1]) for s in range(m)]
      
temp, ans = 0, 0
j = m - 1

for i in range(n):
    if aa[i] > k:
        break
    while bb[j] > k - aa[i]:
        j -= 1
    temp = i+1 + j+1
    if temp > ans:
        ans = temp
        
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = [0]
bb = [0]

for s in range(n):
    aa.append(aa[s] + a[s])
for s in range(m):
    bb.append(bb[s] + b[s])      
ans = 0
j = m

for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k - aa[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = a.copy()
bb = b.copy()

aa = [sum(a[:s+1]) for s in range(n)]
bb = [sum(b[:s+1]) for s in range(m)]
      
temp, ans = 0, 0
j = m - 1

for i in range(n):
    if aa[i] > k:
        break
    while bb[j] > k - a[i]:
        j -= 1
    temp = i+1 + j+1
    if temp > ans:
        ans = temp
        
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = [0]
bb = [0]

for s in range(n):
    aa.append(aa[s] + a[s])
for s in range(m):
    bb.append(bb[s] + b[s])      
ans = 0
j = m

for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k - aa[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

cnt = -1

aa = a.copy()
bb = b.copy()

aa = [sum(a[:s+1]) for s in range(n)]
bb = [sum(b[:s+1]) for s in range(m)]
      
ans = 0

for i in range(n):
    bb_sharp = k - aa[i]
    if bb_sharp < 0:
        break
    else:
        bb_below =[bb[s] for s in range(m) if bb[s] <= bb_sharp]
        temp = i+1 + len(bb_below)
        if temp > ans:
           ans = temp
        
print(ans)

Fixed submission:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = [0]
bb = [0]

for s in range(n):
    aa.append(aa[s] + a[s])
for s in range(m):
    bb.append(bb[s] + b[s])      
ans = 0
j = m

for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k - aa[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

s = sum(a)

for i in range(q):
    cnt = 0
    b, c = map(int, input().split())
    for j in range(n):
        if a[j] == b:
            a[j] = c
            cnt += 1
    s += (c-b)*cnt
    print(s)

Fixed submission:
import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
s = sum(a)

ad = collections.Counter(a)

for i in range(q):
    b, c = map(int, input().split())
    s += ad.get(b, 0) * (c - b) 
    print(s)
    ad[c] += ad.get(b, 0)
    ad[b] = 0
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)

cmb = 0
for x in c.values():
    if x >= 2:
        cmb += math.factorial(x) // (math.factorial(2) * math.factorial(x - 2))  

for z in a:
    y = c.get(z)
    ans = cmb
    if y == 2:
        ans -= 1
    elif y >= 3:
        ans -= (math.factorial(y) // (math.factorial(2) * math.factorial(y - 2))) - (math.factorial(y - 1) // (math.factorial(2) * math.factorial(y - 3)))
    print(ans)

Fixed submission:
import collections
import math

def cmb_factorial(s):
    return math.factorial(s) // (math.factorial(2) * math.factorial(s - 2))

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
f = {}

cmb = 0
for x in c.values():
    f[1] = 0
    f[2] = 1
    if x >= 3:
        f[x] = cmb_factorial(x)
        if x - 1 not in f:
            f[x - 1] = cmb_factorial(x - 1)
    cmb += f.get(x)

for z in a:
    y = c.get(z)
    ans = cmb
    if y >= 2:
        ans = cmb - f.get(y) + f.get(y - 1)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

def prime_check(n):
    if n % 2 == 0:
        return False
    f = 3
    while f * f <= n:
        if n % f == 0:
            return False
        else:
            f += 2
    else:
        return True

if x == 2:
    print(2)
elif x % 2 == 0:
    x += 1

while 1:
    if prime_check(x) == True:
        print(x)
        break
    else:
        x += 2

Fixed submission:
x = int(input())

def prime_check(n):
    f = 3
    while f * f <= n:
        if n % f == 0:
            return False
        else:
            f += 2
    else:
        return True

if x != 2:
    if x % 2 == 0:
        x += 1
    while 1:
        if prime_check(x) == True:
            print(x)
            break
        else:
            x += 2
else:
    print(2)