Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def rec(edges, nodes, cp, cdistance, visited):
    if not visited[cp]:
        visited[cp] = True
        nodes[cp] = (cdistance % 2 == 0)
        if edges[cp]:
            for v, w in edges[cp]:
                rec(edges, nodes, v, cdistance + w, visited)


def main():
    N = int(input())
    nodes = [False] * N
    visited = [False] * N
    edges = [[] for _ in range(N)]

    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        edges[u - 1].append((v - 1, w))
        edges[v - 1].append((u - 1, w))

    rec(edges, nodes, 0, 0, visited)

    for n in nodes:
        print(0 if n else 1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**9)


def rec(edges, nodes, cp, cdistance, visited):
    if not visited[cp]:
        visited[cp] = True
        nodes[cp] = (cdistance % 2 == 0)
        if edges[cp]:
            for v, w in edges[cp]:
                rec(edges, nodes, v, cdistance + w, visited)


def main():
    N = int(input())
    nodes = [False] * N
    visited = [False] * N
    edges = [[] for _ in range(N)]

    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        edges[u - 1].append((v - 1, w))
        edges[v - 1].append((u - 1, w))

    rec(edges, nodes, 0, 0, visited)

    for n in nodes:
        print(0 if n else 1)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue


def main():
    tosearch = Queue()

    H, W = map(int, input().split())

    grid = [[-1 for _ in range(W + 2)]]
    for i in range(H):
        line = list(input())

        index = -1
        while "#" in line[index+1:]:
            index = line.index("#", start=index+1)
            tosearch.put((i + 1, index + 1))

        grid.append([-1] + [0 if char == "#" else -2 for char in line] + [-1])
    grid.append([-1 for _ in range(W + 2)])



    movement = [(-1, 0), (1, 0), (0, -1), (0, 1)]

    while not tosearch.empty():
        y, x = tosearch.get()

        for move in movement:
            ny, nx = y + move[0], x + move[1]

            if grid[ny][nx] == -2:
                grid[ny][nx] = grid[y][x] + 1
                tosearch.put((ny, nx))

    ans = 0
    for line in grid:
        ans = max(ans, max(line))

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque

def main():
    tosearch = deque()

    H, W = map(int, input().split())

    grid = [[-1 for _ in range(W + 2)]]
    for i in range(H):
        grid.append([-1] + [0 if char == "#" else -2 for char in input()] + [-1])
    grid.append([-1 for _ in range(W + 2)])

    for i, line in enumerate(grid):
        for j, char in enumerate(line):
            if char == 0:
                tosearch.append((i, j))

    movement = [(-1, 0), (1, 0), (0, -1), (0, 1)]

    while tosearch:
        y, x = tosearch.popleft()

        for move in movement:
            ny, nx = y + move[0], x + move[1]

            if grid[ny][nx] == -2:
                grid[ny][nx] = grid[y][x] + 1
                tosearch.append((ny, nx))

    ans = 0
    for line in grid:
        ans = max(ans, max(line))

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

import itertools

def main():
    X, Y, Z, K = map(int, input().split())
    data = [list(map(int, input().split())) for _ in range(3)]

    a_add_b = [[i + j for i in data[0]] for j in data[1]]
    a_add_b = list(itertools.chain(*a_add_b))
    a_add_b.sort()
    e_add_c = [[i + j for i in a_add_b[-K:]] for j in data[2]]
    e_add_c = list(itertools.chain(*e_add_c))
    e_add_c.sort()

    e_add_c = e_add_c[::-1]

    for abc in e_add_c[:K]:
        print(abc)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/python3

import numpy as np
import itertools

def main():
    X, Y, Z, K = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    C = np.array(list(map(int, input().split())))

    a_add_b = np.array(list(A + j for j in B))
    a_add_b = np.sort(a_add_b, axis=None)

    e_add_c = np.array(list(C + j for j in a_add_b[:-K-1:-1]))
    e_add_c = np.sort(e_add_c, axis=None)


    for abc in e_add_c[:-K-1:-1]:
        print(abc)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = list(input())
del s[-1]
sSet = set(s) 

death = 0

