Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
input()
a = list(map(int,input().split()))
sa = list(set(a))
b = [ i for i in sa if a.count(i)>=2 ]
c = [ i for i in sa if a.count(i)>=4 ]
b=b+c
b.sort(reverse=True)

if len(b)>=2:
    print(b[0]*b[1])
else:
    print(0)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
bn = 0
ans = 0
count = 0
i = 0

while(i<n):
    if bn==a[i]:
        if count == 0:
            ans = a[i]
            if i+1<n:
                bn = a[i+1]
            i += 1
            count +=1
        else:
            ans *= a[i]
            count +=1
            break
    else:
        bn = a[i]
    i +=1

if count>=2:
    print(ans)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
input()
a = list(map(int,input().split()))
sa = list(set(a))
sa.sort(reverse=True)
ans = 0
count = 0

for i in sa:
    if count>=2:
        break

    if a.count(i)>=2:
        if count==0:
            ans = i
            count +=1
            if a.count(i)>3:
                if count < 2:
                    ans *= i
                    count +=1
        else:
            ans *= i
            count +=1


print(ans)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
bn = 0
ans = 0
count = 0
i = 0

while(i<n):
    if bn==a[i]:
        if count == 0:
            ans = a[i]
            if i+1<n:
                bn = a[i+1]
            i += 1
            count +=1
        else:
            ans *= a[i]
            count +=1
            break
    else:
        bn = a[i]
    i +=1

if count>=2:
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
if c[1] + c[3] < c[0] + 1:
    print('Yes')
elif (c[1] + c[3] == c[0] + 1)and(c[2] == 0):
    print('Yes')
else:
    print('No')


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

c = [0,0,0,0]
for x in a:
    c[x % 4] += 1

# if (c[1]==0) and (c[3]==0):
#     print('Yes')

if c[1] + c[3] < c[0] + 1:
    print('Yes')
elif (c[1] + c[3] == c[0] + 1)and(c[2] == 0):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a_n4 = a_4 = [x for x in a if x%4!=0]
a_4 = [x for x in a if x%4==0]
a_2 = [x for x in a if x%4!=0 and x%2==0]

if (len(a_n4)<=1+len(a_4) and len(a_2)<=1) or (len(a_n4)<=len(a_4) and len(a_2)>1) ):
    print("Yes")
else:
    print("No")


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

c = [0,0,0,0]
for x in a:
    c[x % 4] += 1

# if (c[1]==0) and (c[3]==0):
#     print('Yes')

if c[1] + c[3] < c[0] + 1:
    print('Yes')
elif (c[1] + c[3] == c[0] + 1)and(c[2] == 0):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
if n%2==0 :
    for i in range(n):
        if(i%2):
            b.insert(0,a[i])
        else:
            b.append(a[i])

if n%2!=0 :
    for i in range(n):
        if(i%2):
            b.append(a[i])
        else:
            b.insert(0,a[i])


print(*b)

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

if n%2==0 :
    print(*(a[1::2][::-1]+a[0::2]))
else:
    print(*(a[0::2][::-1]+a[1::2]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]

print(*b)


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

if n%2==0 :
    print(*(a[1::2][::-1]+a[0::2]))
else:
    print(*(a[0::2][::-1]+a[1::2]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())
t = s[::-1]
u = s[0::]
#できるだけ左から(を追加 &右から)を追加

#右から数えて最初に(より左にある)の数　と　)より右にある(の数？
v = []
si = s.index(")")
ti = t.index("(")

stock = 0
i = 0

for i in s:
    if i=="(":
        stock+=1
        v.append("(")
    else:
        if stock ==0:
            v.insert(0,"(")
            v.append(")")
        else:
            stock -= 1
            v.append(")")

for i in range(stock):
    v.append(")")

print(*v,sep='')

Fixed submission:
n = int(input())
s = list(input())


v = []


stock = 0

for i in s:
    if i=="(":
        stock+=1
        v.append("(")
    else:
        if stock ==0:
            v.insert(0,"(")
            v.append(")")
        else:
            stock -= 1
            v.append(")")

for i in range(stock):
    v.append(")")

print(*v,sep='')
Buggy python submission (verdict: Runtime Error):
o = list(input())
e = list(input())

for i in range(len(e)):
        print(o[i],e[i],sep="",end="")

if len(e)<len(o):
        print(o[len(o)])

print("")


Fixed submission:
o = list(input())
e = list(input())

for i in range(len(e)):
        print(o[i],e[i],sep="",end="")

if len(e)<len(o):
        print(o[len(o)-1])

print("")

Buggy python submission (verdict: Runtime Error):
o = list(input())
e = list(input())

for i in range(len(o)):
    print(o[i],e[i],sep="",end="")

print("")


Fixed submission:
o = list(input())
e = list(input())

for i in range(len(e)):
        print(o[i],e[i],sep="",end="")

if len(e)<len(o):
        print(o[len(o)-1])

print("")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

for i in range(n):
    a[i][0], a[i][1] = map(int, input().split())

for i in range(n):
    c[i][0], c[i][1] = map(int, input().split())

index = 0

for i in range(n):
    for j in range(m):
        if j == 0 :
            k = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) +1

        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)


