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

from app.ABC102_C import run


class TestSample(unittest.TestCase):
    def test_run(self):
        self.assertEqual(run(5, [2, 2, 3, 5, 5]), 2)
        self.assertEqual(run(9, [1, 2, 3, 4, 5, 6, 7, 8, 9]), 0)
        self.assertEqual(run(6, [6, 5, 4, 3, 2, 1]), 18)
        self.assertEqual(run(7, [1, 1, 1, 1, 2, 3, 4]), 6)


if __name__ == '__main__':
    unittest.main()

Fixed submission:
def run(n, a):
    a = [a[i]-i-1 for i in range(len(a))]
    a.sort()
    m = a[int((n-1)/2)]
    ret = 0
    for ai in a:
        ret += abs(ai - m)
    return ret


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def run(n, a):
    sum_a = [sum(a[0:i+1]) for i in range(n)]
    ret = sum_a[n - 1]
    for i in range(2, n-1):
        j_l = search_j(sum_a[: i], 0)
        j_r = search_j(sum_a[i:], sum_a[i - 1]) + i
        p = sum_a[j_l]
        q = sum_a[i - 1] - p
        r = sum_a[j_r] - q - p
        s = sum_a[n - 1] - r - q - p
        diff = max(p, q, r, s) - min(p, q, r, s)
        if ret > diff:
            ret = diff
    return ret


def search_j(sum_a, before):
    n = len(sum_a)
    sum_l = sum_a[0] - before
    sum_r = sum_a[n - 1] - sum_a[0]
    diff1 = sum_r - sum_l
    ret = 0
    for i in range(n - 1):
        sum_l = sum_a[i] - before
        sum_r = sum_a[n - 1] - sum_a[i]
        diff2 = sum_r - sum_l
        if diff2 < 0:
            if abs(diff1) < abs(diff2):
                return i - 1
            else:
                return i
        else:
            diff1 = diff2
            ret = i
    return ret


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()


Fixed submission:
from itertools import accumulate


def run(n, a):
    # sum_a = [sum(a[0:i+1]) for i in range(n)]
    sum_a = list(accumulate(a))
    li = 0
    ri = 2
    t = sum_a[-1]
    diff = sum_a[-1]
    # 真ん中の切れ込みを順に変更
    # 左の切れ込みの位置はiに対して単調増加
    # 左の切れ込みで真ん中の項を移動するかどうかは、
    # 真ん中の項を除いて、小さい方に入れる
    # ただし単調増加なので、左の切れ込みの左側が
    # 小さいときに真ん中を左の切れ込みの左側に入れる
    # 右も同様に考える
    for i in range(1, n-2):
        while sum_a[i] > sum_a[li+1] + sum_a[li]:
            li += 1
        while t + sum_a[i] > sum_a[ri+1] + sum_a[ri]:
            ri += 1
        p = sum_a[li]
        q = sum_a[i] - p
        r = sum_a[ri] - q - p
        s = t - sum_a[ri]
        diff = min(diff, max(p, q, r, s) - min(p, q, r, s))
    return diff


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def run(n, a):
    cnt = 0
    for i in range(n):
        while a[i] % 2 == 0:
            a[i] /= 2
            cnt += 1
    return cnt


def read_line():
    n = input().split()
    a = input().split()
    n = int(n)
    a = [int(a[i] for i in range(len(a)))]
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()


Fixed submission:
def run(n, a):
    cnt = 0
    for i in range(n):
        while a[i] % 2 == 0:
            a[i] /= 2
            cnt += 1
    return cnt


