Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
cnt = 0
total = 0
while cnt != len(a):
    cnt = 0
    for i in range(len(a)):
        if a[i] % 2 == 0:
            a[i] //= 2
            total += 1
            break
        else:
            cnt += 1
print(total)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
total = 0
for i in range(len(a)):
    while a[i] % 2 == 0:
        total += 1
        a[i] //= 2
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S = input()

min_num = N+1

for v in range(N):
    min_num = min(S[0:v].count('W')+S[v:N].count('E'),min_num)
print(min_num)

Fixed submission:
N = int(input())

S = input()

min_num = N+1

W = []
E = []

w_cnt = 0
e_cnt = 0

for i in range(N):
    if S[i] == 'W':
        w_cnt += 1
    W.append(w_cnt)

for i in range(N-1,0,-1):
    min_num = min(min_num,W[i-1]+e_cnt)
    if S[i] == 'E':
        e_cnt += 1

print(min(min_num,e_cnt))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

x = list(map(int,input().split()))
sort_x = x.copy()
sort_x.sort()

cnt = 0
center_num = (N-1) // 2

for l in x:
    if sort_x.index(l) <= center_num:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])

Fixed submission:
import copy

N = int(input())

x = list(map(int,input().split()))
sort_x = copy.copy(x)
sort_x.sort()

center_num = (N-1) // 2

for l in x:
    if l <= sort_x[center_num]:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])

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

N = int(input())

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

num_count = collections.Counter(x)

key_list = list(set(x))
key_list.sort()

cnt = 0
flg = True
n = 0
center_num = N // 2

for i in x:
    j = 0
    while cnt < center_num:
        n = key_list[j]
        if flg and i == n:
            cnt += num_count[n]-1
            flg = False
        else:
            cnt += num_count[n]
        j += 1
    print(n)
    cnt = 0
    flg = True

Fixed submission:
import copy

N = int(input())

x = list(map(int,input().split()))
sort_x = copy.copy(x)
sort_x.sort()

center_num = (N-1) // 2

for l in x:
    if l <= sort_x[center_num]:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

c = N // 2 - 1

for i in range(N):
  xp = x.copy()
  st = xp.pop(i)
  xp.sort()
  print(xp[c])

Fixed submission:
import copy

N = int(input())

x = list(map(int,input().split()))
sort_x = copy.copy(x)
sort_x.sort()

center_num = (N-1) // 2

for l in x:
    if l <= sort_x[center_num]:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
st_n = a[0]
st_r = a[1]
m = math.factorial(st_r)*math.factorial(st_n-st_r)
for r in range(1,N):
    cn = math.factorial(a[r])*math.factorial(st_n-a[r])
    if cn < m:
        st_r = a[r]
        m = cn
print(st_n,st_r)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
st_n = a[0]
st_r = a[1]
m = st_r*(st_n-st_r)
for r in range(2,N):
    cn = a[r]*(st_n-a[r])
    if m < cn:
        st_r = a[r]
        m = cn
print(st_n,st_r)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
m = 0
st_n = a[0]
st_r = a[1]
for n in range(N-1):
    for r in range(n+1,N):
        if a[r] != 0:
            cn = math.factorial(a[n])//(math.factorial(a[r])*math.factorial(a[n]-a[r]))
            if m < cn:
                st_n = a[n]
                st_r = a[r]
                m = cn

print(st_n,st_r)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
st_n = a[0]
st_r = a[1]
m = st_r*(st_n-st_r)
for r in range(2,N):
    cn = a[r]*(st_n-a[r])
    if m < cn:
        st_r = a[r]
        m = cn
print(st_n,st_r)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())
a_st=a
b_st=b
num=[]
cnt=0
for i in range(a,b+1):
    if cnt<k:
        num.append(i)
        cnt+=1
cnt=0
for i in range(b,a,-1):
    if cnt<k:
        num.append(i)
        cnt+=1
num2=list(set(num))
num2.sort()
[print(x) for x in num2]

Fixed submission:
a,b,k=map(int,input().split())
a_st=a
b_st=b
num=[]
cnt=0
for i in range(a,b+1):
    if cnt<k:
        num.append(i)
        cnt+=1
    else:
        break
cnt=0
for i in range(b,a,-1):
    if cnt<k:
        num.append(i)
        cnt+=1
    else:
        break
num2=list(set(num))
num2.sort()
[print(x) for x in num2]
Buggy python submission (verdict: Time Limit Exceeded):
x,y = map(int,input().split())

