Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
_a = a[:]
_a.sort()
__a = a[:]
__a.sort(reverse=True)

i = 0
cand_1 = [_a.pop(-1)]
cand_2 = [__a.pop(-1)]
while len(_a) > 0:
    if i % 4 < 2:
        _b = _a.pop(0)
        __b = __a.pop(0)
    else:
        _b = _a.pop(-1)
        __b = __a.pop(-1)
    if i % 2 == 0:
        cand_1.append(_b)
        cand_2.append(__b)
    else:
        cand_1.insert(0, _b)
        cand_2.insert(0, __b)
    i += 1
res1 = 0
res2 = 0
for i in range(1, n):
    res1+= abs(cand_1[i]-cand_1[i-1])
    res2+= abs(cand_2[i]-cand_2[i-1])

print(max(res1, res2))


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort(reverse=True)

if n % 2 == 0:
    res = 0
    for i in range(n // 2 - 1):
        res += a[i] * 2
    res += a[n // 2 - 1]
    res -= a[n // 2]
    for i in range(n // 2 + 1, n):
        res -= a[i] * 2
    print(res)
else:
    res1 = 0
    for i in range(n // 2 - 1):
        res1 += a[i] * 2
    res1 += a[n // 2 - 1] + a[n // 2]
    for i in range(n // 2 + 1, n):
        res1 -= a[i] * 2

    res2 = 0
    for i in range(n // 2):
        res2 += a[i] * 2
    res2 -= a[n // 2] + a[n // 2 + 1]
    for i in range(n // 2 + 2, n):
        res2 -= a[i] * 2
    print(max(res1, res2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
_a = a[:]
_a.sort()
__a = a[:]
__a.sort(reverse=True)

i = 0
cand_1 = [_a.pop(-1)]
cand_2 = [__a.pop(-1)]
while len(_a) > 0:
    if i % 4 < 2:
        _b = _a.pop(0)
        __b = __a.pop(0)
    else:
        _b = _a.pop(-1)
        __b = __a.pop(-1)
    if i % 2 == 0:
        cand_1.append(_b)
        cand_2.append(__b)
    else:
        cand_1.insert(0, _b)
        cand_2.insert(0, __b)
    i += 1
res1 = 0
res2 = 0
for i in range(1, n):
    res1+= abs(cand_1[i]-cand_1[i-1])
    res2+= abs(cand_2[i]-cand_2[i-1])

print(max(res1, res2))


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort(reverse=True)

if n % 2 == 0:
    res = 0
    for i in range(n // 2 - 1):
        res += a[i] * 2
    res += a[n // 2 - 1]
    res -= a[n // 2]
    for i in range(n // 2 + 1, n):
        res -= a[i] * 2
    print(res)
else:
    res1 = 0
    for i in range(n // 2 - 1):
        res1 += a[i] * 2
    res1 += a[n // 2 - 1] + a[n // 2]
    for i in range(n // 2 + 1, n):
        res1 -= a[i] * 2

    res2 = 0
    for i in range(n // 2):
        res2 += a[i] * 2
    res2 -= a[n // 2] + a[n // 2 + 1]
    for i in range(n // 2 + 2, n):
        res2 -= a[i] * 2
    print(max(res1, res2))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

for base in range(1, M//N+1)[::-1]:
    if M % base != 0:
        continue
    print(base)
    break


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

for base in range(1, M//N+1)[::-1]:
    if M % base != 0:
        continue
    print(base)
    break
Buggy python submission (verdict: Runtime Error):
import function
n, start = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]
x_list.append(start)
x_list.sort()


current_gcd = x_list[1] - x_list[0]
for i in range(1, n-1):
    gap = x_list[i+1] - x_list[i]
    current_gcd = function.gcd(current_gcd, gap)

print(current_gcd)

Fixed submission:
import fractions
n, start = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]

x_list.sort()

current_gcd = 0
for i in range(0, n):
    gap = abs(start - x_list[i])
    current_gcd = fractions.gcd(current_gcd, gap)

print(current_gcd)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

print((a-1)*(b-1))

Fixed submission:
a, b = [int(i) for i in input().split()]

print((a-1)*(b-1))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

cum =[0 for _ in range(n)]
cum[0] = a[0] % m
for i in range(1, n):
    cum[i] = cum[i-1] + a[i] % m
    cum[i] %= m

ans = 0
cnt = [0 for _ in range(m)]

for i in cum:
    ans += cnt[i]
    cnt[i] += 1
ans += cnt[0]
print(ans)


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

cum =[0 for _ in range(n)]
cum[0] = a[0] % m
for i in range(1, n):
    cum[i] = cum[i-1] + a[i] % m
    cum[i] %= m

from collections import Counter
c = Counter(cum)

ans = sum((v*(v-1)//2) for v in c.values())
if 0 in c:
    ans += c[0]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import statistics
n = int(input())
a_list = list(map(int, input().split()))

pro_list = [a_list[i-1] - i for i in range(1, n+1)]
ave = int(statistics.mean(pro_list))

b_list = [ave - 1 for i in range(5000)] + [ave + i for i in range(5000)]

ans = [sum([abs(pro-b)for pro in pro_list]) for b in b_list]
print(min(ans))

Fixed submission:
import statistics
n = int(input())
a_list = list(map(int, input().split()))

pro_list = [a_list[i-1] - i for i in range(1, n+1)]
ave = int(statistics.mean(pro_list))
med = int(statistics.median(pro_list))
b_list = [ave - 1 for i in range(10)] + [ave + i for i in range(10)]
b_list += [med - 1 for i in range(10)] + [med + i for i in range(10)]

ans = [sum([abs(pro-b)for pro in pro_list]) for b in b_list]
print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))

sum = [[0 for j in range(n)] for i in range(n)]
xor = [[0 for j in range(n)] for i in range(n)]
ans = n

for i in range(n):
    sum[i][i] = a_list[i]
    xor[i][i] = a_list[i]
for r in range(n):
    for l in range(r+1, n):
        sum[r][l] = sum[r][l-1] + a_list[l]
        xor[r][l] = xor[r][l - 1] ^ a_list[l]
        if sum[r][l] == xor[r][l]:
            ans += 1

print(ans)


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

ans = 0
r = -1
xor_n = 0
sum_n = 0
for l in range(n):
    while True:
        r += 1

        if r < n:
            nr = a[r]
            xor_n ^= nr
            sum_n += nr
            ok = xor_n == sum_n
        if r >= n or not ok:
            ans += (r - 1) - l + 1
            sum_n -= nr
            sum_n -= a[l]
            xor_n ^= nr
            xor_n ^= a[l]
            r -= 1
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

cand_list = []
for i in range(len(s)):
    for j in range(0, len(s)+1):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break

print(sorted(list(set(cand_list)))[k-1])

Fixed submission:
s = input()
k = int(input())

cand_list = []
for i in range(len(s)):
    for j in range(len(s)+1-i):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break
        elif len(cand_list) > k:
            cand_list.pop(len(cand_list) - 1)

print(sorted(cand_list)[k-1])

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

cand_list = []
for i in range(1, len(s)+1):
    for j in range(len(s)):
        cand_list.append(s[j:j+i])

print(sorted(list(set(cand_list)))[k-1])

Fixed submission:
s = input()
k = int(input())

cand_list = []
for i in range(len(s)):
    for j in range(len(s)+1-i):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break
        elif len(cand_list) > k:
            cand_list.pop(len(cand_list) - 1)

print(sorted(cand_list)[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    x = sorted(X[:])
    for i in range(N):
        _x = x[:]
        _x.remove(X[i])
        print(_x[int(N/2-1)])


Fixed submission:
if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    x = sorted(X[:])
    min_median = x[int(N/2-1)]
    max_median = x[int(N/2)]
    for i in range(N):
        if X[i] <= min_median:
            print(max_median)
        else:
            print(min_median)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))

    for i in range(N):
        x = X[:]
        x.pop(i)
        x.sort()
        print(x[int(N/2-1)])


Fixed submission:
if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    x = sorted(X[:])
    min_median = x[int(N/2-1)]
    max_median = x[int(N/2)]
    for i in range(N):
        if X[i] <= min_median:
            print(max_median)
        else:
            print(min_median)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

for i in range(A, B+1):
    if i < (A + K) or (B-K) < i:
        print(i)

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

if A + K >= B or A >= B - K:
    ans = [i for i in range(A, B+1)]
else:
    ans = [i for i in range(A, A+K)]
    ans.extend([j for j in range(B - K + 1, B+1)])
    ans = sorted(list(set(ans)))
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

is_odd_list = [A % 2 == 0, B % 2 == 0, C % 2 == 0]
if all(is_odd_list) or not any(is_odd_list):
    ans = 0
else:
    if sum(is_odd_list) == 1:
        is_odd_list = not is_odd_list
    A = A + is_odd_list[0]
    B = B + is_odd_list[1]
    C = C + is_odd_list[2]
    ans = 1

num_list = sorted([A, B, C])
ans += (num_list[2] - num_list[0]) / 2 + (num_list[2] - num_list[1]) / 2
print(int(ans))

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

is_odd_list = [A % 2 == 0, B % 2 == 0, C % 2 == 0]
if all(is_odd_list) or not any(is_odd_list):
    ans = 0
else:
    if sum(is_odd_list) == 1:
        is_odd_list = [not i for i in is_odd_list]
    A = A + is_odd_list[0]
    B = B + is_odd_list[1]
    C = C + is_odd_list[2]
    ans = 1

num_list = sorted([A, B, C])
ans += (num_list[2] - num_list[0]) / 2 + (num_list[2] - num_list[1]) / 2
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = 0
r = n-1
hist = []
print(0, flush=True)
hist.append(0)
current = input()

while r - l > 2:
    mid = (l+r)//2
    print(mid,flush=True)
    hist.append(mid)
    nex = input()
    if nex == 'Vacant':
        exit()
    if current == nex:
        l = mid
    else:
        r = mid
    current = nex

cand = [i for i in range(l, r+1) if i not in hist]
for i in cand:
    print(i, flush=True)
    nex = input()
    if nex == 'Vacant':
        exit()

Fixed submission:
import sys

n = int(input())
print(0)
sys.stdout.flush()
ls = input()
if ls == 'Vacant':
    exit()
print(n - 1)
sys.stdout.flush()
if input() == 'Vacant':
    exit()
l = 0
r = n - 1
while l != r - 1:
    mid = (l + r) // 2
    if mid % 2 == 1:
        mid += 1
    if mid == r:
        mid -= 1
    print(mid)
    sys.stdout.flush()
    nex = input()
    if nex == 'Vacant':
        exit()

    if ls == nex:
        l = mid
    else:
        r = mid

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

l = 0
r = n-1
hist = []
print(0, flush=True)
hist.append(0)
current = input()

while r - l > 2:
    mid = (l+r)//2
    print(mid,flush=True)
    hist.append(mid)
    nex = input()
    if nex == 'Vacant':
        exit()
    if current == nex:
        l = mid
    else:
        r = mid
    current = nex

cand = [i for i in range(l, r+1) if i not in hist]
for i in cand:
    print(i, flush=True)
    nex = input()
    if nex == 'Vacant':
        exit()

Fixed submission:
import sys

n = int(input())
print(0)
sys.stdout.flush()
ls = input()
if ls == 'Vacant':
    exit()
print(n - 1)
sys.stdout.flush()
if input() == 'Vacant':
    exit()
l = 0
r = n - 1
while l != r - 1:
    mid = (l + r) // 2
    if mid % 2 == 1:
        mid += 1
    if mid == r:
        mid -= 1
    print(mid)
    sys.stdout.flush()
    nex = input()
    if nex == 'Vacant':
        exit()

    if ls == nex:
        l = mid
    else:
        r = mid

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

l = 0
r = n-1
hist = []
print(0)
hist.append(0)
current = input()

while r - l > 2:
    mid = (l+r)//2
    print(mid)
    hist.append(mid)
    nex = input()
    if nex == 'Vacant':
        exit()
    if current == nex:
        l = mid
    else:
        r = mid
    current = nex

cand = [i for i in range(l, r+1) if i not in hist]
for i in cand:
    print(i)
    nex = input()
    if nex == 'Vacant':
        exit()

Fixed submission:
import sys

n = int(input())
print(0)
sys.stdout.flush()
ls = input()
if ls == 'Vacant':
    exit()
print(n - 1)
sys.stdout.flush()
if input() == 'Vacant':
    exit()
l = 0
r = n - 1
while l != r - 1:
    mid = (l + r) // 2
    if mid % 2 == 1:
        mid += 1
    if mid == r:
        mid -= 1
    print(mid)
    sys.stdout.flush()
    nex = input()
    if nex == 'Vacant':
        exit()

    if ls == nex:
        l = mid
    else:
        r = mid
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

abs = [list(map(int, input().split())) for i in range(M)]

ans = 0

for ab in abs:
    a = ab[0] - 1
    b = ab[1] - 1
    _abs = abs[::]
    _abs.remove(ab)

    dist_map = [[i == j for j in range(N)] for i in range(N)]

    for _ab in _abs:
        _a = _ab[0] - 1
        _b = _ab[1] - 1
        if not dist_map[_a][_b]:
            dist_map[_a][_b] = True
            dist_map[_b][_a] = True

    for i in range(N):
        for j in range(N):
            for k in range(N):
                dist_map[j][k] = dist_map[j][k] or (dist_map[j][i] and dist_map[i][k])
                dist_map[k][j] = dist_map[j][k]

    if not dist_map[a][b]:
        ans += 1

print(ans)

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

abs = [list(map(int, input().split())) for i in range(M)]

ans = 0

for ab in abs:
    a = ab[0] - 1
    b = ab[1] - 1
    _abs = abs[::]
    _abs.remove(ab)

    dist_map = [[i == j for j in range(N)] for i in range(N)]

    for _ab in _abs:
        _a = _ab[0] - 1
        _b = _ab[1] - 1
        if not dist_map[_a][_b]:
            dist_map[_a][_b] = True
            dist_map[_b][_a] = True

    for i in range(N):
        for j in range(N):
            for k in range(N):
                dist_map[j][k] = dist_map[j][k] or (dist_map[j][i] and dist_map[i][k])
                dist_map[k][j] = dist_map[j][k]

    if not dist_map[a][b]:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
abcs = [list(map(int, input().split())) for i in range(M)]
INF = 10**9
dist_list = [[INF if i != j else 0 for j in range(N)] for i in range(N)]

# distance[i][j]で(i, j)間の最短の移動距離を保持
for abc in abcs:
    a = abc[0]-1
    b = abc[1]-1
    c = abc[2]
    if c < dist_list[a][b]:
        dist_list[a][b] = c
        dist_list[b][a] = c
# ワーシャルフロイド
for i in range(1, N):
    for j in range(N):
        for k in range(N):
            dist_list[j][k] = min(dist_list[j][k], dist_list[j][i] + dist_list[i][k])
            dist_list[k][j] = dist_list[j][k]

# 総当たり
result = []


def permutation(data, res):
    global result
    if len(data) == 0:
        result.append(res)
        return

    for i in data:
        _res = res[::]
        _res.append(i)
        _data = data[::]
        _data.remove(i)
        permutation(_data, _res)


permutation(r, [])
min_distance = INF
for res in result:
    distance = 0
    for i in range(1, len(res)):
        x = res[i]-1
        y = res[i-1]-1
        distance += dist_list[x][y]
    if distance < min_distance:
        min_distance = distance
print(min_distance)

Fixed submission:
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
abcs = [list(map(int, input().split())) for i in range(M)]
INF = 10**9
dist_list = [[INF if i != j else 0 for j in range(N)] for i in range(N)]

# distance[i][j]で(i, j)間の最短の移動距離を保持
for abc in abcs:
    a = abc[0]-1
    b = abc[1]-1
    c = abc[2]
    if c < dist_list[a][b]:
        dist_list[a][b] = c
        dist_list[b][a] = c
# ワーシャルフロイド
for i in range(1, N):
    for j in range(N):
        for k in range(N):
            dist_list[j][k] = min(dist_list[j][k], dist_list[j][i] + dist_list[i][k])
            dist_list[k][j] = dist_list[j][k]

# 総当たり
result = []


def permutation(data, res):
    global result
    if len(data) == 0:
        result.append(res)
        return

    for i in data:
        _res = res[::]
        _res.append(i)
        _data = data[::]
        _data.remove(i)
        permutation(_data, _res)


permutation(r, [])
min_distance = INF
for res in result:
    distance = 0
    for i in range(1, len(res)):
        x = res[i]-1
        y = res[i-1]-1
        distance += dist_list[x][y]
    if distance < min_distance:
        min_distance = distance
print(min_distance)
Buggy python submission (verdict: Runtime Error):
a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a'))


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))

Fixed submission:
a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a')+1)


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))
Buggy python submission (verdict: Runtime Error):
import sys
from functools import reduce
from math import gcd

POSSIBLE = "POSSIBLE"
IMPOSSIBLE = "IMPOSSIBLE"
n, k = map(int, input().split())
a = list(map(int, input().split()))

# max(a) < k → だめ
# N == 1 ぴったじゃなきゃだめ
# N > 1
## 互いに素な数が含まれている → ○
## 含まれてないが、kがその倍数 → ○
if max(a) < k:
    print(IMPOSSIBLE)
    exit()
if n == 1:
    if k == a[0]:
        print(POSSIBLE)
    else:
        print(IMPOSSIBLE)
else:
    g = reduce(lambda a, b: gcd(a, b), a)
    if g == 1:
        print(POSSIBLE)
    else:
        if k % g == 0:
            print(POSSIBLE)
        else:
            print(IMPOSSIBLE)



Fixed submission:
from functools import reduce
from fractions import gcd

POSSIBLE = "POSSIBLE"
IMPOSSIBLE = "IMPOSSIBLE"
n, k = map(int, input().split())
a = list(map(int, input().split()))

# max(a) < k → だめ
# N == 1 ぴったじゃなきゃだめ
# N > 1
## 互いに素な数が含まれている → ○
## 含まれてないが、kがその倍数 → ○
if max(a) < k:
    print(IMPOSSIBLE)
    exit()
if n == 1:
    if k == a[0]:
        print(POSSIBLE)
    else:
        print(IMPOSSIBLE)
else:
    g = reduce(lambda a, b: gcd(a, b), a)
    if g == 1:
        print(POSSIBLE)
    else:
        if k % g == 0:
            print(POSSIBLE)
        else:
            print(IMPOSSIBLE)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]

stack = [2]

can = False
while True:
    if stack[len(stack)-1] == 1:
        can = True
        break
    c = stack[len(stack)-1]
    i = a.index(c)+1
    if i in stack:
        break
    stack.append(i)

if can:
    print(len(stack)-1)
else:
    print(-1)

Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]

can = False
cnt = 0
idx = a[0]-1
while True:
    cnt += 1
    if cnt > N:
        break
    if idx == 1:
        can = True
        break
    idx = a[idx] - 1

if can:
    print(cnt)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from math import ceil, log10, sqrt

n = int(input())
ans = 0
for i in range(ceil(sqrt(n)))[::-1]:
    if n % i == 0:
        a = i
        b = n//i
        ans = max(len(str(a)), len(str(b)))
        break
print(ans)


Fixed submission:
from math import ceil, log10, sqrt

n = int(input())
ans = 0
for i in range(1, ceil(sqrt(n))+1)[::-1]:
    if n % i == 0:
        a = i
        b = n//i
        ans = max(len(str(a)), len(str(b)))
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
c = list(input())
ans = 0
#print(c)
for i in range(N):
    flag = 0
    if c[i] == "R":
        continue
    elif c[i] == "W":
        #print(c, ans, i, sep=" ",)
        for j in reversed(range(N)):
            if i == j:
                flag = 1
                break
            if c[j] == "R":
                c[i], c[j] = c[j], c[i]
                ans += 1
                print(c, ans, sep=" ")
                break
        else:
            continue
        if flag == 1:
            break

print(ans)

Fixed submission:
N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-cnt:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N + 1):
    A[i] += A[i-1]
for i in range(1, M + 1):
    B[i] += B[i-1]

ans = 0
for a_cnt in range(N + 1):
    if A[a_cnt] > K:
        continue
    b_cnt = M
    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)

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

for i in range(1, N + 1):
    A[i] += A[i-1]
for i in range(1, M + 1):
    B[i] += B[i-1]

ans = 0
b_cnt = M
for a_cnt in range(N + 1):
    if A[a_cnt] > K:
        continue
    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for _a in a:
    all_xor = all_xor ^ _a
for _a in a:
    print(all_xor ^ _a)





Fixed submission:
#import numpy as np
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for _a in a:
    all_xor = all_xor ^ _a
for _a in a:
    print(all_xor ^ _a)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from operator import mul
from functools import reduce


n = int(input())
A = list(map(int, input().split()))
cnt_a = Counter(A)
memo = [1] * 1000001
for a in A:
    memo[a] = 1
A.sort()
for a in A:
    for i in range(a * 2, 1000001, a):
        memo[i] = -1
for l in cnt_a.keys():
    if cnt_a[l] >= 2:
        memo[l] = "daburi"
ans = 0
for a in A:
    if memo[a] == 1:
        ans += 1
print(ans)


Fixed submission:
from collections import Counter
from operator import mul
from functools import reduce


n = int(input())
A = list(map(int, input().split()))
cnt_a = Counter(A)
memo = [1] * 1000001
for a in A:
    memo[a] = 1
A.sort()
a_max = max(A)
for a in A:
    if not memo[a]:
        continue
    for i in range(a * 2, a_max + 1, a):
        memo[i] = -1
for l in cnt_a.keys():
    if cnt_a[l] >= 2:
        memo[l] = "daburi"
ans = 0
for a in A:
    if memo[a] == 1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
import copy

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


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

A.sort()
rA.sort(reverse=True)
ans = 0
for i in range(len(rA)):
    if rA.count(rA[i]) >= 2:
        continue
    flag = 1
    for j in range(len(A)):
        if rA[i] < A[j] * 2:
            break
        if rA[i] % A[j] == 0:
            flag = -1
            break
    if flag == 1:
       ans += 1

print(ans)


Fixed submission:
from collections import Counter
from operator import mul
from functools import reduce


n = int(input())
A = list(map(int, input().split()))
cnt_a = Counter(A)
memo = [1] * 1000001
for a in A:
    memo[a] = 1
A.sort()
a_max = max(A)
for a in A:
    if not memo[a]:
        continue
    for i in range(a * 2, a_max + 1, a):
        memo[i] = -1
for l in cnt_a.keys():
    if cnt_a[l] >= 2:
        memo[l] = "daburi"
ans = 0
for a in A:
    if memo[a] == 1:
        ans += 1
print(ans)