Fixed submission:
n, m = map(int, input().split())

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

for i in range(n):
    a[i][0], a[i][1] = map(int, input().split())

for i in range(m):
    c[i][0], c[i][1] = map(int, input().split())

index = 0


for i in range(n):
    for j in range(m):
        if j == 0 :
            k = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) +1

        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

for i in range(n):
    a[i][0], a[i][1] = map(int, input().split())

for i in range(n):
    c[i][0], c[i][1] = map(int, input().split())

index = 0

for i in range(n):
    k = 1<<20
    for j in range(m):
        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)


Fixed submission:
n, m = map(int, input().split())

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

for i in range(n):
    a[i][0], a[i][1] = map(int, input().split())

for i in range(m):
    c[i][0], c[i][1] = map(int, input().split())

index = 0


for i in range(n):
    for j in range(m):
        if j == 0 :
            k = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) +1

        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)
Buggy python submission (verdict: Runtime Error):
a = input().split()
if a[1] == '+':
  print(a[0]+a[2])
else:
  print(a[0]-a[2])

Fixed submission:
a = input().split()
if a[1] == '+':
  print(int(a[0])+int(a[2]))
else:
  print(int(a[0])-int(a[2]))
Buggy python submission (verdict: Runtime Error):
def sum_dict(d, sum, b, c):
    val = 0
    if b in d:
        val = d[b]
        sum -= (b * val)
        del d[b]
        d[c] = d.get(c, 0) + val
        sum += (c * val)
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, b, c)
    print(s)

Fixed submission:
def sum_dict(d, sum, b, c):
    val = 0
    if b in d:
        val = d[b]
        sum -= (b * val)
        del d[b]
        d[c] = d.get(c, 0) + val
        sum += (c * val)
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, s, b, c)
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
def sum_dict(d, b, c):
    val = 0
    sum = 0
    if b in d:
        val = d[b]
        del d[b]
        d[c] = d.get(c, 0) + val
    for i in d.items():
        sum += (i[0] * i[1])
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, b, c)
    print(s)

Fixed submission:
def sum_dict(d, sum, b, c):
    val = 0
    if b in d:
        val = d[b]
        sum -= (b * val)
        del d[b]
        d[c] = d.get(c, 0) + val
        sum += (c * val)
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, s, b, c)
    print(s)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
p = list(map(int, input().split()))
np = [x for x in range(102) if x not in p]
mnd = 103
mnv = 103
for i in np:
	if abs(i - x) < mn:
		mnv = i
		mnd = abs(i - x)
print(mnv)


Fixed submission:
x,n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
  if (x - i) not in p:
    print(x - i)
    break
  elif (x + i) not in p:
    print(x + i)
    break

Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
p = list(map(int, input().split()))
np = [x for x in range(102) if x not in p]
mnd = 103
mnv = 103
for i in np:
  if abs(i - x) < mn:
    mnv = i
    mnd = abs(i - x)
print(mnv)

Fixed submission:
x,n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
  if (x - i) not in p:
    print(x - i)
    break
  elif (x + i) not in p:
    print(x + i)
    break
Buggy python submission (verdict: Runtime Error):
x = int(input())

if x == 0:
    prine(1)
else:
    print(0)


Fixed submission:
x = int(input())

if x == 0:
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
S = int(input())

def seq(n):
    if n == 0:
        return 1
    elif n == 1 or n == 2:
        return 0
    else:
        return seq(n-1) + seq(n-3)

ans = seq(S)
mod = 10 ** 9 + 7
ans %= mod
print(ans)