def read_line():
    n, = input().split()
    a = input().split()
    n = int(n)
    a = [int(a[i]) for i in range(n)]
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def run(N, C, D, c):
    '''
    マス番号に応じて3色に塗る必要がある
    (i+j)%3が0, 1, 2それぞれに対して、ある色に塗るコストを計算する
    0, 1, 2それぞれのC色のコストのパターンができる
    上記コストに対してC色から3色を選択する全パターンのうち最小のコストを求める
    '''
    cost0 = {}
    cost1 = {}
    cost2 = {}
    for k in range(C):
        cost0[k] = 0
        cost1[k] = 0
        cost2[k] = 0
        for i in range(N):
            for j in range(N):
                if (i+j+2) % 3 == 0:
                    color = c[i][j] - 1
                    cost = D[color][k]
                    cost0[k] += cost
                elif (i+j+2) % 3 == 1:
                    color = c[i][j] - 1
                    cost = D[color][k]
                    cost1[k] += cost
                elif (i+j+2) % 3 == 2:
                    color = c[i][j] - 1
                    cost = D[color][k]
                    cost2[k] += cost
    ret = max(cost0.values()) + max(cost1.values()) + max(cost2.values())
    for i in range(C):
        for j in range(C):
            for k in range(C):
                if i == j or j == k or k == i:
                    continue
                else:
                    ret = min(ret, cost0[i]+cost1[j]+cost2[k])
    return ret


def main():
    N, C = map(int, input().split())
    D = []
    for i in range(C):
        D.append(list(map(int, input().split())))
    c = []
    for i in range(N):
        c.append(list(map(int, input().split())))
    print(run(N, C, D, c))


if __name__ == '__main__':
    main()

Fixed submission:
def run(N, C, D, c):
    '''
    マス番号に応じて3色に塗る必要がある
    (i+j)%3が0, 1, 2それぞれに対して、何色が何個あるか計算しておく
    ある色に塗るコストを計算する
    0, 1, 2それぞれのC色のコストのパターンができる
    上記コストに対してC色から3色を選択する全パターンのうち最小のコストを求める
    '''
    color0 = {}
    color1 = {}
    color2 = {}
    for k in range(C):
        color0[k] = 0
        color1[k] = 0
        color2[k] = 0
    for i in range(N):
        for j in range(N):
            color = c[i][j] - 1
            if (i+j+2) % 3 == 0:
                color0[color] += 1
            elif (i+j+2) % 3 == 1:
                color1[color] += 1
            elif (i+j+2) % 3 == 2:
                color2[color] += 1
    cost0 = {}
    cost1 = {}
    cost2 = {}
    for k in range(C):
        cost0[k] = 0
        cost1[k] = 0
        cost2[k] = 0
        for i in range(C):
            cost = D[i][k]
            cost0[k] += cost * color0[i] 
            cost1[k] += cost * color1[i] 
            cost2[k] += cost * color2[i] 
    ret = max(cost0.values()) + max(cost1.values()) + max(cost2.values())
    for i in range(C):
        for j in range(C):
            for k in range(C):
                if i == j or j == k or k == i:
                    continue
                else:
                    ret = min(ret, cost0[i]+cost1[j]+cost2[k])
    return ret


def main():
    N, C = map(int, input().split())
    D = []
    for i in range(C):
        D.append(list(map(int, input().split())))
    c = []
    for i in range(N):
        c.append(list(map(int, input().split())))
    print(run(N, C, D, c))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def run(N, A):
    r = 0
    A_sum = 0
    A_xor = 0
    A_and = 0
    r = -1
    cnt = 0
    for l in range(N):
        while (A_sum - A_xor == 2*A_and) and r < N-1:
            r += 1
            A_sum += A[r]
            A_xor ^= A[r]
            A_and &= A[r]
        if A_sum - A_xor == 2*A_and:
            cnt += r - l + 1
        else:
            cnt += r - l
        '''
        元に戻す
        xor:
        0 0 => 0
        0 1 => 1
        1 0 => 1
        1 1 => 0
        '''
        A_sum -= A[l]
        A_xor ^= A[l]
        A_and = 2*(A_sum - A_xor)
    return cnt


def main():
    N = int(input())
    A = map(int, input().split())
    print(run(N, A))


if __name__ == '__main__':
    main()


