Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]


for i in range(n+1):
    for j in range(m+1):
        if a[i] + b[j] <= k:
            pass
        else:
            if a[i] + b[j-1] <= k:
                cnt = max(cnt, i + j - 1)
            break
    else:
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split())))
b=list(map(int, input().split())))

cnt=0

a_sum=[0]
b_sum=[0]

a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a_sum[i] += a_sum[i-1]

for i in range(1, m+1):
    b_sum[i] += b_sum[i-1]


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            pass
        else:
            if a_sum[i] + b_sum[j-1] <= k:
                cnt=max(cnt, i + j - 1)
            break
    else:
        if a_sum[i] + b_sum[j] <= k:
            cnt=max(cnt, i + j)
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0

a_sum = [0]
b_sum = [0]

a_sum.extend(a)
b_sum.extend(b)


for i in range(1, n+1):
    a_sum[i] += a_sum[i-1]

for i in range(1, m+1):
    b_sum[i] += b_sum[i-1]


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            pass
        else:
            if a_sum[i] + b_sum[j-1] <= k:
                cnt = max(cnt, i + j - 1)
            break
    else:
        if a_sum[i] + b_sum[j] <= k:
            cnt = max(cnt, i + j)
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0

a_sum = [0]
b_sum = [0]

a_sum.extend(a)
b_sum.extend(b)


for i in range(1, n+1):
    a_sum[i] += a_sum[i-1]

for i in range(1, m+1):
    b_sum[i] += b_sum[i-1]


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            cnt = max(cnt, i + j)
        else:
            break
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
# import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0

a_sum = deque([0])
b_sum = deque([0])
atmp = 0
btmp = 0

for i in a:
    atmp += i
    a_sum.append(atmp)

for i in b:
    btmp += i
    b_sum.append(btmp)


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            cnt = max(cnt, i + j)
        else:
            break

print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
# import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0

a_sum = deque([0])
b_sum = deque([0])
atmp = 0
btmp = 0

for i in a:
    atmp += i
    a_sum.append(atmp)

for i in b:
    btmp += i
    b_sum.append(btmp)


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            cnt = max(cnt, i + j)

print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0

a_sum = [0]
b_sum = [0]
atmp = 0
btmp = 0

for i in a:
    atmp += i
    a_sum.append(atmp)

for i in b:
    btmp += i
    b_sum.append(btmp)


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            cnt = max(cnt, i + j)

print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
from collections import deque
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1
    else:
        for i in range(1, min(len(a), len(b))):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == deque([]):
        for i in range(len(b)):
            if k < b[0]:
                break
            k -= b.popleft()
            cnt += 1
        break
    if b == deque([]):
        for i in range(len(a)):
            if k < a[0]:
                break
            k -= a.popleft()
            cnt += 1
        break
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
from collections import deque
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1

    else:
        for i in range(1, min(len(a), len(b))+1):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a.popleft()
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == deque([]):
        for i in range(len(b)):
            if k < b[0]:
                break
            k -= b.popleft()
            cnt += 1
        break
    if b == deque([]):
        for i in range(len(a)):
            if k < a[0]:
                break
            k -= a.popleft()
            cnt += 1
        break
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
from collections import deque
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1

    else:
        for i in range(1, min(len(a), len(b))+1):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a.popleft()
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == deque([]):
        for i in range()
        k -= b.popleft()
        cnt += 1
        if
        break
    if b == deque([]):
        while k >= a[0]:
            k -= a.popleft()
            cnt += 1
        break
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
from collections import deque
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1

    else:
        for i in range(1, min(len(a), len(b))+1):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a.popleft()
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == deque([]):
        while k > b[0]:
            k -= b.popleft()
            cnt += 1
        break
    if b == deque([]):
        while k > a[0]:
            k -= a.popleft()
            cnt += 1
        break
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
from collections import deque
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1

    else:
        for i in range(1, min(len(a), len(b))+1):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a[0]
                    a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b[0]
                    b.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a[0]
                    a.popleft()
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b[0]
                    b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == deque([]):
        a = [float("inf")]
    if b == deque([]):
        b = [float("inf")]

print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
from collections import deque
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1

    else:
        for i in range(1, min(len(a), len(b))+1):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a[0]
                    a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b[0]
                    b.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a[0]
                    a.popleft()
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b[0]
                    b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == []:
        a = [float("inf")]
    if b == []:
        b = [float("inf")]
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)

Buggy python submission (verdict: Runtime Error):
from sys import exit
# import copy
# import numpy as np
# from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a[0]
        a.pop(0)
        cnt += 1

    elif a[0] > b[0]:
        k -= b[0]
        b.pop(0)
        cnt += 1

    else:
        for i in range(1, min(len(a), len(b))+1):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a[0]
                    a.pop(0)
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b[0]
                    b.pop(0)
                    cnt += 1
                    if k < a[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a[0]
                    a.pop(0)
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b[0]
                    b.pop(0)
                    cnt += 1
                    if k < b[0]:
                        break
    if a == []:
        a = [float("inf")]
    if b == []:
        b = [float("inf")]
print(cnt)


Fixed submission:
from sys import exit
import copy
# import numpy as np
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0


a.insert(0, 0)
b.insert(0, 0)


for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)