Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N,K = map(int,input().split())
c = [int(input()) for i in range(N)]
c.sort()
output = c[K-1] - c[0]
for i in range(N-K):
    output = c[K+i] - c[i+1] if output > c[K+i] - c[i+1]
print(output)


Fixed submission:
# -*- coding: utf-8 -*-
N,K = map(int,input().split())
c = [int(input()) for i in range(N)]
c.sort()
output = c[K-1] - c[0]
for i in range(N-K):
    if output > c[K+i] - c[i+1]:output = c[K+i] - c[i+1]
print(output)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a = int(input().split()[1])
c = [int(input().split()[0]) for i in range(a)]
import collections
c = collections.Counter(c)
for k,v in sorted(c.items()):
    for i in range(v):
        j = i+1
        print(f'{k:08}{j:08}')


Fixed submission:
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
d = [[i,tuple(map(int,input().split()))] for i,_ in enumerate(range(m))]
#print(d)

d.sort(key=lambda x:x[1][1])
p_cnt = [0] * (n+1)
ret_tuples = [0] * m #(市id,認識番号) のtupleのリスト

for i,v in enumerate(d):
    p = v[1][0]
    x = p_cnt[p]+1
    p_cnt[p]+=1
    ret_tuples[i] = (v[0],"{:0=6}{:0=6}".format(p,x))

ret_tuples.sort(key=lambda x:x[0])
for i in ret_tuples:
    print(i[1])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
s = input()
len_s = len(s)
k = int(input())
substring_list = []
sappend = substring_list.append
for i in range(len_s):
    for j in range(i,len_s):
        sappend(s[i:j+1])
substring_set = set(substring_list)
print(sorted(substring_set)[k-1])

Fixed submission:
# -*- coding: utf-8 -*-
s = input()
len_s = len(s)
k = int(input())
substring_list = []
sappend = substring_list.append
for i in range(len_s):
    for j in range(5):
        sappend(s[i:min(i+1+j,len_s)])
substring_set = set(substring_list)
print(sorted(substring_set)[k-1])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int,input().split()))
rate_bucket = [0] * 9
ret = 0
for a in an:
    rate_bucket[a//400]+=1
for i in rate_bucket[0:-1:]:
    if i > 0:
        ret+=1
print("{} {}".format(ret,ret+rate_bucket[-1]))


Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int,input().split()))
rate_bucket = [0] * 9
ret = 0
for a in an:
    rate_bucket[min(a//400,8)]+=1
for i in rate_bucket[0:-1:]:
    if i > 0:
        ret+=1
print("{} {}".format(max(ret,1),ret+rate_bucket[-1]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
#k(2~n)について、2~kの素数までで割り切れる回数をカウント

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        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]]

prime_list = primes(n)
prime_cnt = dict([(k,0) for k in prime_list])
from decimal import Decimal

for k in range(2,n+1):
    k = Decimal(k)
    for j in prime_list:
        j=Decimal(j)
        while k%j==0:
            prime_cnt[j]+=1
            k = k/j
        if k==1:
            break

import functools
import operator

print(functools.reduce(operator.mul, [v+1 for v in prime_cnt.values()])%(10**9+7))


Fixed submission:
n = int(input())
#k(2~n)について、2~kの素数までで割り切れる回数をカウント

if n==1:
    print(1)
    import sys
    sys.exit()

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        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]]

prime_list = primes(n)
prime_cnt = dict([(k,0) for k in prime_list])
from decimal import Decimal

for k in range(2,n+1):
    k = Decimal(k)
    for j in prime_list:
        j=Decimal(j)
        while k%j==0:
            prime_cnt[j]+=1
            k = k/j
        if k==1:
            break

import functools
import operator


print(functools.reduce(operator.mul, [v+1 for v in prime_cnt.values()])%(10**9+7))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
ta = [list(map(int,input().split())) for i in range(n)]

cur_t = 1
cur_a = 1


def ceil(a, b):
    return a // b + int(a % b != 0)

for t,a in ta:
    if cur_t > t or cur_a > a:
        rate = ceil(max([cur_t/t,cur_a/a]))
        cur_t = t*rate
        cur_a = a*rate
    else:
        cur_t=t
        cur_a=a