n = 1000000000000000001

for i in range(n):
    if i % x == 0 and i % y != 0:
        print(i)
        exit()
print(-1)

Fixed submission:
x,y = map(int,input().split())

if x % y == 0:
    print(-1)
else:
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int,input().split())

if Y % 1000 != 0:
    print(-1,-1,-1)

n1 = Y // 10000
n2 = Y // 5000
n3 = Y // 1000
if abs(N-n1) < abs(N-n3):
    for i in range(N,-1,-1):
        for j in range(n2+1):
            for k in range(n1+1):
                if i*10000 + j*5000 + k*1000 == Y and i+j+k == N:
                    print(i,j,k)
                    exit()
                if Y < i*10000 + j*5000 + k*1000: break
else:
    for i in range(N,-1,-1):
        for j in range(n2+1):
            for k in range(n3+1):
                if k*10000 + j*5000 + i*1000 == Y and i+j+k == N:
                    print(k,j,i)
                    exit()
                if Y < k*10000 + j*5000 + i*1000: break
print(-1,-1,-1)

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

if Y % 1000 != 0:
    print(-1,-1,-1)

n1 = Y // 10000
n2 = Y // 5000

for i in range(n1+1):
    for j in range(n2+1):
        if (N-i-j) < 0: continue
        if i*10000 + j*5000 + (N-i-j)*1000 == Y:
            print(i,j,(N-i-j))
            exit()
        if Y < i*10000 + j*5000 + (N-i-j)*1000: break
print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
s = input()
print(s-"FESTIVAL")

Fixed submission:
s = input()
print(s[:len(s)-8])
Buggy python submission (verdict: Runtime Error):
# 計算量O(N2M)

N = int(input())

d = list(map(int,input().split()))
d_cnt = [0]*max(d)

for v in d:
    d_cnt[v-1] += 1

M = int(input())

t = list(map(int,input().split()))
t_cnt = [0]*max(t)

for v in t:
    t_cnt[v-1] += 1

if N < M:
    print('NO')
    exit()

for i in range(min(len(d_cnt),len(t_cnt))):
    if t_cnt[i] != 0:
        if d_cnt[i] < t_cnt[i]:
            print('NO')
            exit()

print('YES')


Fixed submission:
# 計算量O(N2M)
import collections
N = int(input())

d = collections.Counter(list(map(int,input().split())))

M = int(input())
t = list(map(int,input().split()))
t_num = t.copy()
t_num = set(list(t_num))
t = collections.Counter(t)

if N < M:
    print('NO')
    exit()

for key in t_num:
    if d[key] < t[key]:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Runtime Error):
# 計算量O(N2M)

N = int(input())

d = list(map(int,input().split()))
d_cnt = [0]*max(d)

for v in d:
    d_cnt[v-1] += 1

M = int(input())

t = list(map(int,input().split()))
t_cnt = [0]*max(t)

for v in t:
    t_cnt[v-1] += 1

if N < M:
    print('NO')
    exit()


for i in range(len(t_cnt)):
    if t_cnt[i] != 0:
        if d_cnt[i] < t_cnt[i]:
            print('NO')
            exit()

print('YES')


Fixed submission:
# 計算量O(N2M)
import collections
N = int(input())

d = collections.Counter(list(map(int,input().split())))

M = int(input())
t = list(map(int,input().split()))
t_num = t.copy()
t_num = set(list(t_num))
t = collections.Counter(t)

if N < M:
    print('NO')
    exit()

for key in t_num:
    if d[key] < t[key]:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Runtime Error):
# 計算量O(N2M)

N = int(input())

d = list(map(int,input().split()))
d_cnt = [0]*max(d)

for v in d:
    d_cnt[v-1] += 1

M = int(input())

t = list(map(int,input().split()))
t_cnt = [0]*max(t)

for v in t:
    t_cnt[v-1] += 1

if N < M:
    print('NO')
    exit()

for dn,tn in zip(d_cnt,t_cnt):
    if tn != 0:
        if dn < tn:
            print('NO')
            exit()

print('YES')


Fixed submission:
# 計算量O(N2M)
import collections
N = int(input())

d = collections.Counter(list(map(int,input().split())))

M = int(input())
t = list(map(int,input().split()))
t_num = t.copy()
t_num = set(list(t_num))
t = collections.Counter(t)

if N < M:
    print('NO')
    exit()

for key in t_num:
    if d[key] < t[key]:
        print('NO')
        exit()