for i in range(Q):
	t, d = input().split()

	if t in sSet:
		tmpS = s.copy()
		for index, golems in enumerate(tmpS):
			if t in golems:
				if d == 'L' and index == 0: 
					s[index] = ""
					death += len(golems) 
				elif d == 'L':
					s[index-1] = tmpS[index-1] + golems
					s[index] = ""
				elif d == 'R' and index == N - 1:
					s[index] = ""
					death += len(golems)
				else:
					s[index+1] = tmpS[index+1] + golems
					s[index] = ""


print(len(s) - death)


Fixed submission:
a, b, c = map(int, input().split())
res = "Yes" if a == b == c else "No"
print(res)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split()) 

if a==1 or b==1 or k==1:
	print(1)
	exit()

divisorA = [ i for i in range(1,a ) if a % i == 0 ]
divisorB = [ i for i in range(1,b ) if b % i == 0 ]

divisor = set(divisorA + divisorB)

divisor = sorted(divisor &  set(divisorA) )

print( divisor[k-1] )

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

divisorA = [ i for i in range(1,a+1 ) if a % i == 0 ]
divisorB = [ i for i in range(1,b+1 ) if b % i == 0 ]

divisor = []

for elemA in divisorA:
	divisor += filter(lambda elem: elem == elemA, divisorB)	

divisor = sorted(divisor)
divisor = divisor[::-1]
# print(divisor)

print( divisor[k-1] )
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

def main():
    N, W = map(int, input().split())

    dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

    for i in range(N):
        weight, value = map(int, input().split())

        for w in range(W + 1):
            if w < weight:
                dp[i+1][w] = dp[i][w]

            else:
                dp[i+1][w] = max(dp[i][w], dp[i][w-weight] + value)

    print(dp[-1][-1])

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/python3

