Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=deque()
  mapA=map(int,input().strip("\n").split())
  for a in mapA:
    A.append(a)
  B=deque()
  mapB=map(int,input().strip("\n").split())
  for b in mapB:
    B.append(b)
  #A=list(map(int,input().strip("\n").split()))
  #B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  #def dfs(a,b,k,s):
  def dfs(A,B,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    ansA=s
    ansB=s
    if len(A)>0:
      x=copy.deepcopy(A)
      y=copy.deepcopy(B)
      tmp=x.popleft()
      ansA=dfs(x,y,k-tmp,s+1)
    #if a<n:
    #  ansA=dfs(a+1,b,k-A[a],s+1)
    #else:
    #  ansA=s
    if len(B)>0:
      #print(A)
      x=copy.deepcopy(A)
      y=copy.deepcopy(B)
      tmp=y.popleft()
      ansB=dfs(x,y,k-tmp,s+1)
    #if b<m:
    #  ansB=dfs(a,b+1,k-B[b],s+1)
    #else:
    #  ansB=s
    return max(ansA,ansB)

  x=copy.deepcopy(A)
  y=copy.deepcopy(B)
  ans=dfs(x,y,k,0)
  #ans=max(dfs(1,0,k-A[0],1),dfs(0,1,k-B[0],1))
  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=deque()
  mapA=map(int,input().strip("\n").split())
  for a in mapA:
    A.append(a)
  B=deque()
  mapB=map(int,input().strip("\n").split())
  for b in mapB:
    B.append(b)
  #A=list(map(int,input().strip("\n").split()))
  #B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  #def dfs(a,b,k,s):
  def dfs(A,B,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    ansA=s
    ansB=s
    if len(A)>0:
      x=copy.deepcopy(A)
      y=copy.deepcopy(B)
      tmp=x.popleft()
      ansA=dfs(x,y,k-tmp,s+1)
    #if a<n:
    #  ansA=dfs(a+1,b,k-A[a],s+1)
    #else:
    #  ansA=s
    if len(B)>0:
      #print(A)
      x=copy.deepcopy(A)
      y=copy.deepcopy(B)
      tmp=y.popleft()
      ansB=dfs(x,y,k-tmp,s+1)
    #if b<m:
    #  ansB=dfs(a,b+1,k-B[b],s+1)
    #else:
    #  ansB=s
    return max(ansA,ansB)

  x=copy.deepcopy(A)
  y=copy.deepcopy(B)
  ans=dfs(x,y,k,0)
  #ans=max(dfs(1,0,k-A[0],1),dfs(0,1,k-B[0],1))
  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a<n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s

    if b<m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=max(dfs(1,0,k-A[0],1),dfs(0,1,k-B[0],1))
  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a<n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s
    if b<m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=dfs(0,0,k,0)
  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a<n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s
    if b<m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=dfs(0,0,k,0)
  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a<n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s
    if b<m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=dfs(0,0,k,0)
  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a!=n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s
    if b!=m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=dfs(0,0,k,0)
  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  ans=0
  a=0
  b=0
  while k>0 and (a<n or b<m):
    if a>=n:
      if k<B[b]:
        break
      ans+=1
      k-=B[b]
      b+=1
      continue

    if b>=m:
      if k<A[a]:
        break
      ans+=1
      k-=A[A]
      a+=1
      continue

    if A[a]<=B[b]:
      if k<A[a]:
        break
      ans+=1
      k-=A[a]
      a+=1
    else:
      if k<B[b]:
        break
      ans+=1
      k-=B[b]
      b+=1

  print(ans)


Fixed submission:
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)