print('YES')
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(max(a)+1):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)


Fixed submission:
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
max_num = 0

for x in range(max(a)+1):
      max_num = max(max_num,(c[x] + c[x+1] + c[x+2]))
print(max_num)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(1,max(a)+1):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)


Fixed submission:
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
max_num = 0

for x in range(max(a)+1):
      max_num = max(max_num,(c[x] + c[x+1] + c[x+2]))
print(max_num)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
res = 0
for i in range(2,n:
    if a[i-1] == i:
        res += 1
print(res)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
res = 0
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        i+=2
    else:
        i+=1
print(res)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
res = 0
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        while a[i-1] == i:
            res+=1
            i+=1
            if i < n+1:
                break
        res -= 1
    i+=1
print(res)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
res = 0
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        i+=2
    else:
        i+=1
print(res)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
res = 0
flg = True
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        while a[i-1] == i:
            res+=1
            i+=1
        res -= 1
    i+=1
print(res)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
res = 0
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        i+=2
    else:
        i+=1
print(res)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())

N = int(input())

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

s = []

res = []

for v,i in enumerate(a,1):
    for _ in range(v):
        s.append(str(i))

for i in range(H):
    for j in range(W):
        res.append(str(s.pop(0)))
    if i % 2 == 1:
        res.reverse()
    print(' '.join(res))
    res = []

Fixed submission:
H,W = map(int,input().split())

N = int(input())

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

res = []
j = 0
st = 0 # リスト添え字管理

for i in range(H):
    j = 0
    while j < W:
        while 0 < a[st] and j < W:
            res.append(str(st+1))
            j += 1
            a[st] -= 1
        if a[st] == 0:
            st += 1
    if i % 2 == 1:
        res.reverse()
    print(' '.join(res))
    res = []
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().split()

b = []
if n % 2:
    flg = False
else:
    flg = True
for v in a:
    if flg:
        b.append(v)
        flg = False
    else:
        b.insert(0,v)
        flg = True

print(' '.join(b))

Fixed submission:
n = int(input())
a = input().split()
reb_a = a[::-1]
if n % 2 == 0:
    res = reb_a[::2]+a[::2]
else:
    res = reb_a[::2]+a[1::2]

print(' '.join(res))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print('Yes' if A<=C<=B else 'No')