Fixed submission:
def run(N, A):
    r = 0
    A_sum = 0
    A_xor = 0
    A_and = 0
    r = -1
    cnt = 0
    for l in range(N):
        while (A_sum - A_xor == 2*A_and) and r < N-1:
            r += 1
            A_sum += A[r]
            A_xor ^= A[r]
            A_and &= A[r]
        if A_sum - A_xor == 2*A_and:
            cnt += r - l + 1
        else:
            cnt += r - l
        '''
        元に戻す
        xor:
        0 0 => 0
        0 1 => 1
        1 0 => 1
        1 1 => 0
        '''
        A_sum -= A[l]
        A_xor ^= A[l]
        A_and = 2*(A_sum - A_xor)
    return cnt


def main():
    N = int(input())
    A = list(map(int, input().split()))
    print(run(N, A))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import unittest

from D import run, primes


class TestSample(unittest.TestCase):
    def test_run(self):
        self.assertEqual(run(5), '11 31 41 61 71')
        self.assertEqual(run(6), '11 31 41 61 71 101')
        self.assertEqual(run(7), '11 31 41 61 71 101 131')

    def test_primes(self):
        self.assertEqual(primes(5), [2, 3, 5])
        self.assertEqual(primes(20), [2, 3, 5, 7, 11, 13, 17, 19])


if __name__ == '__main__':
    unittest.main()


Fixed submission:
def run(N):
    p_list = primes(555555)
    # 選択した素数が、5で割って余りが1のもののみ選択すれば、必ず合成数になる
    ret = []
    for p in p_list:
        if p % 5 == 1:
            ret.append(p)
        if len(ret) == N:
            break
    return ' '.join([str(p) for p in ret])


def primes(n):
    '''
    エラトステネスの篩にて、素数のリストを作成
    '''
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]


def main():
    N = int(input())
    print(run(N))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
row = list(map(int, input().strip().split()))
count=0
for i range(0,N,2):
  if row[i]%2==0:
    count+=1
print(count)

Fixed submission:
N = int(input())
row = list(map(int, input().strip().split()))
count=0
for i in range(0,N,2):
  if row[i]%2==1:
    count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [i for i in range(1,n+1)]
l = list(filter(lambda x: x%3 != 0,l))
l = list(filter(lambda x; x%5 != 0,l))
print(sum(l))

Fixed submission:
n = int(input())
l = [i for i in range(1,n+1)]
l = list(filter(lambda x: x%3 != 0,l))
l = list(filter(lambda x: x%5 != 0,l))
print(sum(l))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [-1 for _ in range(n)]
dp[0] = 0
for i in range(1,n):
    for j in range(1,k+1):
        if i - j < 0:
            break
        if dp[i] == -1:
            dp[i] = dp[i-j] + abs(h[i]-h[i-j])
        dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
print(dp[n-1])