Fixed submission:
S = int(input())
mod = 10 ** 9 + 7

dp = [1, 0, 0]
cnt = 0
for i in range(3, S+1):
    cnt = dp[i-1] + dp[i-3]
    cnt %= mod
    dp.append(cnt)

ans = dp[S]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

def func(n):
    if n == 1:
        return 0
    else:
        sum = 0
        for i in range(n-1):
            sum += A[i]
        return func(n-1) + sum * A[n-1]

ans = func(N)
mod = 10 ** 9 + 7
print(ans % mod)


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

a = [0]
for i in range(N):
    a.append(a[i] + A[i])

cnt = 0
for i in range(N-1):
    cnt += A[i] * (a[N] - a[i+1])

mod = 10 ** 9 + 7
ans = cnt % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0

for i in range(N):
    for j in range(N):
        if i < j:
            ans += A[i] *A [j]

mod = 10 ** 9 + 7
print(ans % mod)


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

a = [0]
for i in range(N):
    a.append(a[i] + A[i])

cnt = 0
for i in range(N-1):
    cnt += A[i] * (a[N] - a[i+1])

mod = 10 ** 9 + 7
ans = cnt % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
S = int(input())

flag = False
ans = 0
for i in range(len(S)):
    if S[i] == 'R':
        ans += 1
        flag = True
    elif S[i] == 'S' and flag:
        break

print(ans)


Fixed submission:
S = input()

flag = False
ans = 0
for i in range(len(S)):
    if S[i] == 'R':
        ans += 1
        flag = True
    elif S[i] == 'S' and flag:
        break

print(ans)

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

flag = False
ans = 0
for i in range(len(S)):
    if S[i] == 'R':
        ans += 1
        flag = True
    elif S[i] == 'S' ans flag:
        break

print(ans)


Fixed submission:
S = input()

flag = False
ans = 0
for i in range(len(S)):
    if S[i] == 'R':
        ans += 1
        flag = True
    elif S[i] == 'S' and flag:
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(N):
    j = N // i
    ans += i * j * (j+1) / 2

print(ans)


Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1):
    j = N // i
    ans += i * j * (j+1) // 2

print(ans)

Buggy python submission (verdict: Runtime Error):
ans = 0
for i in range(N):
    j = N // i
    ans += i * j * (j+1) / 2

print(ans)


Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1):
    j = N // i
    ans += i * j * (j+1) // 2

print(ans)
Buggy python submission (verdict: Runtime Error):
x = list(map(int, input().split()))
for i in range(x):
    if x[i] == 0:
        print(i+1)
        break


Fixed submission:
x = list(map(int, input().split()))
for i in range(len(x)):
    if x[i] == 0:
        print(i+1)
        break

Buggy python submission (verdict: Runtime Error):
x = list(map(int, input().split()))
for i in range(x):
    if x[i] == 0:
        print(i)
        break


Fixed submission:
x = list(map(int, input().split()))
for i in range(len(x)):
    if x[i] == 0:
        print(i+1)
        break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
set_list = []
count = 0

for i in range(N):
    S = input()
    if not S in set_list:
        set_list.append(S)
        count += 1

print(count)

Fixed submission:
N = int(input())
set_list = set()

for i in range(N):
    S = input()
    set_list.add(S)

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

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

K = int(input())

sum1 = 0
sum2 = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            if i =< j =< k:
                sum1 += gcd(i, j, k)
            if i == j == k:
                sum2 += gcd(i, j, k)

print(sum1 * 3 - sum2 * 2)


Fixed submission:
import math
from functools import reduce

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

K = int(input())

sum1 = 0
sum2 = 0
sum3 = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            if i <= j <= k:
                sum1 += gcd(i, j, k)
                if i == j == k:
                    sum2 += gcd(i, j, k)
                if (i == j != k) or (j == k != i) or (k == i != j):
                    sum3 += gcd(i, j, k)

print(sum1 * 6 - sum2 * 5 - sum3 * 3)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

K = int(input())

sum = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum += gcd(i, j, k)

print(sum)


Fixed submission:
import math
from functools import reduce

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

K = int(input())

sum1 = 0
sum2 = 0
sum3 = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            if i <= j <= k:
                sum1 += gcd(i, j, k)
                if i == j == k:
                    sum2 += gcd(i, j, k)
                if (i == j != k) or (j == k != i) or (k == i != j):
                    sum3 += gcd(i, j, k)