print(cur_t+cur_a)


Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
ta = [list(map(int,input().split())) for i in range(n)]

cur_t = 1
cur_a = 1


def ceil(a, b):
    return a // b + int(a % b != 0)

for t,a in ta:
    if cur_t > t or cur_a > a:
        rate = max([ceil(cur_t,t),ceil(cur_a,a)])
        cur_t = t*rate
        cur_a = a*rate
    else:
        cur_t=t
        cur_a=a
print(cur_t+cur_a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1

for a in A:
    ans *= a

if ans > 10 ** 18:
    ans = -1
print(ans)


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

ans = 1

if 0 in A:
    print(0)
    exit()

for a in A:
    ans *= a
    if ans > 10 ** 18:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

D = 10000

X = int(input())

L2 = [i for i in range(-D, D)]
L = [i**5 for i in L2]

idx = bisect.bisect_left(L, X)-1

B = L[:idx]
A = L[idx:]

for a in A:
    for b in B:
        if a - b == X:
            break
    else:
        continue
    break

print(L2[L.index(a)], L2[L.index(b)])


Fixed submission:
import bisect
import math

D = 120

X = int(input())

for a in range(-D, D):
    for b in range(-D-1, D-1):
        if a**5 - b**5 == X:
            break
    else:
        continue
    break

print(a, b)

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

D = 10 ** 4

X = int(input())

L = [i**5 for i in range(-D, D)]
L2 = [i for i in range(-D, D)]

idx = bisect.bisect_left(L, X)-1

B = L[:idx]
A = L[idx:]

for a in A:
    for b in B:
        if a - b == X:
            break
    else:
        continue
    break

print(L2[L.index(a)], L2[L.index(b)])


Fixed submission:
import bisect
import math

D = 120

X = int(input())

for a in range(-D, D):
    for b in range(-D-1, D-1):
        if a**5 - b**5 == X:
            break
    else:
        continue
    break

print(a, b)

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

D = 10 ** 5

X = int(input())

L = [i**5 for i in range(-D, D)]
L2 = [i for i in range(-D, D)]

idx = bisect.bisect_left(L, X)-1

B = L[:idx]
A = L[idx:]

for a in A:
    for b in B:
        if a - b == X:
            break
    else:
        continue
    break

print(L2[L.index(a)], L2[L.index(b)])


Fixed submission:
import bisect
import math

D = 120

X = int(input())

for a in range(-D, D):
    for b in range(-D-1, D-1):
        if a**5 - b**5 == X:
            break
    else:
        continue
    break

print(a, b)

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

D = 10 ** 6

X = int(input())

L = [i**5 for i in range(-D, D)]
L2 = [i for i in range(-D, D)]

idx = bisect.bisect_left(L, X)-1

B = L[:idx]
A = L[idx:]

for a in A:
    for b in B:
        if a - b == X:
            break
    else:
        continue
    break

print(L2[L.index(a)], L2[L.index(b)])


Fixed submission:
import bisect
import math

D = 120

X = int(input())

for a in range(-D, D):
    for b in range(-D-1, D-1):
        if a**5 - b**5 == X:
            break
    else:
        continue
    break

print(a, b)
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

red = P[:X]
green = Q[:Y]
ans = sum(red) + sum(green)

ridx = 0
redidx = -1
greenidx = -1

for i in range(X+Y):
    if (red[redidx] < green[greenidx] and abs(redidx) <= len(red)) or abs(greenidx) > len(green):
        if red[redidx] < R[ridx]:
            ans -= red[redidx]
            ans += R[ridx]
            ridx += 1
            redidx -= 1
    elif (red[redidx] > green[greenidx] and abs(greenidx) <= len(green)) or abs(redidx) > len(red):
        if green[greenidx] < R[ridx]:
            ans -= green[greenidx]
            ans += R[ridx]
            ridx += 1
            greenidx -= 1

    if ridx == len(R):
        break

print(ans)


Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

red = P[:X]
green = Q[:Y]
ans = sum(red + green)
rg = sorted(red + green)

for i in range(min(C, X+Y)):
    if rg[i] < R[i]:
        ans += R[i] - rg[i]

print(ans)

Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

red = P[:X]
green = Q[:Y]
ans = sum(red) + sum(green)

ridx = 0
redidx = -1
greenidx = -1

for i in range(X+Y):
    if red[redidx] < green[greenidx] and abs(redidx) <= len(red):
        if red[redidx] < R[ridx]:
            ans -= red[redidx]
            ans += R[ridx]
            ridx += 1
            redidx -= 1
    elif red[redidx] > green[greenidx] and abs(greenidx) <= len(green):
        if green[greenidx] < R[ridx]:
            ans -= green[greenidx]
            ans += R[ridx]
            ridx += 1
            greenidx -= 1

    if ridx == len(R):
        break

print(ans)


Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

red = P[:X]
green = Q[:Y]
ans = sum(red + green)
rg = sorted(red + green)

for i in range(min(C, X+Y)):
    if rg[i] < R[i]:
        ans += R[i] - rg[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
S = [str(input()) for _ in range(N)]

c = collections.Counter(S)

ans = [i[0] for i in c.items() if i[1] >= c.most_common(1)[0][1]]
ans.sort()

for a in ans:
    print(a)


Fixed submission:
N = int(input())
S = [str(input()) for _ in range(N)]

S.sort()

ans = []
most = 0
tmpstr = S[0]
tmpcnt = 0


for s in S:
    if tmpstr == s:
        tmpcnt += 1
    else:
        if tmpcnt > most:
            ans.clear()
            ans.append(tmpstr)
            most = tmpcnt

        elif tmpcnt == most:
            ans.append(tmpstr)

        tmpcnt = 1
        tmpstr = s

if tmpcnt > most:
    ans.clear()
    ans.append(tmpstr)
    most = tmpcnt
elif tmpcnt == most:
    ans.append(tmpstr)

for a in ans:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
input = sys.stdin.readline


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

if K >= N:
    print('0')
else:
    for i in range(K):
        H[np.argmax(H)] = 0
    print(sum(H))


Fixed submission:
import sys
input = sys.stdin.readline

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H.sort(reverse=True)

if K >= N:
    print('0')
else:
    del(H[0:K])
    print(sum(H))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

ans = 0

for i in range(0, len(P)-1):
    if (P[1] <= P[0]):
        ans += 1
        del(P[0])
    else:
        del(P[1])

print(ans+1)


Fixed submission:
import sys
input = sys.stdin.readline

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

ans = 0
pivot = P[0]

for i in range(0, len(P)):
    if (pivot >= P[i]):
        ans += 1
        pivot = P[i]

print(ans)

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

ans = 0

for i in range(0, len(P)-1):
    if (P[1] <= P[0]):
        ans += 1
        del(P[0])
    else:
        del(P[1])

print(ans+1)


Fixed submission:
import sys
input = sys.stdin.readline

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

ans = 0
pivot = P[0]

for i in range(0, len(P)):
    if (pivot >= P[i]):
        ans += 1
        pivot = P[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import operator as op

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

L = [0] * N

for a in A:
    L[a-1] = A.index(a) + 1

print(*L)


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

L = [0] * N

for i, a in enumerate(A):
    L[a-1] = i + 1

print(*L)

Buggy python submission (verdict: Time Limit Exceeded):
import operator as op

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

L = []

for a in A:
    L.append([A.index(a) + 1, a])

L.sort(key=op.itemgetter(1))

ans = str()
for l in L:
    ans += str(l[0])
    if l[1] != N:
        ans += " "
print(ans)


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

L = [0] * N

for i, a in enumerate(A):
    L[a-1] = i + 1

print(*L)
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

ans = [i for i in range(1, A+1) if A % i == 0 and B % i == 0]
print(ans[K])


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

ans = [i for i in range(1, min(A, B) + 1) if A % i == 0 and B % i == 0]
print(ans[-K])

Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

ans = [i for i in range(1, A+1) if A % i == 0 and B % i == 0]
print(ans[1])


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

ans = [i for i in range(1, min(A, B) + 1) if A % i == 0 and B % i == 0]
print(ans[-K])
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
a_values = collections.Counter(a)

while len(a_values) > k:
    a_most = a_values.most_common()[0]
    a_least = a_values.most_common()[-1]

    a.remove(a_least[0])
    a.append(a_most[0])
    a_values = collections.Counter(a)
    ans += 1
else:
    print(ans)


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

a_values = collections.Counter(a)

o = len(a_values) - k
values, counts = zip(*a_values.most_common()[::-1])

if o <= 0:
    print(0)
else:
    print(sum(counts[:o]))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

for a in A:
    for i in range(bisect.bisect_right(B, a), len(B)):
        cPtn = len(C) - bisect.bisect_right(C, B[i])
        ans += cPtn

print(ans)


Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

for b in B:
    aPtn = bisect.bisect_left(A, b)
    cPtn = len(C) - bisect.bisect_right(C, b)
    ans += aPtn * cPtn

print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    suu="abcdefghijklmnopqrstuvwxyz"#26
    n=int(input())
    puts=""
    if n<27:#その数より小さい
        print(suu[n-1])
        return
    while True:
        temp=n%26
        puts=suu[temp-1]+puts
        n/=26
        if temp==0:#補正
            n-=1
        if n<27:
            puts=suu[n-1]+puts
            break
    print(puts)
if __name__ == "__main__":
    main()


Fixed submission:
def main():
    suu="abcdefghijklmnopqrstuvwxyz"#26
    n=int(input())
    puts=""
    if n<27:#その数より小さい
        print(suu[n-1])
        return
    while True:
        temp=n%26
        n//=26
        puts=suu[temp-1]+puts
        if temp==0:#補正
            n-=1
        if n<27:
            puts=suu[n-1]+puts
            break
    print(puts)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
s=input();c=0
for i in range(len(s)):
    for j in range(1,len(s)+1):
        if s[i:j]:
            if int(s[i:j])%2019==0:
                c+=1
print(c)

Fixed submission:
s,w=map(int,input().split())
print(("un"if w>=s else "")+"safe")
Buggy python submission (verdict: Runtime Error):
n=int(input())
c=0
for i in range(1,n+1):
    if str(i)%2==1:
        c+=1
print(c)

Fixed submission:
n=int(input())
c=0
for i in range(1,n+1):
    if len(str(i))%2==1:
        c+=1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
def F(a,b):
    a=len(str(a))
    b=len(str(b))-2#float型のため
    return a if a>b else b
n=int(input())
o=[]
k=100000000
c=0
m=10000000000
for i in range(1,n):
    if c>0:
        c-=1
        continue
    s=n/i
    if s.is_integer():
        k=F(i,s)
        o.append(k)
        if k>m:
            break
        m=k
        i=int("1"+"0"*len(str(i)))-i#iを次の位にする
try:
    print(min(o))
except:
    print(1)

Fixed submission:
from math import sqrt
def F(A,B):
    A=len(str(A))
    B=len(str(B))-2
    return A if A>B else B
n=int(input())
o=[]
for a in range(1,int(sqrt(n))+1):
    b=n/a
    if b.is_integer():
        o.append(F(a,b))
print(o[-1])

Buggy python submission (verdict: Runtime Error):
def F(a,b):
    a=len(str(a))
    b=len(str(b))-2#float型のため
    return a if a>b else b
n=int(input())
o=[]
k=100000000
c=0
m=10000000000
for i in range(1,n):
    if c>0:
        c-=1
        continue
    if i>=n:
        break
    s=n/i
    if s.is_integer():
        k=F(i,s)
        o.append(k)
        if k>m:
            break
        m=k
        i=int("1"+"0"*len(str(i)))-i#iを次の位にする
print(min(o))

Fixed submission:
from math import sqrt
def F(A,B):
    A=len(str(A))
    B=len(str(B))-2
    return A if A>B else B
n=int(input())
o=[]
for a in range(1,int(sqrt(n))+1):
    b=n/a
    if b.is_integer():
        o.append(F(a,b))
print(o[-1])
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    s = 0
    while n != 0:
        s += n%10
        n =int(n/10)
    if s%9==0:
        print('Yes')
    else:
        print('No')
        
if __name__=='__main__':
    main()


Fixed submission:
def main():
    n = input()

    s = 0

    while n:
        s += int(n[-1])
        n = n[:-1]
    
    if s%9==0:
        print('Yes')
    else:
        print('No')
        
if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    data = input().split()
    res = 1
    for i in range(n):
        res *= int(data[i])
        if res == 0:
            print(0)
            return
    if res > 10**18:
        print(-1)
        return
    print(res)
    return

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    data = input().split()
    
    for i in range(n):
        data[i] = int(data[i])
        if data[i] == 0:
            print(0)
            return
        
    res = 1
    for i in range(n):
        res *= data[i]
        if res > 10**18:
            print(-1)
            return
    print(res)
    return

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
score=1
s=[]


for i in range(k,n+1):
    for j in range(k):
        score*=a[i-k+j]
    s.append(score)
    score=1
#print(s)

for i in range(n-k):
    if (s[i+1]-s[i])>0:
        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]>a[i-k]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

ans=1000
kabu=0
flag=0

for i in range(n-1):
    if a[i]<a[i+1]:
        if flag <=0:
            kabu=int(ans/a[i])
            ans-=(kabu*a[i])
            #print(a[i],ans,kabu)
        flag=1
    elif a[i]>a[i+1]:
        if flag >0:
            ans+=(kabu*a[i])
            #print(ans)
        flag=-1
    else:
        if flag>0:
            flag=2
        else:
            flag=-2
    if i==(n-2) and flag>0:
        ans+=(kabu*a[i+1])
        #print(a[i+1],ans)

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

ans=1000
kabu=0
flag=0

for i in range(n-1):
    if a[i]<a[i+1]:
        if flag <=0:
            kabu=int(ans/a[i])
            ans-=(kabu*a[i])
            #print(a[i],ans,kabu)
        flag=1
    elif a[i]>a[i+1]:
        if flag >0:
            ans+=(kabu*a[i])
            #print(ans)
        flag=-1
    else:
        if flag>0:
            flag=2
        else:
            flag=-2
    if i==(n-2) and flag>0:
        ans+=(kabu*a[i+1])
        #print(a[i+1],ans)

print(ans)

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

ans=1000
kabu=0
flag=0

for i in range(n-1):
    if a[i]<a[i+1]:
        if flag <=0:
            kabu=int(ans/a[i])
            ans-=(kabu*a[i])
            #print(a[i],ans,kabu)
        flag=1
    elif a[i]>a[i+1]:
        if flag >0:
            ans+=(kabu*a[i])
            #print(ans)
        flag=-1
    else:
        if flag>0:
            flag=2
        else:
            flag=-2
    if i==(n-2) and flag>0:
        ans+=(kabu*a[i+1])
        #print(a[i+1],ans)

print(ans)
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()))
aa=[0]
bb=[0]
a_sum=0
b_sum=0