import numpy as np
def main():
    N, W = map(int, input().split())

    dp = np.zeros((N+1, W+1), dtype='uint64')

    for i in range(N):
        weight, value = map(int, input().split())

        dp[i+1][:weight] = dp[i][:weight]
        dp[i+1][weight:] = np.maximum(dp[i][weight:], dp[i][:-weight] + value)

    print(dp[-1][-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3

import numpy as np

def main():
    N, W = map(int, input().split())

    dp = np.zeros((N+1, W+1), dtype='uint16')

    for i in range(N):
        weight, value = map(int, input().split())

        dp[i+1][:weight] = dp[i][:weight]
        dp[i+1][weight:] = np.maximum(dp[i][weight:], dp[i][:-weight] + value)

    print(dp[-1][-1])

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/python3

import numpy as np

def main():
    N, W = map(int, input().split())

    dp = np.full((N+1, N * (10**3) +1), np.inf)
    dp[0][0] = 0

    for i in range(N):
        weight, value = map(int, input().split())

        dp[i+1][:value] = dp[i][:value]
        dp[i+1][value:] = np.minimum(dp[i][value:], dp[i][:-value] + weight)


    res = 0
    for i, weight in enumerate(dp[N]):
        if weight <= W: res = i

    print(res)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c = map(int, input().split())
counter = 0

while c + b > 0 and a + b > 0:
	# print(a, b, c, counter)
	counter += 1
	if c > 0:
		c -= 1
		if b > 0:
			counter += 1
			b -= 1
		else:
			a -= 1
	elif b > 0:
		b -= 1

if c > 0:
	counter += 1
else:
	counter += b

print(counter)

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

tmp_eatable = min(b, c)

counter += tmp_eatable * 2
b -= tmp_eatable
c -=tmp_eatable
# print(a, b, c, counter)
if c > 0 :
	tmp_eatable = min(a, c)
	counter += tmp_eatable
	c -= tmp_eatable
	# print(a, b, c, counter)
	if c > 0 :
		counter += 1

else :
	counter += b

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

D, G = map(int, input().split())
pc = [tuple(map(int, input().split())) for _ in range(D)]

memo = dict()


def rec(crp, crscore, crans):
    global D, G, pc, memo

    if (crp, crscore) in memo:
        return memo[(crp, crscore)] + crans

    if crscore >= G:
        return crans
    elif crp > D:
        return 10**9

    p, c = pc[crp - 1]

    tmp_min = min(
        rec(crp + 1, crscore + 100 * crp * i, crans + i) for i in range(p)
    )

    res = min(tmp_min, rec(crp + 1, crscore + 100 * crp * p + c, crans + p))
    memo[(crp, crscore)] = res - crans
    return res


print(rec(1, 0, 0))


Fixed submission:
from itertools import product


D, G = map(int, input().split())
pc = [tuple(map(int, input().split())) for _ in range(D)]


ans = 1e9
for selected in product((True, False), repeat=D):
    tmp_score = 0
    tmp_count = 0
    rest_max = 0

    for i, is_select in enumerate(selected):
        if is_select:
            tmp_score += 100 * (i + 1) * pc[i][0] + pc[i][1]
            tmp_count += pc[i][0]
        else:
            rest_max = i

    if tmp_score < G:
        s1 = 100 * (rest_max + 1)
        need = (G - tmp_score + s1 - 1) // s1

        if need >= pc[rest_max][0]:
            continue

        tmp_count += need

    ans = min(ans, tmp_count)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

D, G = map(int, input().split())
pc = [tuple(map(int, input().split())) for _ in range(D)]

memo = dict()


def rec(crp, crscore, crans):
    global D, G, pc, memo

    if (crp, crscore, crans) in memo:
        return memo[(crp, crscore, crans)]

    if crscore >= G:
        return crans
    elif crp > D:
        return 10**9

    p, c = pc[crp - 1]

    tmp_min = min(
        rec(crp + 1, crscore + 100 * crp * i, crans + i) for i in range(p)
    )

    res = min(tmp_min, rec(crp + 1, crscore + 100 * crp * p + c, crans + p))
    memo[(crp, crscore, crans)] = res
    return res


print(rec(1, 0, 0))


Fixed submission:
from itertools import product


D, G = map(int, input().split())
pc = [tuple(map(int, input().split())) for _ in range(D)]


ans = 1e9
for selected in product((True, False), repeat=D):
    tmp_score = 0
    tmp_count = 0
    rest_max = 0

    for i, is_select in enumerate(selected):
        if is_select:
            tmp_score += 100 * (i + 1) * pc[i][0] + pc[i][1]
            tmp_count += pc[i][0]
        else:
            rest_max = i

    if tmp_score < G:
        s1 = 100 * (rest_max + 1)
        need = (G - tmp_score + s1 - 1) // s1

        if need >= pc[rest_max][0]:
            continue

        tmp_count += need

    ans = min(ans, tmp_count)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

from bisect import bisect_left


def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    res = 0
    for a in A:
        t = bisect_left(B, a + 1)
        for b in B[t:]:
            s = bisect_left(C, b + 1)
            res += N - s

    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/python3

from bisect import bisect_left, bisect_right


def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    res = 0
    for b in B:
        res += bisect_left(A, b) * (N - bisect_right(C, b))

    print(res)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%10 in (2,4,5,7,9):
    print ('hon')
elif n%10 in (0,1,6,8):
    print ('pon')
else:
    print('bon')


Fixed submission:
x = input()
if x.upper() == x:
    print("A")
else:
    print("a")

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env pypy3
n=int(input())
if n%10 in (2,4,5,7,9):
    print ('hon')
elif n%10 in (0,1,6,8):
    print ('pon')
else:
    print('bon')


Fixed submission:
x = input()
if x.upper() == x:
    print("A")
else:
    print("a")

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

keta = 0
tmp = 26
beki = [26]

while True:
    if n <= beki[-1]:
        break
    tmp *= 26
    beki.append(beki[-1] + tmp)
    keta += 1
n_tmp = n
ans_num = []

n_tmp -= beki[keta - 1] + 1
for i in range(keta):
    waru = 26**(keta - i)
    x = (n_tmp) // waru
    ans_num.append(x)
    n_tmp -= x * waru

ans_num.append(n_tmp)
ans = ''

for d in ans_num:
    ans += chr(d + 97)

if n <= 26:
    print(chr(n + 96))
else:
    print(ans)

Fixed submission:
x = input()
if x.upper() == x:
    print("A")
else:
    print("a")
Buggy python submission (verdict: Runtime Error):
1 1
1000

Fixed submission:
n,k = list(map(int, input().split(' ')))
p = list(map(int, input().split(' ')))
p.sort()
print(sum(p[:k]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
tmp = 1
dat = list(map(int, input().split(" ")))
for d in dat:
    tmp *= d

if tmp > 1000000000000000000:
    print ("-1")
else:
    print (tmp)

Fixed submission:
n=int(input())
tmp = 1
dat = list(map(int, input().split(" ")))
#print(dat, (0 in dat))
over = False
if 0 in dat:
    print ("0")
else:
    for d in dat:
        tmp *= d
        if tmp > 1000000000000000000:
            print ("-1")
            over = True
            break
    if not over:
        print (tmp)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
tmp = 1
dat = input().split(" ")
for d in dat:
    tmp *= int(d)

if tmp > 1000000000000000000:
    print ("-1")
else:
    print (tmp)

Fixed submission:
n=int(input())
tmp = 1
dat = list(map(int, input().split(" ")))
#print(dat, (0 in dat))
over = False
if 0 in dat:
    print ("0")
else:
    for d in dat:
        tmp *= d
        if tmp > 1000000000000000000:
            print ("-1")
            over = True
            break
    if not over:
        print (tmp)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
tmp = 1
dat = input().split(" ")
for d in dat:
    tmp *= int(d)

if tmp > 1000000000000000000:
    print ("-1")
else:
    print (tmp)

Fixed submission:
n=int(input())
tmp = 1
dat = list(map(int, input().split(" ")))
#print(dat, (0 in dat))
over = False
if 0 in dat:
    print ("0")
else:
    for d in dat:
        tmp *= d
        if tmp > 1000000000000000000:
            print ("-1")
            over = True
            break
    if not over:
        print (tmp)
Buggy python submission (verdict: Runtime Error):
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

pidx = 0
qidx = 0
for i in range(x+y):
  ptmp = 0
  qtmp = 0
  valid_p = True
  valid_q = True
  if pidx < a:
  	ptmp = p[pidx]
  else:
    valid_p = False
  if qidx < b:
    qtmp = q[qidx]
  else:
    valid_q = False
  sel_p = True # pを探索
  if valid_q:
    if not valid_p:
      sel_p = False
    elif ptmp<qtmp:
      sel_p = False
  rtmp = r[c - 1 - i] # 逆順
  if sel_p:
    if ptmp < rtmp and pidx < a:
      p[pidx] = rtmp
      pidx += 1
  else:
    if qtmp < rtmp and qidx < b:
      q[qidx] = rtmp
      qidx += 1
print (sum(p) + sum(q))

Fixed submission:
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

z = sorted(p+q+r)[-x-y:]

print (sum(z))

Buggy python submission (verdict: Runtime Error):
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

pidx = 0
qidx = 0
for i in range(c):
  ptmp = p[pidx]
  qtmp = q[pidx]
  rtmp = r[c - 1 - i] # 逆順
  if ptmp < qtmp:
    if ptmp < rtmp:
      p[pidx] = rtmp
      pidx += 1
  else:
    if qtmp < rtmp:
      q[qidx] = rtmp
      qidx += 1
print (sum(p) + sum(q))

Fixed submission:
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

z = sorted(p+q+r)[-x-y:]

print (sum(z))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n=int(input())
a=list(map(int, input().split(' ')))
c = collections.Counter(a)

def n_c_2(val):
  ret = 0
  if val > 1:
    ret = (val)*(val-1)//2
  return ret

org_nc2 = {}
org_minus1_nc2 = {}
ans = {}

for k in list(c.keys()):
  org_nc2[k] = n_c_2(c[k])
for k in list(c.keys()):
  org_minus1_nc2[k] = n_c_2(c[k] - 1)
for k in list(c.keys()):
  tmp = 0
  for j in list(c.keys()):
    if j==k:
      tmp += org_minus1_nc2[j]
    else:
      tmp += org_nc2[j]
  ans[k] = tmp

for d in a:
  print (ans[d])


Fixed submission:
import collections
n=int(input())
a=list(map(int, input().split(' ')))
c = collections.Counter(a)

def n_c_2(val):
  ret = 0
  if val > 1:
    ret = (val)*(val-1)//2
  return ret

org_nc2 = {}
org_minus1_nc2 = {}
sumall = 0
for k in list(c.keys()):
  org_nc2[k] = n_c_2(c[k])
  org_minus1_nc2[k] = n_c_2(c[k] - 1)
  sumall += org_nc2[k]
for d in a:
  ans = sumall - org_nc2[d] + org_minus1_nc2[d]
  print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n=int(input())
a=list(map(int, input().split(' ')))
c = collections.Counter(a)


def n_c_2(val):
  ret = 0
  if val > 1:
    ret = (val)*(val-1)//2
  return ret

org_nc2 = {}
org_minus1_nc2 = {}

for k in list(c.keys()):
  org_nc2[k] = n_c_2(c[k])
for k in list(c.keys()):
  org_minus1_nc2[k] = n_c_2(c[k] - 1)

for d in a:
  ans = 0
  for k in list(c.keys()):
    if d == k:
      ans += org_minus1_nc2[k]
    else:
      ans += org_nc2[k]
  print (ans)

Fixed submission:
import collections
n=int(input())
a=list(map(int, input().split(' ')))
c = collections.Counter(a)

def n_c_2(val):
  ret = 0
  if val > 1:
    ret = (val)*(val-1)//2
  return ret

org_nc2 = {}
org_minus1_nc2 = {}
sumall = 0
for k in list(c.keys()):
  org_nc2[k] = n_c_2(c[k])
  org_minus1_nc2[k] = n_c_2(c[k] - 1)
  sumall += org_nc2[k]
for d in a:
  ans = sumall - org_nc2[d] + org_minus1_nc2[d]
  print (ans)
Buggy python submission (verdict: Runtime Error):
a=input()
ret = True
for s in a:
	sum = 0
	for t in _in:
		if s==t:
			sum += 1
	if sum != 2:
		ret = False
if ret:
	print("Yes")
else:
	print ("No")

Fixed submission:
a=input()
ret = True
for s in a:
	sum = 0
	for t in a:
		if s==t:
			sum += 1
	if sum != 2:
		ret = False
if ret:
	print("Yes")
else:
	print ("No")
Buggy python submission (verdict: Runtime Error):
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[h*i+j]='r'
		if v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)

Fixed submission:
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[w*i+j]='r'
		if v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	#print(v)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[h*i+j]='r'
		elif v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	#print(LL)
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)	

Fixed submission:
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[w*i+j]='r'
		if v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)
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()))
a=0
b=0
cnt=0
for i in range(max(n+1,m+1)):
	if min(A[a],B[b])>k:
		break
	if A[a]>=B[b]:
		k-=B[b]
		b+=1
		cnt+=1
	else:
		k-=A[a]
		a+=1
		cnt+=1