print(sum1 * 6 - sum2 * 5 - sum3 * 3)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

print(N(N - 1) // 2 + M(M - 1) // 2)


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

print(N * (N - 1) // 2 + M * (M - 1) // 2)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

N1 = min(H, W)
N2 = max(H, W)

if N1 % 2 == 0:
  count = (N1 * N2) // 2
else:
  count = (N1 * (N1 -1) + N1 + 1) // 2
  if (N2 - N1) % 2 == 0:
    count += (N1 * (N2 - N1)) // 2
  else:
    count += (N1 * (N2 - N1 - 1) + N1 - 1) // 2

print(count)

Fixed submission:
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(nums[K-1])
Buggy python submission (verdict: Runtime Error):
A, B, M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

result = min(a) + min(b)
for i in range(M):
  x, y, c = map(int, input().split())
  sum = a[x] + b[y] - c
  if sum < result:
    result = sum

print(result)

Fixed submission:
A, B, M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

result = min(a) + min(b)
for i in range(M):
  x, y, c = map(int, input().split())
  sum = a[x-1] + b[y-1] - c
  if sum < result:
    result = sum

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

a = []
for i in range(n):
    d,e = map(int,input().split())
    a.append([d,e])


b = []
for i in range(n):
    if a[i][0] == a[i][1]:
        b.append(1)
    else:
        b.append(0)

c = 0
for i in range(n):
    if b[i] == 1 and b[i+1] == 1 and b[i+2] == 1:
        c = 1
        break

if c == 1:
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())

a = []
for i in range(n):
    d,e = map(int,input().split())
    a.append([d,e])


b = []
for i in range(n):
    if a[i][0] == a[i][1]:
        b.append(1)
    else:
        b.append(0)

c = 0
for i in range(n-2):
    if b[i] == 1 and b[i+1] == 1 and b[i+2] == 1:
        c = 1
        break

if c == 1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
d = 10 ** 9 + 7
n = int(input())

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

s = 0
for i in range(n):
    b = 0
    for j in range(i + 1,n):
        b += a[j]
        b %= d
    c = a[i] % d
    s += c * b
    s %= d

print(s)


Fixed submission:
d = 10 ** 9 + 7
n = int(input())

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


s = 0
for i in range(n):
    s += a[i]
    s %= d

ans = 0

b = 0
for i in range(n):
    b += a[i] ** 2
    b %= d

ans = s ** 2 - b
ans %= d

if ans % 2 == 0:
    ans //= 2
else:
    ans += d
    ans //= 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())

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

b = []
for i in range(k-1,n):
    c = 1
    for j in range(k):
        c *= a[i - j]
    b.append(c)

for i in range(n-k):
    if b[i] < b[i + 1]:
        print("Yes")
    else:
        print("No")


Fixed submission:
n,k = map(int,input().split())

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

for i in range(k,n):
    if a[i-k] < a[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
#c
n,m,k = map(int,input().split())

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

b = list(map(int,input().split()))

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


ans = 0
j = q-1
for i in range(n):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Fixed submission:
n,m,k = map(int,input().split())

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

b = list(map(int,input().split()))


c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


ans = 0
j = m
for i in range(n+1):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())

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

b = list(map(int,input().split()))

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(n):
    f += b[i]
    e.append(f)


ans = 0
j = q-1
for i in range(n):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Fixed submission:
n,m,k = map(int,input().split())

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

b = list(map(int,input().split()))


c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


ans = 0
j = m
for i in range(n+1):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())

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

b = list(map(int,input().split()))

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)
    if d > k:
        break

e = [0]
f = 0
for i in range(n):
    f += b[i]
    e.append(f)
    if f > k:
        break

p = len(c)
q = len(e)

ans = 0
j = q-1
for i in range(p):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Fixed submission:
n,m,k = map(int,input().split())

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

b = list(map(int,input().split()))


c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


ans = 0
j = m
for i in range(n+1):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())

def f(x,k):
    return (abs(x-k) < x)

while(f(n,k)):
    n = abs(n-k)

print(n)

Fixed submission:
n,k = map(int,input().split())

def f(x,k):
    return (abs(x-k) < x)

n = divmod(n,k)[1]

while(f(n,k)):
    n = abs(n-k)

print(n)