Fixed submission:
import numpy as np
n, k = map(int, input().split())
h = list(map(int, input().split()))
h = np.array(h)
dp =np.zeros(n, dtype='int64')
dp[0] = 0
for i in range(1,n):
    lo = max(i-k,0)
    dp[i] = np.min(dp[lo:i]+np.abs(h[i]-h[lo:i]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, w = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(n)]
items = np.array(items)
# dp[n-1][w] solution
# dp[i][w] = max(dp[i-1][w-items[0][0]]+items[0][1], dp[i-1][w])
dp = np.zeros((n,w+1), dtype='int64')
if items[0][0] <= w:
    dp[0, items[0][0]:] = items[0][1]
for i in range(1,n):
    for j in range(0,w+1):
        if j-items[i][0] >= 0:
            dp[i][j] = max(dp[i-1][j-items[i][0]]+items[i][1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
print(dp[n-1][w])


Fixed submission:
import numpy as np
n, W = map(int, input().split())
dp = np.zeros((n,W+1), dtype='int64')
for i in range(n):
    w, v = map(int , input().split())
    dp[i, :w] = dp[i-1, :w]
    dp[i, w:] = np.fmax(dp[i-1, w:], dp[i-1,:W-w+1]+v)
print(dp[n-1][W])
Buggy python submission (verdict: Runtime Error):
print 2

Fixed submission:
day = input()
if day == "SUN":
  print(7)
elif day=="MON":
  print(6)
elif day=="TUE":
  print(5)
elif day=="WED":
  print(4)
elif day=="THU":
  print(3)
elif day=="FRI":
  print(2)
elif day=="SAT":
  print(1)

Buggy python submission (verdict: Runtime Error):
import sys
def nextHoliday(day):
    days={'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
    return days[day.upper()]
  
day = sys.stdin.readline()
output=nextHoliday(day)
print(output)


Fixed submission:
day = input()
if day == "SUN":
  print(7)
elif day=="MON":
  print(6)
elif day=="TUE":
  print(5)
elif day=="WED":
  print(4)
elif day=="THU":
  print(3)
elif day=="FRI":
  print(2)
elif day=="SAT":
  print(1)
Buggy python submission (verdict: Runtime Error):
day = input()
number=int(input())
number = number + 0

alphabet=list("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")

myIter =iter(day)
out=list()
for x in myIter:
  
  pos = alphabet.index(x)
  out.append(alphabet[pos + number])

print(''.join(out))

Fixed submission:
number=int(input())
day = input()

if number ==0:
  print(day)
else:
  alphabet=list("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
  myIter =iter(day)
  out=list()
  for x in myIter:
    pos = alphabet.index(x)
    out.append(alphabet[pos + number])
    
  print(''.join(out))
Buggy python submission (verdict: Runtime Error):
M=int(input())
#Get the number that needs to be handled
num=''
for _ in range(M):
    x=list(map(int, input().split()))
    num+=''.join([str(x[0]) for _ in range(x[1])])
#print(num)
# get the list from the number
res = [int(x) for x in str(num)]
#print(res)

count=1
#now do the loop
while True:
    count+=1
    #print(count, "->",res[0:2], res[2:])
    s1=sum(res[0:2])
    res.pop(1)
    res.pop(0)
    for i in str(s1):
        res.insert(0,int(i))
    #print(sum(res))
    if (len(res)<=2) and sum(res)<9:
        break
#the sum of the residual should be less than 9
print(count)

Fixed submission:
m = int(input())
d = [list(map(int, input().split())) for _ in range(m)]
print(sum([x[1] for x in d]) - 1 + (sum([x[0]*x[1] for x in d]) - 1) // 9)

Buggy python submission (verdict: Runtime Error):
M=int(input())
s=[input() for _ in range(M)]
z=[]
for x in s:
    d=list(map(int, x.split()))
    for i in range(d[1]):
        z.append(d[0])
count = len(N)-1
while True:
    if sum(z)>9: 
        z=map(int, str(sum(z)))
        count += 1
    else:
        break
print(count)

Fixed submission:
m = int(input())
d = [list(map(int, input().split())) for _ in range(m)]
print(sum([x[1] for x in d]) - 1 + (sum([x[0]*x[1] for x in d]) - 1) // 9)
Buggy python submission (verdict: Runtime Error):
n,k=list(map(int, input().split()))
dic={}
for i in range(2*k):
  j=int(input())
  l=list(map(int, input().split()))
  for a in l:
    if a not in dic:
      dic[a]=True
x=len(list(dic.keys()))
print(n-x)
  

Fixed submission:
n,k=list(map(int, input().split()))
dic={}
for i in range(k):
  j=int(input())
  l=list(map(int, input().split()))
  for a in l:
    if a not in dic:
      dic[a]=True
x=len(list(dic.keys()))
print(n-x)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
def gcd(a,b,c):
  return gcd(gcd(a,b),c)
ct=0
k=int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ct+=gcd(i,j,k)
print(ct)


Fixed submission:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
ct=0
k=int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ct+=gcd(gcd(i,j),k)
print(ct)

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
def gcd(a,b,c):
  return gcd(gcd(a,b),c)
ct=0
k=int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ct+=gcd(a,b,c)
print(ct)

Fixed submission:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
ct=0
k=int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ct+=gcd(gcd(i,j),k)
print(ct)
Buggy python submission (verdict: Runtime Error):
if a+b<c:
  if (4*a*b)<(pow(c-a-b,2)):
    print("Yes")
  else:
    print("No")
else:
  print("No")

Fixed submission:
a,b,c=list(map(int, input().split()))
if a+b<c:
  if (4*a*b)<(pow(c-a-b,2)):
    print("Yes")
  else:
    print("No")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c=list(map(str, input().split()))
d,e,f=list(map(str, input().split()))
q,n,z=list(map(str, input().split()))
print(a+e+z)

Fixed submission:
a=input()
b=input()
c=input()
print(a[0]+b[1]+c[2])
Buggy python submission (verdict: Runtime Error):
a = 0
N = int(input())
for i in range(1, 10):
  for j in range(1, 10):
    if N == i*j:
      print('Yes')
      a = 1
  if a == 1:
    break
if a == 0:
  print('No')

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

if 1<=A<=9 and 1<=B<=9:
  	print (A*B)
else:
  	print('-1')
Buggy python submission (verdict: Time Limit Exceeded):
import math

N=int(input())
ARRAY=[[[-1] * (N+1) for i in range(N+1)] for j in range(N+1)]

for i in range(1,N+1):
    count=0
    for x in range(1,int(math.sqrt(i))+1):
        for y in range(1,int(math.sqrt(i-x))+1):
            for z in range(1,int(math.sqrt(i-x-y))+1):

                if ARRAY[x][y][z]==-1:
                    res=x**2+y**2+z**2+x*y+y*z+z*x
                    ARRAY[x][y][z]=res
                    if res==i:
                        count+=1
                else:
                    res=ARRAY[x][y][z]
                    if res==i:
                        count+=1

    print(count)

Fixed submission:
import math

N=int(input())
ARR=[0]*(N+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            res=x**2+y**2+z**2+x*y+y*z+z*x
            if res<=N:
                ARR[res]+=1

for i in ARR[1:]:
    print(i)

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

N=int(input())
ARRAY=[[[-1] * (N+1) for i in range(N+1)] for j in range(N+1)]

for i in range(1,N+1):
    count=0
    for x in range(1,int(math.sqrt(i))+1):
        for y in range(1,int(math.sqrt(i-x))+1):
            for z in range(1,int(math.sqrt(i-x-y))+1):

                if ARRAY[x][y][z]==-1:
                    res=x**2+y**2+z**2+x*y+y*z+z*x
                    ARRAY[x][y][z]=res
                    if res==i:
                        count+=1
                else:
                    res=ARRAY[x][y][z]
                    if res==i:
                        count+=1

    print(count)

Fixed submission:
import math

N=int(input())
ARR=[0]*(N+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            res=x**2+y**2+z**2+x*y+y*z+z*x
            if res<=N:
                ARR[res]+=1

for i in ARR[1:]:
    print(i)

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

N=int(input())


for i in range(1,N+1):
    count=0
    for x in range(1,int(math.sqrt(i))+2):
        for y in range(1,N-x+1):
            for z in range(1,i-x-y+1):
                if x**2+y**2+z**2+x*y+y*z+z*x==i:
                    count+=1
    print(count)

Fixed submission:
import math

N=int(input())
ARR=[0]*(N+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            res=x**2+y**2+z**2+x*y+y*z+z*x
            if res<=N:
                ARR[res]+=1

for i in ARR[1:]:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

n = N
while True:
    if sum(A[:n]) <= K:
        break
    n -= 1

m = M
max_num = 0
for n in range(n + 1):
    #print(n, m)
    if sum(A[:n]) > K:
        break
    while True:
        #print(n, m)
        if sum(A[:n]) + sum(B[:m]) <= K:
            max_num = max(max_num, n+m)
            break
        m -= 1
# print(cost)
print(max_num)


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

ma = [0] * (N + 1)
mb = [0]*(M+1)


for i in range(N):
    ma[i + 1] = ma[i] + A[i]

for i in range(M):
    mb[i + 1] = mb[i] + B[i]

j = M
max_num = 0

for i in range(N+1):
    if ma[i] > K:
        break
    while ma[i] + mb[j] > K:
        j -= 1
    max_num = max(max_num, i + j)
print(max_num)

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

n = N
while True:
    if sum(A[:n]) <= K:
        break
    n -= 1

m = M
cost = []
for n in range(n + 1):
    #print(n, m)
    if sum(A[:n]) > K:
        break
    while True:
        #print(n, m)
        if sum(A[:n]) + sum(B[:m]) <= K:
            cost.append(n + m)
            break
        m -= 1
# print(cost)
print(max(cost))


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

ma = [0] * (N + 1)
mb = [0]*(M+1)


for i in range(N):
    ma[i + 1] = ma[i] + A[i]

for i in range(M):
    mb[i + 1] = mb[i] + B[i]

j = M
max_num = 0

for i in range(N+1):
    if ma[i] > K:
        break
    while ma[i] + mb[j] > K:
        j -= 1
    max_num = max(max_num, i + j)
print(max_num)

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

m = M
cost = []
for n in range(N + 1):
    #print(n, m)
    if sum(A[:n]) > K:
        break
    while True:
        #print(n, m)
        if sum(A[:n]) + sum(B[:m]) <= K:
            cost.append(n + m)
            break
        m -= 1
# print(cost)
print(max(cost))


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

ma = [0] * (N + 1)
mb = [0]*(M+1)


for i in range(N):
    ma[i + 1] = ma[i] + A[i]

for i in range(M):
    mb[i + 1] = mb[i] + B[i]

j = M
max_num = 0

for i in range(N+1):
    if ma[i] > K:
        break
    while ma[i] + mb[j] > K:
        j -= 1
    max_num = max(max_num, i + j)
print(max_num)
Buggy python submission (verdict: Time Limit Exceeded):
# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


array = [0]*(10**5+1)

for a in A:
    array[a] += 1

for bc in BC:
    b, c = bc
    array[c] += array[b]
    array[b] = 0

    total = 0
    for i in range(10 ** 5 + 1):
        total += i * array[i]
    print(total)


Fixed submission:
# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


array = [0]*(10**5+1)
total = sum(A)

for a in A:
    array[a] += 1

for bc in BC:
    b, c = bc
    total += c*array[b]-b*array[b]
    array[c] += array[b]
    array[b] = 0
    print(total)

Buggy python submission (verdict: Time Limit Exceeded):
# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


array = [0]*(10**5+1)

for a in A:
    array[a] += 1

for bc in BC:
    b, c = bc
    array[c] += array[b]
    array[b] = 0

    total = 0
    for i in range(10 ** 5 + 1):
        total += i * array[i]
    print(total)


Fixed submission:
# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


array = [0]*(10**5+1)
total = sum(A)

for a in A:
    array[a] += 1

for bc in BC:
    b, c = bc
    total += c*array[b]-b*array[b]
    array[c] += array[b]
    array[b] = 0
    print(total)

Buggy python submission (verdict: Time Limit Exceeded):
# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


def replacement(orig, b, c):
    if orig == b:
        return c
    else:
        return orig


for bc in BC:
    b, c = bc
    A = [replacement(a, b, c) for a in A]
    print(sum(A))


Fixed submission:
# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


array = [0]*(10**5+1)
total = sum(A)

for a in A:
    array[a] += 1

for bc in BC:
    b, c = bc
    total += c*array[b]-b*array[b]
    array[c] += array[b]
    array[b] = 0
    print(total)