print(cnt)

Fixed submission:
n,m,k=map(int, input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
import bisect
AR=[0]
BR=[0]
for i in range(n):
	AR.append(A[i]+AR[i])
for i in range(m):
	BR.append(B[i]+BR[i])

ans=0
for i in range(n+1):
	if AR[i]>k:
		break
	s=k-AR[i]
	t=bisect.bisect(BR,s)-1
	ans=max(ans,i+t)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
L= list(map(int, input().split()))
S=[0]*n
S[0]=1
p=0
cnt=0
for i in range(n):
	if L[p] in S:
		cnt+=1
		S[i+1]=L[p]
		break
	else:
		cnt+=1
		S[i+1]=L[p]
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:cnt]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print(S[k])
else:
	print(S2[(k-cnt)%loop])


Fixed submission:
n, k = map(int, input().split())
L= list(map(int, input().split()))
S=[]
S.append(1)
Q=set()
Q.add(1)
p=0
cnt=0
for i in range(n):
	if L[p] in Q:
		cnt+=1
		S.append(L[p])
		break
	else:
		cnt+=1
		S.append(L[p])
		Q.add(L[p])
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print(S[k])
else:
	print(S2[(k-cnt)%loop])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
L= list(map(int, input().split()))
S=[]
S.append(1)
p=0
cnt=0
for i in range(n):
	if L[p] in S:
		cnt+=1
		S.append(L[p])
		break
	else:
		cnt+=1
		S.append(L[p])
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print(S[k])
else:
	print(S2[(k-cnt)%loop])

Fixed submission:
n, k = map(int, input().split())
L= list(map(int, input().split()))
S=[]
S.append(1)
Q=set()
Q.add(1)
p=0
cnt=0
for i in range(n):
	if L[p] in Q:
		cnt+=1
		S.append(L[p])
		break
	else:
		cnt+=1
		S.append(L[p])
		Q.add(L[p])
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print(S[k])
else:
	print(S2[(k-cnt)%loop])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L=[]
for i in range(n):
	s= input()
	if s not in L:
		L.append(s)

print(len(L))

Fixed submission:
n = int(input())
A=set()
B=set()

for i in range(n):
	s = input()
	if len(s)>=5:
		A.add(s)
	else:
		B.add(s)
		
print(len(A)+len(B))