Fixed submission:
a,b,c=map(int,input().split())
print('Yes' if a<=c<=b else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = 1
for i in range(1,N+1):
    p *= i
print(p % ((10**9)+7))


Fixed submission:
N = int(input())
p = 1
for i in range(1,N+1):
    p = i * (p % ((10**9)+7))
print(p % ((10**9)+7))
Buggy python submission (verdict: Runtime Error):
s,c = map(int,input().split())

if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

#print(res,s,c)

if c:
    res += c//4
print(res)

Fixed submission:
s,c = map(int,input().split())
res = 0
if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

if c:
    res += c//4
print(res)

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

if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    m = 0

#print(res,s,c)

if c:
    res += c//4
print(res)

Fixed submission:
s,c = map(int,input().split())
res = 0
if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

if c:
    res += c//4
print(res)

Buggy python submission (verdict: Runtime Error):
s,c = map(int,input().split())
res = 0

if s*2 <= c:
    res += s
    c -= s*2
    res+= c
else:
    res += c//2
    c //= 2
if c:
    res += m//4
print(res)

Fixed submission:
s,c = map(int,input().split())
res = 0
if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

if c:
    res += c//4
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

a_list = []

b_list = []

for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

a_list = a_list[::-1]
b_list = b_list[::-1]

#print(a_list)
#print(b_list)

st = 0

for i in range(N):
    a_list[i] += st
    if a_list[i] % b_list[i]:
        if a_list[i] < b_list[i]:
            st += b_list[i]-a_list[i]
        elif a_list[i] > b_list[i]:
            n = b_list[i]
            j = 2
            while a_list[i] > n:
                n = b_list[i]*j
                j += 1
            st += n-a_list[i]
print(st)

Fixed submission:
N = int(input())

a_list = []

b_list = []

for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

a_list = a_list[::-1]
b_list = b_list[::-1]

#print(a_list)
#print(b_list)

st = 0

for i in range(N):
    a_list[i] += st
    if a_list[i] % b_list[i]:
        if a_list[i] < b_list[i]:
            st += b_list[i]-a_list[i]
        elif a_list[i] > b_list[i]:
            st += b_list[i]*((a_list[i]//b_list[i])+1)-a_list[i]
print(st)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                cnt += 1
            elif s < x+y+z:
                break
print(cnt)

Fixed submission:
k,s = map(int,input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= (s-x-y) <= k:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                cnt += 1
print(cnt)

Fixed submission:
k,s = map(int,input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= (s-x-y) <= k:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()

n = 0
e = 0
w = 0
s = 0

for v in s:
    if v == 'N': n+=1
    if v == 'E': e+=1
    if v == 'W': w+=1
    if v == 'S': s+=1

if n == s and e == w:
    print('Yes')
else:
    print('No')

Fixed submission:
S = input()

n = 0
e = 0
w = 0
s = 0

for v in S:
    if v == 'N': n+=1
    if v == 'E': e+=1
    if v == 'W': w+=1
    if v == 'S': s+=1
if ((0<n and 0<s) or (n==0 and s==0)) and ((0<e and 0<w) or (e==0 and w==0)):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):

n=int(input())

alist=[0 for i in range(n+1)]

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

for i in A:
    alist[i]+=1
asum=sum(A)
for i in range(q):
    b,c=map(int , input().split())
    bnum=alist[b]
    asum+=bnum*(c-b)
    alist[b]=0
    alist[c]+=bnum
    print(asum)


Fixed submission:

n=int(input())

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

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

for i in A:
    alist[i]+=1
asum=sum(A)
for i in range(q):
    b,c=map(int , input().split())
    bnum=alist[b]
    asum+=bnum*(c-b)
    alist[b]=0
    alist[c]+=bnum
    print(asum)

Buggy python submission (verdict: Runtime Error):

n=int(input())

alist=[0 for i in range(n+1)]

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

for i in A:
    alist[i]+=1
asum=sum(A)
for i in range(q):
    b,c=map(int , input().split())
    bnum=alist[b]
    asum+=bnum*(c-b)
    alist[b]=0
    alist[c]+=bnum
    print(asum)


Fixed submission:

n=int(input())

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

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

for i in A:
    alist[i]+=1
asum=sum(A)
for i in range(q):
    b,c=map(int , input().split())
    bnum=alist[b]
    asum+=bnum*(c-b)
    alist[b]=0
    alist[c]+=bnum
    print(asum)
Buggy python submission (verdict: Time Limit Exceeded):
import math

a=input()
a=int(a)
sum=0

def gcda(x,y,z):
    temp=math.gcd(x,y)
    return math.gcd(temp,z)

for i in range(1,a+1):
    for j in range(1,a+1):
        for k in range(1,a+1):
            sum+=gcda(i,j,k)

print(sum)


Fixed submission:
import math

a=input()
a=int(a)
sum=0

def gcda(x,y,z):
    temp=math.gcd(x,y)
    return math.gcd(temp,z)

for i in range(1,a+1):
    for j in range(1,a+1):
        for k in range(1,a+1):
            sum+=gcda(i,j,k)

print(sum)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
import copy

a = input()
a=int(a)
ball=[]
mydict={}
DPdict={}
temp=input().split(" ")
for i in range(a):
    if not (temp[i] in mydict):
        mydict[temp[i]]=1
    else:
        mydict[temp[i]]+=1
    ball.append(temp[i])

for i in range(len(ball)):
    rettemp=0
    if i in DPdict:
        print(int(DPdict[i]))
        continue
    for j in mydict.keys():

        if ball[i]==j:
            rettemp+=(mydict[j]-1)*(mydict[j]-2)/2
        else :
            rettemp+=(mydict[j]-1)*(mydict[j])/2
    DPdict[i]=rettemp
    print(int(rettemp))


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力

a = input()
# スペース区切りの整数の入力
H,W=a.split(" ")
N=int(H)
M=int(W)
retnum=0
for i in range(N):
    retnum+=i
retnum+=M*(M-1)/2
print(int(retnum))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

# ans = []
# for i in range(len(t)):
#     # print(t[i:])
#     # print(s[i:])
#     if t[i:] in s[i:]:
#         break
#     for j in range(1,len(t[i:])):
#         # print(t[i:][:-j])
#         # print(s[i:][:-j])
#         if t[i:][:-j] in s[i:][:-j]:
#             ans.append(i+j)
#             break
# if t in s:
#     print(0)
# elif len(ans) == 0:
#     print(len(t))
# else:
#     print(min(ans))
ans = len(t)
for i in range(len(s)-len(t)):
    dif = 0
    for j in range(len(t)):
        if t[j] != s[i:i+len(t)][j]:
            diff += 1
    ans = min(dif,ans)

print(ans)     

Fixed submission:
s = input()
t = input()

# ans = []
# for i in range(len(t)):
#     # print(t[i:])
#     # print(s[i:])
#     if t[i:] in s[i:]:
#         break
#     for j in range(1,len(t[i:])):
#         # print(t[i:][:-j])
#         # print(s[i:][:-j])
#         if t[i:][:-j] in s[i:][:-j]:
#             ans.append(i+j)
#             break
# if t in s:
#     print(0)
# elif len(ans) == 0:
#     print(len(t))
# else:
#     print(min(ans))
ans = len(t)
for i in range(len(s)-len(t)+1):
    dif = 0
    for j in range(len(t)):
        if t[j] != s[i:i+len(t)][j]:
            dif += 1
    ans = min(dif,ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC172　C - Walking Takahashi
X,K,D=map(int,input().split())

q=abs(X)//D
if q>K:
    print(abs(X)-K*D)
else:
    if (K-q)%2==0:
        print(abs(X)-q*D)
    else:
        print(abs(abs(X)-(q+1)*D))

Fixed submission:
n = input()

cnt = 0
flag = False
if n[1] == 'S':
    if 'R' in n:
        print(1)
        flag = True
    else:
        print(0)
        flag = True
if flag == False:
    for i in n:
        if i == 'R':
            cnt += 1
    print(cnt)
Buggy python submission (verdict: Runtime Error):
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
for j in range(n+1):
    if k-suma[j] < 0:
        break
    for l in range(m+1):
        if k-suma[j]-sumb[l] > 0:
        res.append(j+l)
print(max(res))

Fixed submission:
n,m,k = map(int, input().split( ))
A = list(map(int, input().split( )))
B = list(map(int, input().split( )))
acc1 = [0]
for i in range(n):
  acc1.append(acc1[-1] + A[i])
acc2 = [0]
for i in range(m):
  acc2.append(acc2[-1] + B[i])

ans = 0
j = m
for i in range(n+1):
  if acc1[i] > k:
    break
  while acc2[j] > k - acc1[i] and j > 0:
    j -= 1
  ans = max(ans,i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

ans = 0
flag = False
suma = []
sumb = []
a = 0
b = 0
for i in an:
    a += i
    if a <= k:
        suma.append(a)
    else:
        break
for i in bn:
    b += i
    if b <= k:
        sumb.append(b)
    else:
        break
suma = suma[::-1]
res = []
for j,l in enumerate(suma):
    dif = k-l
    for o,p in enumerate(sumb):
        if p <= dif:
            res.append(len(suma)-j+o+1)
        else:
            break
            
print(max(res))

Fixed submission:
n,m,k = map(int, input().split( ))
A = list(map(int, input().split( )))
B = list(map(int, input().split( )))
acc1 = [0]
for i in range(n):
  acc1.append(acc1[-1] + A[i])
acc2 = [0]
for i in range(m):
  acc2.append(acc2[-1] + B[i])

ans = 0
j = m
for i in range(n+1):
  if acc1[i] > k:
    break
  while acc2[j] > k - acc1[i] and j > 0:
    j -= 1
  ans = max(ans,i+j)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
A = list(map(int,input().split()))

s = sum(A)
A.sort(reverse=True)

if A[m] >= s*1/(4*m):
    print('Yes')
else:
    print('No')

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

s = sum(A)
A.sort(reverse=True)

if A[m-1] >= s*1/(4*m):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

cnt = 9
if k < 10:
    print(k)
else:
    for i in range(10,10**16+2):
        s = str(i)
        flag = True
        for j in range(len(s)-1):
            if abs(int(s[j])-int(s[j+1])) > 1:
                flag = False
                break
        if flag == True:
            cnt += 1
        if cnt == k:
            print(i)
            break

Fixed submission:
k = int(input())

l = [i for i in range(1,10)]
for i in range(k):
    if l[i]%10 != 0:
        l.append(10*l[i]+l[i]%10-1)
    l.append(10*l[i]+l[i]%10)
    if l[i]%10 != 9:
        l.append(10*l[i]+l[i]%10+1)
print(l[k-1])
Buggy python submission (verdict: Runtime Error):
list(map(int,input().split()))

Fixed submission:
s = input()

if ('A' in s) and ('B' in s):
    print('Yes')
else:
    print('No')