for i in range(n):
    if (a_sum+a[i])<=k:
        a_sum+=a[i]
        aa.append(a_sum)
    else:
        break
for i in range(m):
    if (b_sum+b[i])<=k:
        b_sum+=b[i]
        bb.append(b_sum)
    else:
        break

#print(aa)
#print(bb)
cnt=0
for i in range(len(aa)):
    for j in range(len(bb)):
        if (aa[i]+bb[j])<=k:
            cnt=max(cnt,i+j)
print(cnt)


Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]
bb=[0]
a_sum=0
b_sum=0

for i in range(n):
    if (a_sum+a[i])<=k:
        a_sum+=a[i]
        aa.append(a_sum)
    else:
        break
for i in range(m):
    if (b_sum+b[i])<=k:
        b_sum+=b[i]
        bb.append(b_sum)
    else:
        break

#print(aa)
#print(bb)
cnt=len(bb)-1
ans=0
for i in range(len(aa)):
    for j in range(cnt,-1,-1):
        if bb[j]<=(k-aa[i]):
            cnt=j
            ans=max(ans,(i+j))
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
ans=sum(a)
cnt=0
for i in range(q):
    b,c=map(int,input().split())
    cnt=a.count(b)
    ans+=cnt*(c-b)
    for j in range(cnt):
        a.remove(b)
        a.append(c)
    print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
d=[0]*(10**5+1)
for i in range(n):
    d[a[i]]+=1
ans=sum(a)
cnt=0
for i in range(q):
    b,c=map(int,input().split())
    ans+=(d[b]*(c-b))
    d[c]+=d[b]
    d[b]=0
    print(ans)