Buggy python submission (verdict: Time Limit Exceeded):
# C - Tsundoku
import sys
sys.setrecursionlimit(10**9)

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())

la = 0
t = 0
for i in range(N):
    if A[i] + t <= K:
        la += 1
        t += A[i]

lb = 0
t = 0
for i in range(M):
    if B[i] + t <= K:
        lb += 1
        t += B[i]

T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)
    return

dfs(0, 0, T, 0)
print(ans)

Fixed submission:
# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# C - Tsundoku
import sys
sys.setrecursionlimit(10**9)

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
la = len(A)
lb = len(B)
T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)
    return

dfs(0, 0, T, 0)
print(ans)

Fixed submission:
# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# C - Tsundoku
import sys
sys.setrecursionlimit(10**9)

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
la = len(A)
lb = len(B)
T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)
    return

dfs(0, 0, T, 0)
print(ans)

Fixed submission:
# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
# C - Tsundoku
import sys
sys.setrecursionlimit = 10**18

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
la = len(A)
lb = len(B)
T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)
    return
    
dfs(0, 0, T, 0)
print(ans)

Fixed submission:
# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
# C - Tsundoku
import sys
sys.setrecursionlimit = 10**18

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
la = len(A)
lb = len(B)
T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)

dfs(0, 0, T, 0)
print(ans)

Fixed submission:
# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
# C - Tsundoku
import sys
sys.setrecursionlimit = 10**10

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
la = len(A)
lb = len(B)
T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)

dfs(0, 0, T, 0)
print(ans)

Fixed submission:
# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
# C - Tsundoku
import sys
sys.setrecursionlimit = 10**7

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
la = len(A)
lb = len(B)
T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)

dfs(0, 0, T, 0)
print(ans)

Fixed submission:
# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)