We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.
It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).
Consider the following action:
 - Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.
How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

-----Constraints-----
 - 1 \leq N, M \leq 200000
 - 1 \leq K \leq 10^9
 - 1 \leq A_i, B_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

-----Output-----
Print an integer representing the maximum number of books that can be read.

-----Sample Input-----
3 4 240
60 90 120
80 150 80 150

-----Sample Output-----
3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.
We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.
 - Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.
 - Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.
 - Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.
[{"code": "def solve():\n  N,M,K = map(int, input().split())\n  A = list(map(int, input().split()))\n  B = list(map(int, input().split()))\n  ret = 0\n\n  A_cusum = [0]\n  A_border_index = 0 # \u8d85\u3048\u308b\u3068\u304d\u306eindex\n  for a_ in A:\n    A_end = A_cusum[-1]\n    if A_end+a_ > K:\n      break\n\n    A_cusum.append(A_end+a_)\n    \n  A_border_index = len(A_cusum)-1\n  ret = A_border_index\n\n  B_cusum = [0]\n  B_border_index = 0\n  \n  while A_border_index >= 0 and B_border_index < M:\n\n    while B_border_index < M:\n      B_end = B_cusum[-1]\n      b_ = B[B_border_index]\n\n      if A_cusum[A_border_index]+B_end+b_ > K:\n        break\n\n      B_cusum.append(B_end+b_)\n      B_border_index += 1\n\n    ret = max(ret, A_border_index+B_border_index)\n    A_border_index -= 1\n\n  print(ret)\n  \nsolve()", "passed": true, "time": 0.68, "memory": 14324.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\na=[int(x) for x in input().split()]\nb=[int(x) for x in input().split()]\n\nca,cb=[0],[0]\nfor i in range(n):\n  ca.append(ca[i]+a[i])\nfor i in range(m):\n  cb.append(cb[i]+b[i])\n\nans,j=0,m  \nfor i in range(n+1):\n  if ca[i]>k: break;\n  while cb[j]>k-ca[i]: j-=1;\n  ans=max(ans,i+j)\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "n,m,k = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\n\na = [0]\nb = [0]\n\nfor i in range(n):\n    a.append(a[i]+ A[i])\nfor i in range(m):\n    b.append(b[i] + B[i])\n# print(a)\n# print(b)\n# print(a[3])\nans=0\nj = m\nfor i in range(n+1):\n    if a[i] > k:\n        break\n    while b[j] > k - a[i]:\n        j -= 1\n    ans = max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "import sys\nread = sys.stdin.read\nreadlines = sys.stdin.readlines\nfrom itertools import accumulate\nfrom bisect import bisect\ndef main():\n    n, m, k = map(int, input().split())\n    a = tuple(accumulate(map(int, input().split())))\n    b = tuple(accumulate(map(int, input().split())))\n    r = bisect(b, k)\n\n    for i1, ae in enumerate(a):\n        if k < ae:\n            break\n        r = max(r, bisect(b, k - ae) + i1 + 1)\n    print(r)\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14096.0, "status": "done"}, {"code": "import bisect\nn, m, k = map(int, input().split())\naaa = list(map(int, input().split()))\nbbb = list(map(int, input().split()))\nsum_a = [0] * (n + 1)\nsum_b = [0] * (m + 1)\n\nfor i in range(n):\n    sum_a[i + 1] = sum_a[i] + aaa[i]\n\nfor j in range(m):\n    sum_b[j + 1] = sum_b[j] + bbb[j]\n\nans = 0\nfor i in range(n + 1):\n    if sum_a[i] > k:\n        break\n    tmp = bisect.bisect_right(sum_b, k - sum_a[i])\n    ans = max(ans, i + tmp - 1)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14092.0, "status": "done"}, {"code": "n,m,k = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\nsum_a = [0]\nsum_b = [0]\n\ncounta = 0\nfor x in a:\n    counta += x\n    if counta <= k:\n        sum_a.append(counta)\n    else:\n        break\n\ncountb = 0\nfor y in b:\n    countb += y\n    if countb <= k:\n        sum_b.append(countb)\n    else:\n        break\n\n\nn = len(sum_b)\n\nans = 0\n\nfor i in range(len(sum_a)):\n    for j in reversed(range(n)):\n        if sum_a[i] + sum_b[j]<= k:\n            ans = max(ans,i+j)\n            n = j+1\n            break\n    else:\n        break\n\n\nprint(ans)", "passed": true, "time": 0.26, "memory": 14080.0, "status": "done"}, {"code": "def binary_search(arr, num):\n  left = 0\n  right = len(arr)-1\n  while right-left > 0:\n    mid = (left+right) // 2\n    if arr[mid] > num:\n      right = mid\n    else:\n      left = mid + 1\n  if arr[left] > num:\n    return left\n  else:\n    return len(arr)\n\ndef main():\n  n, m, k = map(int , input().split())\n  a_books = list(map(int , input().split()))\n  b_books = list(map(int , input().split()))\n  a_cum_sum = [0] * (n+1)\n  b_cum_sum = [0] * (m+1)\n\n  for i in range(n):\n    a_cum_sum[i+1] = a_cum_sum[i] + a_books[i]\n  for i in range(m):\n    b_cum_sum[i+1] = b_cum_sum[i] + b_books[i]\n  ans = 0\n  for i in range(n+1):\n    if a_cum_sum[i] > k:\n      break\n    rest = k - a_cum_sum[i]\n    index = binary_search(b_cum_sum, rest)\n    ans = max(ans, i+index-1)\n  print(ans)\n\ndef __starting_point():\n  main()\n__starting_point()", "passed": true, "time": 0.23, "memory": 14272.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\na=[int(x) for x in input().split()]+[10**9+5]\nb=[int(x) for x in input().split()]+[10**9+5]\n\ncnt=i=0\nfor ai in a:\n  if cnt+ai>k: break;\n  cnt+=ai; i+=1; \n\nj=0\nfor bi in b:\n  if cnt+bi>k: break;\n  cnt+=bi; j+=1;\n  \nans=s=i+j\nfor i in reversed(range(i)):\n  s-=1; cnt-=a[i];\n  while cnt+b[j]<=k:\n    s+=1; cnt+=b[j]; j+=1;\n  ans=max(ans,s)\n  \nprint(ans)", "passed": true, "time": 0.22, "memory": 14252.0, "status": "done"}, {"code": "import itertools\nimport bisect\nn,m,k=list(map(int,input().split()))\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nca=[0]+list(itertools.accumulate(a))\ncb=[0]+list(itertools.accumulate(b))\nans=0\nfor i in range(n+1):\n  if k<ca[i]:\n    break\n  j=bisect.bisect(cb,k-ca[i])\n  ans=max(i-1+j,ans)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14392.0, "status": "done"}, {"code": "def main():\n    n, m, k = list(map(int, input().split()))\n    A = list(map(int, input().split()))\n    B = list(map(int, input().split()))\n\n    s = sum(B)\n    ans = 0\n    i, j = 0, m - 1\n    while i < n:\n        if s <= k:\n            ans = max(ans, i + j + 1)\n            s += A[i]\n            i += 1\n        else:\n            if j < 0:\n                break\n            s -= B[j]\n            j -= 1\n\n    if s <= k:\n        ans = max(ans, n + j + 1)\n\n    print(ans)\n    return\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14036.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\na, b = [0], [0]\nfor i in range(N):\n    a.append(a[i] + A[i])\n    \nfor i in range(M):\n    b.append(b[i] + B[i])\n    ans, j = 0, M\n\nfor i in range(N + 1):\n    if a[i] > K:\n        break\n    while b[j] > K - a[i]:\n        j -= 1\n    ans = max(ans, i + j)\nprint(ans)", "passed": true, "time": 0.68, "memory": 14368.0, "status": "done"}, {"code": "N,M,K = map(int,input().split())\nlsA = list(map(int,input().split()))\nlsB = list(map(int,input().split()))\n\nlsAN = [0]\nsumA = 0\nfor i in range(N):\n    sumA += lsA[i]\n    lsAN.append(sumA)\nlsBN = [0]\nsumB = 0\nfor i in range(M):\n    sumB += lsB[i]\n    lsBN.append(sumB)\nj = M\nans = 0\nfor i in range(N+1):\n    if lsAN[i] > K:\n        break\n    while lsBN[j] > K - lsAN[i]:\n        j -= 1\n    ans = max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.26, "memory": 14256.0, "status": "done"}, {"code": "# author:  Taichicchi\n# created: 15.09.2020 21:14:18\n\nimport sys\n\nN, M, K = list(map(int, input().split()))\n\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\na = [0]\nb = [0]\n\nfor i in range(N):\n    a.append(a[i] + A[i])\nfor i in range(M):\n    b.append(b[i] + B[i])\n\nans = 0\nj = M\n\nfor i in range(N + 1):\n    if a[i] > K:\n        break\n    while b[j] > K - a[i]:\n        j -= 1\n    ans = max(ans, i + j)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "N,M,K=map(int,input().split())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\n\na=[0]\nb=[0]\nfor i in range(N):\n    a.append(a[i]+A[i])\nfor i in range(M):\n    b.append(b[i]+B[i])\n\n#print(a)\n#print(b)\n\nans=0\nj=M\nfor i in range(N+1):\n    if a[i]>K:\n        break\n    while b[j]>K-a[i]:\n        j-=1\n    #print(i,j)\n    ans=max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.17, "memory": 14388.0, "status": "done"}, {"code": "from collections import deque\nfrom itertools import accumulate\nn,m,k = map(int,input().split())\na_list = list(accumulate(list(map(int,input().split()))))\na_list = [0]+a_list\nb_list = list(accumulate(list(map(int,input().split()))))\nb_list = [0]+b_list+[float('inf')]\ncnt_list = []\n\nfor i in range(len(a_list)) :\n    t = k\n    cnt = 0\n    a = a_list[i]\n    if t < a :\n        continue\n    t -= a\n    cnt += i\n\n    ok = 0\n    no = m+2\n    while no != ok+1 :\n        center = (ok+no)//2\n\n        if t >= b_list[center] :\n            ok = center\n        if t < b_list[center] :\n            no = center\n    cnt += ok\n    cnt_list.append(cnt)\n\nans = max(cnt_list)\nprint(ans)", "passed": true, "time": 0.25, "memory": 14328.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nA = [0]\nB = [0]\nans = 0\nfor i in range(n):\n    A.append(A[i] + a[i])\nfor i in range(m):\n    B.append(B[i] + b[i])\nj = m\nfor i in range(n + 1):\n    if A[i] > k:\n        break\n    while(A[i] + B[j] > k):\n        # print('i: {}, j: {}'.format(i, j))\n        j -= 1\n    ans = max(ans, i + j)\nprint(ans)\n", "passed": true, "time": 0.23, "memory": 14112.0, "status": "done"}, {"code": "N, M, K= map(int, input().split())\nA=list(map(int, input().split()))\nB=list(map(int, input().split()))\n\nAsum=[0]\nBsum=[0]\n\nfor i in range(N):\n    Asum.append(Asum[-1]+A[i])\n        \nfor i in range(M):\n    Bsum.append(Bsum[-1]+B[i])\n    \nm=0\nj=M\n\nfor i in range(len(Asum)):\n    if Asum[i]>K:\n        break\n    while Asum[i]+Bsum[j]>K:\n        j-=1\n    if m<i+j:\n        m=i+j\n        \nprint(m)", "passed": true, "time": 0.15, "memory": 14100.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\narr1=list(map(int,input().split()))\narr2=list(map(int,input().split()))\n\nacum1=[0]\nfor i in range(n):\n  acum1.append(acum1[-1]+arr1[i])\nacum2=[0]\nfor i in range(m):\n  acum2.append(acum2[-1]+arr2[i])\nans=0\nj=m\nfor i in range(n+1):\n  if acum1[i]>k:\n    break\n  while acum2[j]>k-acum1[i] and j>0:\n    j-=1\n  ans=max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "from itertools import accumulate\nfrom bisect import bisect_right\nN, M, K = map(int,input().split())\nA = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))\nB = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))\nans = 0\nfor i in range(N+1):\n    left = K-A[i]\n    if left < 0:\n        break\n    j = bisect_right(B, left)\n    ans = max(ans, i+j-1)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14268.0, "status": "done"}, {"code": "def getval():\n    n,m,k = map(int,input().split())\n    A = list(map(int,input().split()))\n    B = list(map(int,input().split()))\n    a = [A[0]]\n    b = [B[0]]\n    for i in range(0,n-1):\n        a.append(a[i]+A[i+1])\n    for i in range(0,m-1):\n        b.append(b[i]+B[i+1])\n    return n,m,k,a,b\n\ndef main(n,m,k,a,b):\n    idxa = 0\n    ans = 0\n    t = 0\n    while a[idxa]<=k and idxa<n:\n        idxa += 1\n        if idxa==n:\n            break\n    ans = idxa\n    idxa -= 1\n    t = a[idxa]\n    for i in range(m):\n        t = a[idxa] + b[i]\n        if t<=k:\n            ans = max(ans,idxa+i+2)\n        else:\n            flag = False\n            while t>k:\n                idxa -= 1\n                if idxa<0:\n                    a.append(0)\n                    break\n                t = a[idxa]+b[i]\n            ans = max(ans,idxa+i+2)\n\n    print(ans)\n\ndef __starting_point():\n    n,m,k,a,b = getval()\n    main(n,m,k,a,b)\n__starting_point()", "passed": true, "time": 0.21, "memory": 14364.0, "status": "done"}, {"code": "import bisect\nimport itertools\nn,m,k=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nca=[0]+list(itertools.accumulate(a))\ncb=[0]+list(itertools.accumulate(b))\nans=0\nfor i in range(n+1):\n  bk=ca[i]\n  if bk<=k:\n    j=bisect.bisect(cb,k-bk)\n    ans=max(ans,i+j-1)\n  else:\n    break\nprint(ans)", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nasum=[0]\nbsum=[0]\nfor i in range(n):\n    asum.append(asum[-1]+a[i])\nfor i in range(m):\n    bsum.append(bsum[-1]+b[i])\nans=0\nfor i in range(n+1):\n    if asum[i]>k:\n        break\n    while asum[i]+bsum[m]>k and m>0:\n        m-=1\n    ans=max(ans,i+m)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\na, b = [0], [0]\nfor i in range(n):\n    a.append(a[i] + A[i])\n\nfor i in range(m):\n    b.append(b[i] + B[i])\n\nans, j = 0, m\nfor i in range(n + 1):\n    if a[i] > k:\n        break\n    while b[j] > k - a[i]:\n        j -= 1\n    ans = max(ans, i + j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\nC, D = [0], [0]\nfor i in range(N):\n    C.append(C[-1] + A[i])\nfor i in range(M):\n    D.append(D[-1] + B[i])\n\nans = 0\nfor i in range(N + 1):\n    T = K - C[i]\n    l, r = 0, M + 1\n    while r - l > 1:\n        m = (l + r) // 2\n        if D[m] <= T: l = m\n        else: r = m\n    if T >= 0: ans = max(ans, i + l)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "n,m,k = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nc = [0]*(n+1)\nd = [0]*(m+1)\nfor i in range(n):\n    c[i+1] = a[i]+c[i]\nfor i in range(m):\n    d[i+1] = b[i]+d[i]\nfor i in range(m+1)[::-1]:\n    if d[i] <= k:\n        x = i\n        break\nans = x\nfor i in range(1,n+1):\n    while c[i] + d[x] > k:\n        if x >= 1:\n            x -= 1\n        else:\n            break\n    if c[i] + d[x] <= k:\n        ans = max(ans,i+x)\nprint(ans)", "passed": true, "time": 0.16, "memory": 14180.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\na=[int(x) for x in input().split()]\nb=[int(x) for x in input().split()]\n\nc=[0]\nfor i in range(n):\n  if c[i]+a[i]<=k:\n    c.append(c[i]+a[i])\n  else:\n    break\n\nd=[0]\nfor i in range(m):\n  if d[i]+b[i]<=k:\n    d.append(d[i]+b[i])\n  else:\n    break\n\ne=0\nf=len(d)-1\nfor i in range(len(c)):\n  for j in range(f,-1,-1):\n    if c[i]+d[j]<=k:\n      if i+j>e:\n        e=i+j\n      f=j\n      break\nprint(e)", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "import bisect\nN,M,K = map(int,input().split()) \nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\nfor i in range(1,N):\n  A[i] += A[i-1]\nfor i in range(1,M):  \n  B[i] += B[i-1]\nma = bisect.bisect(A,K)\nfor m in range(0,M):\n  if B[m]>K:\n    break  \n  n = bisect.bisect(A,K-B[m])\n  if  ma < n + m + 1:\n    ma = n + m + 1 \nprint(ma)", "passed": true, "time": 0.23, "memory": 14148.0, "status": "done"}, {"code": "def main():\n    line1 = input()\n    line2 = input()\n    line3 = input()\n    n, m, k = list(map(int, line1.split()))\n    a = [0] + list(map(int, line2.split()))\n    b = [0] + list(map(int, line3.split()))\n    mark1, mark2 = 0, 0\n    for i in range(1, len(a)):\n        a[i] += a[i-1]\n        if a[i] > k:\n            mark1 = i\n            break\n    for i in range(1, len(b)):\n        b[i] += b[i-1]\n        if b[i] > k:\n            mark2 = i\n            break\n    if mark1:\n        a = a[:mark1]\n    if mark2:\n        b = b[:mark2]\n    ans = 0\n    for i in range(len(a)):\n        target = k - a[i]\n        tmp = 0\n        low, high = 0, len(b)\n        while low < high:\n            mid = (low + high) // 2\n            if b[mid] <= target:\n                tmp = mid\n                low = mid + 1\n            else:\n                high = mid - 1\n        ans = max(ans, i + tmp)\n    print(ans)\n    return\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.29, "memory": 14392.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline # for speed up\nsys.setrecursionlimit(10**7)\n\nn,m,k=list(map(int,input().split()))\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\n\naa=[0]*(len(a)+1)\nbb=[0]*(len(b)+1)\n\nfor ii in range(len(a)):\n  aa[ii+1]=aa[ii]+a[ii]\nfor ii in range(len(b)):\n  bb[ii+1]=bb[ii]+b[ii]\n\"\"\"\nprint(a)\nprint(aa)\nprint(b)\nprint(bb)\n\"\"\"\nr=0\njmax=len(bb)-1\nfor ii in range(len(aa)):\n  if aa[ii]>k:\n    break\n  for jj in range(jmax,-1,-1):\n    if bb[jj]>k-aa[ii]:\n      pass\n    else:\n      r=max(r,ii+jj)\n      #print(r,ii,jj)\n      jmax=jj\n      break\nprint(r)\n", "passed": true, "time": 0.14, "memory": 14140.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\ncurr = 0\nA_index = 0\nB_index = 0\nwhile curr + A[A_index] <= K:\n    curr += A[A_index]\n    A_index += 1\n    if A_index == N:\n        break\n\nwhile curr + B[B_index] <= K:\n    curr += B[B_index]\n    B_index += 1\n    if B_index == M:\n        break\n\nans = A_index + B_index\n\nwhile A_index:\n    A_index -= 1\n    curr -= A[A_index]\n    if B_index == M:\n        break\n    while curr + B[B_index] <= K:\n        curr += B[B_index]\n        B_index += 1\n        if B_index == M:\n            break\n    ans = max(ans, A_index + B_index)\n\nprint(ans)", "passed": true, "time": 0.21, "memory": 14216.0, "status": "done"}, {"code": "from bisect import bisect_right\n\nn, m, k = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\ncnt = 0\na_cum = [0] * (n + 1)\nb_cum = [0] * (m + 1)\n\nfor i in range(n):\n    a_cum[i+1] = a_cum[i] + a[i]\nfor i in range(m):\n    b_cum[i+1] = b_cum[i] + b[i]\n\nfor i in range(n+1):\n    a_cnt = i\n    rest = k - a_cum[i]\n    if rest < 0:\n        break\n    b_cnt = bisect_right(b_cum,rest) - 1    \n    cnt = max(cnt, a_cnt + b_cnt)\n\nprint(cnt)", "passed": true, "time": 0.29, "memory": 14116.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\na, b = [0]*(N+1), [0]*(M+1)\nfor i in range(N):\n\ta[i+1] = a[i] + A[i] \nfor i in range(M):\n\tb[i+1] = b[i] + B[i]\n \nans, j = 0, M\nfor i in range(N + 1):\n\tif a[i] > K:\n\t\tbreak\n\twhile b[j] > K - a[i]:\n\t\tj -= 1\n\tans = max(ans, i + j)\nprint(ans)", "passed": true, "time": 0.24, "memory": 14124.0, "status": "done"}, {"code": "n,m,k=map(int,input().split());A,B=eval(\"[0]+[*map(int,input().split())],\"*2);s=t=x=0;j=m\nfor i in range(n+1):s+=A[i];A[i]=s\nfor i in range(m+1):t+=B[i];B[i]=t\nfor i in range(n+1):\n  if A[i]>k:break\n  while B[j]>k-A[i]:j-=1\n  x=max(x,i+j)\nprint(x)", "passed": true, "time": 1.47, "memory": 14156.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nA,B = [0],[0]\n \nfor i in range(n):\n  A.append(a[i] + A[i])\nfor i in range(m):\n  B.append(b[i] + B[i])\n \nnum,x = 0,m\n \nfor i in range(len(A)):\n  if A[i] > k:\n    break\n  while A[i] + B[x] > k:\n    x -= 1\n  num = max(num, i + x)\n  \nprint(num)\n", "passed": true, "time": 0.27, "memory": 14320.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nSA =[0]\nSB =[0]\nfor i in range(len(A)):\n  SA.append(SA[i] + A[i])\nfor j in range(len(B)):\n  SB.append(SB[j] + B[j])\n\nl = M\nans = 0\nfor k in range(N+1):\n  if SA[k] > K:\n    break\n  while SA[k] + SB[l] > K:\n    l -= 1\n  ans = max(ans, k + l)\nprint(ans)", "passed": true, "time": 0.18, "memory": 14344.0, "status": "done"}, {"code": "N , M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\na,b=[0],[0]\nfor i in range(N): a.append(a[i] + A[i])\nfor i in range(M): b.append(b[i] + B[i])\nans,j=0,M\nfor i in range(N+1):\n  if a[i]>K:\n    break\n  while b[j] > K - a[i]:\n    j -= 1\n  ans = max(ans, i+j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14312.0, "status": "done"}, {"code": "from itertools import accumulate\nimport bisect\n\nN, M, K = map(int, input().split())\nA=[0]+list(accumulate(map(int,input().split())))\nB=[0]+list(accumulate(map(int,input().split())))\n\nX = 0\nY_num = [0]*(N+1)\n\nfor i in range(N+1):\n    if A[i] <= K:\n        X = bisect.bisect_right(B, K-A[i])\n        Y_num[i] = i + X - 1\n\nprint(max(Y_num))", "passed": true, "time": 0.15, "memory": 14164.0, "status": "done"}, {"code": "\nN, M , K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\nRA = [0]\nRB = [0]\n\ntmp = 0\nfor i in range(N):\n    tmp += A[i]\n    RA.append(tmp)\n\ntmp = 0\nfor i in range(M):\n    tmp += B[i]\n    RB.append(tmp)\n#print(RA)\n#print(RB)\n\nans = 0\nbest = M\nfor i in range(N+1):\n    if RA[i]>K:\n        break\n    while RB[best] > K - RA[i]:\n        best -= 1\n    ans = max(ans, i + best)\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\na, b = [0], [0]\nfor i in range(N):\n\ta.append(a[i] + A[i])\nfor i in range(M):\n\tb.append(b[i] + B[i])\n\nans, j = 0, M\nfor i in range(N + 1):\n\tif a[i] > K:\n\t\tbreak\n\twhile b[j] > K - a[i]:\n\t\tj -= 1\n\tans = max(ans, i + j)\nprint(ans)", "passed": true, "time": 0.18, "memory": 14152.0, "status": "done"}, {"code": "N,M,K = map(int,input().split())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\na,b = [0],[0]\nfor i in range(N):\n  a.append(a[i]+A[i])\nfor i in range(M):\n  b.append(b[i]+B[i])\nans,j = 0,M\nfor i in range(N+1):\n  if a[i] > K:\n    break\n  while b[j] > K -a[i]:\n    j -= 1\n  ans = max(ans, i+j)\nprint(ans)", "passed": true, "time": 0.19, "memory": 14152.0, "status": "done"}, {"code": "def getmax(x,y):\n    if x>y:\n        return x\n    else:\n        return y\nN,M,K = list(map(int,input().split()))\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\n\na,b = [0],[0]\nfor i in range(N):   #a[i]\u306b\u306fA\u306e\u672c\u3092i\u518a\u8aad\u3093\u3060\u6642\u306e\u6642\u9593\u304c\u305d\u308c\u305e\u308c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\uff0e\n    a.append(a[i]+A[i])  #\u8a08\u7b97\u91cf\u3092\u6e1b\u3089\u3059\u305f\u3081\uff0ca[i]\uff081\u518a\u524d\u307e\u3067\u306b\u304b\u304b\u308b\u6642\u9593\uff09\u3092\u7528\u3044\u308b\nfor i in range(M):\n    b.append(b[i]+B[i])\n\nans,j = 0,M\nfor i in range(N+1):\n    if a[i]>K:\n        break\n    while b[j] > K-a[i]:    #B\u306e\u672c\u3092\u8aad\u3093\u3060\u5834\u5408\u306e\u51e6\u7406\u306f\u3053\u3053\u3067\u5b9f\u884c\u3055\u308c\u308b\uff0e\n        j -=1\n    ans = max(ans, i+j)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline # for speed up\nsys.setrecursionlimit(10**7)\n\nn,m,k=list(map(int,input().split()))\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\naa=[0]*(len(a)+1)\nbb=[0]*(len(b)+1)\n\nfor ii in range(len(a)):\n  aa[ii+1]=aa[ii]+a[ii]\nfor ii in range(len(b)):\n  bb[ii+1]=bb[ii]+b[ii]\n  \nii=0\njmax=0\nr=0\nfor jj in range(len(aa)):\n  if aa[jj]>k:\n    break\n  else:\n    r=ii+jj\n    jmax=jj\n    \nfor ii in range(len(bb)):\n  for jj in range(jmax,-1,-1):\n    if bb[ii]>k-aa[jj]:\n      pass\n    else:\n      jmax=jj\n      r=max(r,ii+jj)\n      break\n\"\"\"\nfor ii in range(m+1):\n  print(c[ii])\n\"\"\"  \n\nprint(r)\n", "passed": true, "time": 0.14, "memory": 14232.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nsum_as = [0]\nsum_bs = [0]\n\nfor i in range(n):\n    sum_as.append(sum_as[i]+a[i])\nfor i in range(m):\n    sum_bs.append(sum_bs[i]+b[i])\n\nans = 0\ni = 0\nj = m\n\nwhile i<=n and sum_as[i] <= k:\n    while sum_bs[j] > k-sum_as[i]:\n        j -= 1\n    ans = max(ans, i+j)\n    i += 1\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = [0] + list(map(int, input().split()))\nB = [0] + list(map(int, input().split()))\nfor i in range(1, N+1):\n    A[i] += A[i-1]\n\ni = N\ntotal = 0\nans = 0\nfor j in range(M+1):\n    total += B[j]\n    while i >= 0 and A[i]+total > K:\n        i -= 1\n    if A[i]+total <= K:\n        ans = max(ans, i+j)\n\nprint(ans)", "passed": true, "time": 0.2, "memory": 14344.0, "status": "done"}, {"code": "n, m ,k = list(map(int, input().split()))\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\na, b = [0], [0]\nfor i in range(n):\n    a.append(a[i]+A[i])\nfor i in range(m):\n    b.append(b[i]+B[i])\n\nans, j = 0, m\nfor i in range(n+1):\n    if a[i] > k:\n        break\n    while b[j] > k - a[i]:\n        j -= 1\n    ans = max(ans, i+j)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14256.0, "status": "done"}, {"code": "N,M,K=map(int,input().split())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\n \na=[0]\nb=[0]\nfor i in range(N):\n    a.append(a[i]+A[i])\nfor i in range(M):\n    b.append(b[i]+B[i])\n \n#print(a)\n#print(b)\n \nans=0\nj=M\nfor i in range(N+1):\n    if a[i]>K:\n        break\n    while b[j]>K-a[i]:\n        j-=1\n    #print(i,j)\n    ans=max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\na, b = [0], [0]\nfor i in range(N):\n  a.append(a[i] + A[i])\nfor i in range(M):\n  b.append(b[i] + B[i])\n\nans, j = 0, M\nfor i in range(N + 1):\n  if a[i] > K:\n    break\n  while b[j] > K - a[i]:\n    j -= 1\n  ans = max(ans, i + j)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14148.0, "status": "done"}, {"code": "from bisect import bisect\nN, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nSA = [0] * (N + 1)\nSB = [0] * (M + 1)\nfor i in range(N):\n    SA[i+1] = SA[i] + A[i]\nfor i in range(M):\n    SB[i+1] = SB[i] + B[i]\nresult = 0\nfor x in range(N+1):\n    if SA[x] > K:\n        break\n    y = bisect(SB, K - SA[x]) - 1\n    result = max(result, x + y)\nprint(result)", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "import bisect\n\nN,M,K=list(map(int,input().split()))\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\nsum1=[0]\nsum2=[0]\nfor i in range(N):\n    sum1.append(sum1[-1]+A[i])\nfor i in range(M):\n    sum2.append(sum2[-1]+B[i])\n\nans=0\nfor i in range(N+1):\n    if sum1[i]>K:\n        break\n    ans=max(ans,i+bisect.bisect_right(sum2,K-sum1[i])-1)\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "# Begin Header {{{\nfrom math import gcd\nfrom collections import Counter, deque, defaultdict\nfrom heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge\nfrom bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort\nfrom itertools import accumulate, product, permutations, combinations, combinations_with_replacement\n# }}} End Header\n# _________\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306f\u3053\u3053\u304b\u3089\uff01\uff01___________\nn, m, k = list(map(int, input().split()))\nA = list(accumulate(list(map(int, input().split()))))\nB = list(accumulate(list(map(int, input().split()))))\nA=[0]+A\nB=[0]+B\nans = []\nfor i in range(n+1):\n    c = bisect_right(B, k-A[i])-1\n    if c!=-1:\n        ans.append(c+i)\nprint((max(ans)))\n", "passed": true, "time": 0.14, "memory": 14120.0, "status": "done"}, {"code": "import itertools\nimport bisect\nn,m,k=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nca=[0]+list(itertools.accumulate(a))\ncb=[0]+list(itertools.accumulate(b))\nans=0\nfor i in range(n+1):\n  wk=ca[i]\n  if wk>k:\n    break\n  else:\n    j=bisect.bisect(cb,k-ca[i])\n    ans=max(ans,i+j-1)\nprint(ans)", "passed": true, "time": 0.23, "memory": 14124.0, "status": "done"}, {"code": "n,m,k = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\nsum_a = [0]\nsum_b = [0]\n\ncounta = 0\nfor x in a:\n    counta += x\n    if counta <= k:\n        sum_a.append(counta)\n    else:\n        break\n\ncountb = 0\nfor y in b:\n    countb += y\n    if countb <= k:\n        sum_b.append(countb)\n    else:\n        break\n\n\nn = len(sum_b)\n\nans = 0\n\nfor i in range(len(sum_a)):\n    for j in reversed(range(n)):\n        if sum_a[i] + sum_b[j]<= k:\n            ans = max(ans,i+j)\n            n = j+1\n            break\n    else:\n        break\n\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "from bisect import bisect\nN, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nSA = [0] * (N + 1)\nSB = [0] * (M + 1)\nfor i in range(N):\n    SA[i+1] = SA[i] + A[i]\nfor i in range(M):\n    SB[i+1] = SB[i] + B[i]\n\nresult = 0\ny = M\nfor x in range(N+1):\n    if SA[x] > K:\n        break\n    while y >= 0 and SA[x] + SB[y] > K:\n        y -= 1\n    result = max(result, x + y)\nprint(result)", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "from itertools import accumulate as a\nN,M,K=map(int,input().split());l=[0]\nP=l+list(a(map(int,input().split())))\nQ=l+list(a(map(int,input().split())))\ni=j=0\nf=lambda:P[i]+Q[j]<=K\nwhile(i<=N)and f():i+=1\nwhile i>=0:\n i-=1\n while(j<=M)and f():j+=1 \n l+=[i+j-1]\nprint(max(l))", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "from itertools import accumulate\nimport bisect\n\nn, m, k = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\na_acc = [0] + list(accumulate(a))  # a\u30920\u518a\u8aad\u3080=1\u518a\u3082\u8aad\u307e\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u306e\u3067\u3001[0]\u3092\u5148\u982d\u306b\u8ffd\u52a0\u3057\u307e\u3059\nb_acc = list(accumulate(b))  # bisect_right\u3067\u306f\u3001x\u4ee5\u4e0b\u306e\u8981\u7d20\u304c\u3044\u304f\u3064\u3042\u308b\u304b\uff1f\u3092\u6c42\u3081\u308b\u306e\u3067\u3001\u3053\u3061\u3089\u306b0\u306f\u5165\u308c\u307e\u305b\u3093\n\nans = 0\nfor an in range(n + 1):\n    rem = k - a_acc[an]\n    if rem < 0:\n        # a\u3092\u3053\u308c\u4ee5\u4e0a\u8aad\u3081\u307e\u305b\u3093\n        break\n\n    bn = bisect.bisect_right(b_acc, rem)\n    ans = max(ans, an + bn)\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "N,M,K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\na = [0]\nb = [0]\n\nfor i in range(N):\n    a.append(a[i] + A[i])\nfor j in range(M):\n    b.append(b[j] + B[j])\nans = 0\nj = M\nfor i in range(N+1):\n    if a[i] > K:\n        break\n    while a[i] + b[j] > K:\n        j -= 1\n    ans = max(ans, i+j)\nprint(ans)", "passed": true, "time": 0.22, "memory": 14360.0, "status": "done"}, {"code": "#tsundoku\nn,m,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\nreadtime_a = [0]\nreadtime_b = [0]\nfor i in range(n):\n    readtime_a.append(readtime_a[i]+a[i])\nfor i in range(m):\n    readtime_b.append(readtime_b[i]+b[i])\n\n#print(readtime_a)\n#print(readtime_b)\n\ncnt = [0]\nimport bisect\n\nfor i in range(n+1):\n    if readtime_a[i] > k:\n        continue\n    else:\n        #print(i,bisect.bisect(readtime_b,k-readtime_a[i])-1,k-readtime_a[i])\n        \n        cnt.append(i-1 + bisect.bisect(readtime_b,k-readtime_a[i]))\n\nprint((max(cnt)))\n", "passed": true, "time": 0.35, "memory": 14392.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = [0] + list(map(int, input().split()))\nB = [0] + list(map(int, input().split()))\nASum, BSum = [0] * (N + 1), [0] * (M + 1)\nASum[0], BSum[0] = A[0], B[0]\nAOver, BOver = -1, -1\nfor i in range(1, N + 1):\n    ASum[i] = ASum[i-1] + A[i]\n    if AOver == -1 and ASum[i] > K: AOver = i - 1\nfor i in range(1, M + 1):\n    BSum[i] = BSum[i-1] + B[i]\n    if BOver == -1 and BSum[i] > K: BOver = i - 1\nif AOver == -1: AOver = N\nif BOver == -1: BOver = M\nans = 0\nimport bisect\nfor i in reversed(range(AOver + 1)):\n    if i + BOver <= ans: break\n    time = K - ASum[i]\n    ans = max(ans, i + bisect.bisect_right(BSum, time) - 1)\n\nprint(ans)", "passed": true, "time": 0.18, "memory": 14272.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\na = [0] + list(map(int, input().split()))\nb = [0] + list(map(int, input().split()))\nfor i in range(1, n + 1):\n    a[i] += a[i - 1]\nfor i in range(1, m + 1):\n    b[i] += b[i - 1]\nans, j = 0, m\nfor i in range(n + 1):\n    if a[i] > k: \n        break\n    while a[i] + b[j] > k:\n        j -= 1\n    if i + j > ans:\n        ans = i + j\nprint(ans)\n\n", "passed": true, "time": 0.33, "memory": 14348.0, "status": "done"}, {"code": "N, M, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\nb = 0\ntb = 0\n\nfor i in range(M):\n    if tb + B[i] > K:\n        break\n    tb += B[i]\n    b = i+1\n\nans = [0, b]\nm = b\na = 0\nta = 0\n\nfor i in range(N):\n    if ta + A[i] > K:\n        break\n    a = i+1\n    ta += A[i]\n    while True:\n        if ta + tb > K:\n            if b == 0:break\n            b -= 1\n            tb -= B[b]\n        else:\n            if a + b > m:\n                m = a + b\n                ans = [a, b]\n            break\n\nprint((ans[0]+ans[1]))\n\n\n", "passed": true, "time": 0.14, "memory": 14200.0, "status": "done"}, {"code": "from sys import stdin\nnii=lambda:map(int,stdin.readline().split())\nlnii=lambda:list(map(int,stdin.readline().split()))\nfrom bisect import bisect_right\nfrom itertools import accumulate\n\nn,m,k=nii()\na=lnii()\nb=lnii()\nar=[0]+list(accumulate(a))\nbr=list(accumulate(b))\n\nans=0\nfor i in range(n+1):\n  time=ar[i]\n  if time>k:\n    break\n  t_ans=i\n  inx=bisect_right(br,k-time)\n  t_ans+=inx\n  ans=max(ans,t_ans)\nprint(ans)", "passed": true, "time": 0.24, "memory": 14216.0, "status": "done"}, {"code": "from itertools import accumulate\nfrom bisect import bisect_left\n\nri = lambda S: [int(v) for v in S.split()]\n\n\ndef rii():\n    return ri(input())\n\n\nN, M, K = rii()\nA = rii()\nB = rii()\n\ni = j = 0\n\npA = [0] + list(accumulate(A))\npB = [0] + list(accumulate(B))\n\nans = 0\nfor i, a in enumerate(pA):\n    br = 0\n    if K >= a:\n        r = K - a\n        br = i\n    \n    if r:\n        j = bisect_left(pB, r)\n        if j != len(pB):\n            if pB[j] > r:\n                j -= 1\n            br += j\n    \n    ans = max(ans, br)\n\nprint(ans)", "passed": true, "time": 0.25, "memory": 14244.0, "status": "done"}, {"code": "import itertools\nn,m,k=map(int,input().split())\na=list(itertools.accumulate(list(map(int,input().split()))))\nb=list(itertools.accumulate(list(map(int,input().split()))))\na.insert(0,0)\na=[a[-i-1] for i in range(n+1)]\nb.insert(0,0)\nj=0\nans=0\nfor i in range(n+1):\n  if a[i]<=k and j!=m+1:\n    while a[i]+b[j]<=k:\n      j+=1\n      if j==m+1:\n        break\n    ans=max(ans,n-i+j-1)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nA,B = [0],[0]\n\nfor i in range(n):\n  A.append(a[i] + A[i])\nfor i in range(m):\n  B.append(b[i] + B[i])\n\nnum,x = 0,m\n\nfor i in range(n+1):\n  if A[i] > k:\n    break\n  while A[i] + B[x] > k:\n    x -= 1\n  num = max(num, i + x)\n  \nprint(num)\n\n\n", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nimport itertools as it\nsa = [0] + list(it.accumulate(a))\nsb = [0] + list(it.accumulate(b))\nmaxi = 0\nj = m \nfor i in range(n+1):\n    if sa[i] <= k:\n        while sa[i] + sb[j] > k:\n            j -= 1\n        maxi = max(maxi, i + j)\n\nprint(maxi)\n\n\n\n\n", "passed": true, "time": 0.35, "memory": 14208.0, "status": "done"}, {"code": "n,m,k = map(int,input().split())\nshelfA = list(map(int,input().split()))\nshelfB = list(map(int,input().split()))\nprodA = [0]*(n+1)\nprodB = [0]*(m+1)\nfor i in range(1,n+1):\n    prodA[i] = prodA[i-1] + shelfA[i-1]\nfor i in range(1,m+1):\n    prodB[i] = prodB[i-1] + shelfB[i-1]\n\nans = -1\nj = m\nfor i in range(n+1):\n    if(prodA[i]>k):\n        break\n    while(prodB[j] > k - prodA[i]):\n        # print(prodB[j],j,k-prodA[i])\n        j-=1\n    # print(ans)\n    ans = max(ans,i+j)\n\n\n\nprint(ans)", "passed": true, "time": 0.24, "memory": 14040.0, "status": "done"}, {"code": "def binary_search(arr, num):\n  left = 0\n  right = len(arr)-1\n  while right-left > 0:\n    mid = (left+right) // 2\n    if arr[mid] > num:\n      right = mid\n    else:\n      left = mid + 1\n  if arr[left] > num:\n    return left\n  else:\n    return len(arr)\n\ndef main():\n  n, m, k = map(int , input().split())\n  a_books = list(map(int , input().split()))\n  b_books = list(map(int , input().split()))\n  b_cum_sum = [0] * (m+1)\n  for i in range(m):\n    b_cum_sum[i+1] = b_cum_sum[i] + b_books[i]\n  current = 0\n  ans = 0\n  for i in range(n+1):\n    if i > 0:\n      current += a_books[i-1]\n    if current > k:\n      break\n    rest = k - current\n    index = binary_search(b_cum_sum, rest)\n    ans = max(ans, i+index-1)\n  print(ans)\n\ndef __starting_point():\n  main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "N, M, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\ncumsum_a = [0] * (N + 1)\ncumsum_b = [0] * (M + 1)\n\nfor i in range(1, N + 1):\n    cumsum_a[i] = cumsum_a[i - 1] + A[i - 1]\n\nfor i in range(1, M + 1):\n    cumsum_b[i] = cumsum_b[i - 1] + B[i - 1]\n\nans = 0\nbi = M\nfor i in range(N+1):\n    for j in range(bi, -1, -1):\n        t = cumsum_a[i] + cumsum_b[j]\n        if t <= K:\n            ans = max(ans, i + j)\n            bi = j\n            break\n\nprint(ans)\n", "passed": true, "time": 0.34, "memory": 14300.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\ns = sum(B)\nans = 0\ni, j = 0, M - 1\nwhile i < N:\n    #print(s, i, j)\n    if s <= K:\n        ans = max(ans, i + j + 1)\n        s += A[i]\n        i += 1\n    else:\n        if j < 0: break\n        s -= B[j]\n        j -= 1\nif s <= K:\n    ans = max(ans, N + j + 1)\nprint(ans)", "passed": true, "time": 0.33, "memory": 14164.0, "status": "done"}, {"code": "N, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\na, b = [0], [0]\nfor i in range(N):\n    a.append(a[i] + A[i])\nfor i in range(M):\n    b.append(b[i] + B[i])\nans, j = 0, M\nfor i in range(N + 1):\n    if a[i] > K:\n        break\n    while b[j] > K - a[i]:\n        j -= 1\n    ans = max(ans, i + j)\nprint(ans)", "passed": true, "time": 0.25, "memory": 14356.0, "status": "done"}, {"code": "#172 \u7dd1\nfrom itertools import accumulate\nN,M,K=map(int,input().split())\nAlist=list(map(int,input().split()))\nBlist=list(map(int,input().split()))\ncumsum=list(accumulate(Alist))\nans=0\nnum=0\nflag=0\nflag1=0\nfor i in range(N):\n    if cumsum[i]>K:\n        suma=cumsum[i-1]\n        break\nelse:\n    flag1=True\n    ans+=1\n    num+=1\n    suma=cumsum[i]\nans+=i #index\u6ce8\u610f\nnum+=i\nk=0\nwhile suma+Blist[k]<=K:\n    suma+=Blist[k]\n    k+=1\n    num+=1\n    if k==M:\n        print(num)\n        return\nans=max(ans,num)\nfor j in range(i+1):\n    if flag1:\n        suma-=Alist[i-j]\n    else:\n        suma-=Alist[i-1-j]\n    num-=1\n    while suma+Blist[k]<=K:\n        suma+=Blist[k]\n        k+=1\n        num+=1\n        ans=max(ans,num)\n        if k>=M:\n            flag=True\n            break\n    if flag:\n        break\nans=max(ans,num)\nprint(ans)", "passed": true, "time": 0.35, "memory": 14124.0, "status": "done"}, {"code": "import sys\ndef input(): return sys.stdin.readline().rstrip()\nfrom itertools import accumulate\ndef main():\n    n, m, k = map(int,input().split())\n    A = [0] + list(map(int,input().split()))\n    B = [0] + list(map(int,input().split()))\n    A = list(accumulate(A))\n    B = list(accumulate(B))\n    ans = 0\n    j = m\n    for i in range(n + 1):\n        if A[i] > k:\n            break\n        while A[i] + B[j] > k:\n            j -= 1\n        ans = max(ans, i + j)\n    print(ans)\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.25, "memory": 14208.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\naa = list(map(int, input().split()))\nbb = list(map(int, input().split()))\nasum = [0]\nbsum = [0]\n\nfor i in range(len(aa)):\n    asum.append(asum[i]+aa[i])\nfor i in range(len(bb)):\n    bsum.append(bsum[i]+bb[i])\n\nj = len(bsum)-1\nans = 0\nfor i in range(len(asum)):\n    while j >= 0:\n        if k >= asum[i] + bsum[j]:\n            ans = max(ans, i+j)\n            break\n        else:\n            j -= 1\n\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14088.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nA,B = [0],[0]\n \nfor i in range(n):\n  A.append(a[i] + A[i])\nfor i in range(m):\n  B.append(b[i] + B[i])\n \nnum,x = 0,m\n \nfor i in range(len(a)+1):\n  if A[i] > k:\n    break\n  while A[i] + B[x] > k:\n    x -= 1\n  num = max(num, i + x)\n  \nprint(num)\n \n", "passed": true, "time": 0.14, "memory": 14096.0, "status": "done"}, {"code": "N, M, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\n\ndef get_integral(nums):\n    integral = [0]\n    for i in range(0, len(nums)):\n        integral.append(integral[i] + nums[i])\n\n    return integral\n\n\nintegral_a = get_integral(A)\nintegral_b = get_integral(B)\n\nans = 0\nbestj = M\nfor i in range(N+1):\n    ta = integral_a[i]\n    if ta > K:\n        break\n    while ta + integral_b[bestj] > K:\n        bestj -= 1\n\n    best = i + bestj\n    ans = max(best, ans)\n\nprint(ans)\n\n\n", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "n,m,k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nfrom itertools import accumulate\nimport bisect\ncumsum_a = list(accumulate(a))\ncumsum_b = list(accumulate(b))\n\nans = 0\nfor i in range(1, n+1):\n    if cumsum_a[i-1] > k:\n        break\n    \n    cnt_b = bisect.bisect(cumsum_b, k - cumsum_a[i-1])\n    ans = max(ans, i + cnt_b)\n\nfor i in range(1, m+1):\n    if cumsum_b[i-1] > k:\n        break\n    \n    cnt_a = bisect.bisect(cumsum_a, k - cumsum_b[i-1])\n    ans = max(ans, i + cnt_a)\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14088.0, "status": "done"}, {"code": "import bisect\n\nN,M,K=map(int,input().split())\narr1=list(map(int,input().split()))\narr2=list(map(int,input().split()))\n\nA=[0]\nfor i in range(N):\n  A.append(arr1[i]+A[-1])\nB=[0]\nfor i in range(M):\n  B.append(arr2[i]+B[-1])\n\nans=0\nfor i in range(N+1):\n  if A[i]>K:\n    break\n  j=bisect.bisect_right(B,K-A[i])-1\n  ans=max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.22, "memory": 14152.0, "status": "done"}, {"code": "from bisect import bisect_left\nN, M, K = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nSA = [0] * (N + 1)\nSB = [0] * (M + 1)\nfor i in range(N):\n    SA[i+1] = SA[i] + A[i]\nfor i in range(M):\n    SB[i+1] = SB[i] + B[i]\nresult = 0\nfor x in range(N+1):\n    if SA[x] > K:\n        break\n    y = bisect_left(SB, K - SA[x] + 1) - 1\n    result = max(result, x + y)\nprint(result)", "passed": true, "time": 0.14, "memory": 14132.0, "status": "done"}, {"code": "N,M,K=map(int,input().split())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\n \na=[0]\nb=[0]\nfor i in range(N):\n    a.append(a[i]+A[i])\nfor i in range(M):\n    b.append(b[i]+B[i])\n \n#print(a)\n#print(b)\n \nans=0\nj=M\nfor i in range(N+1):\n    if a[i]>K:\n        break\n    while b[j]>K-a[i]:\n        j-=1\n    #print(i,j)\n    ans=max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14152.0, "status": "done"}, {"code": "def main(N, M, K, A, B):\n    #print(f'K: {K}, A: {A}, B: {B}')\n\n    Ai = [0]\n    for i in range(N):\n        Ai.append(Ai[i]+A[i])\n    #print(f'Ai: {Ai}')\n\n    Bj = [0]\n    for j in range(M):\n        Bj.append(Bj[j]+B[j])\n    #print(f'Bj: {Bj}')\n\n    ans = 0\n    # len(A) = N+1, len(B) = M+1\n    best_i = 0\n    for j in range(M+1):\n        tmp = 0\n        for i in range(best_i, N+1):\n            #print(f'i: {N-i}, j: {j}')\n            #if Ai[N-i] + Bj[M-j] <= K:\n            if Ai[N-i] + Bj[j] <= K:\n                #tmp = N - i + M - j\n                tmp = N - i + j\n                best_i = i\n                break\n        #print(f'tmp: {tmp}')\n        if tmp > ans:\n            ans = tmp\n\n    return ans\n            \n\ndef __starting_point():\n    N, M, K = list(map(int, input().split()))\n    A = list(map(int, input().split()))\n    B = list(map(int, input().split()))\n    print((main(N, M, K, A, B)))\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nx,i,j=0,0,0\na.append(10**9+1)\nb.append(10**9+1)\nwhile x+a[i]<=k:\n    x+=a[i]\n    i+=1\nmaxs=i\nfor c in range(n+m):\n    if x+b[j]<=k:\n        x+=b[j]\n        j+=1\n        maxs=max(maxs,i+j)\n    else:\n        if i>0:\n          x=max(0,x-a[i-1])\n          i-=1\nprint(maxs)", "passed": true, "time": 0.14, "memory": 14064.0, "status": "done"}, {"code": "N,M,K = map(int,input().split())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\na = [0]\nfor i in range(N):\n    a.append(a[i] + A[i])\nak = [i-K for i in a]\nb = [0]\nfor i in range(M):\n    b.append(b[i] - B[i])\nimport bisect\nans = 0\nfor i in range(M+1):\n    k = bisect.bisect_right(ak,b[i])\n    if k > 0:\n        ans = max(k+i-1,ans)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14036.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Mon Sep  7 11:05:00 2020\n\n@author: liang\n\"\"\"\n\n\"\"\"\n\u7247\u5074\u3092\u56fa\u5b9a\u3057\u3066\u3001\u305d\u308c\u305e\u308c\u306e\u30b1\u30fc\u30b9\u306b\u5bfe\u3057\u3066\u6700\u9069\u89e3\u3092\u6c42\u3081\u308b\n\u305d\u308c\u305e\u308c\u306e\u30b1\u30fc\u30b9\u306b\u3064\u3044\u3066\nindex(b_i) =< index(b_i-1)\n\u3067\u3042\u308b\u304b\u3089\u3001b\u306e\u6700\u5927\u5024best\u3092\u4fdd\u5b58\u3057\u3066\u63a2\u7d22\u3059\u308b\u3053\u3068\u3067\u91cd\u8907\u63a2\u7d22\u3092\u56de\u907f\u3067\u304d\u308b\n\"\"\"\nN, M, K = map(int, input().split())\n\nA = [0] + [int(x) for x in input().split()]\nB = [0] + [int(x) for x in input().split()]\n\ns_b = 0\nfor i in range(M+1):\n    s_b += B[i]\n    if s_b > K:\n        s_b -= B[i]\n        best = i - 1\n        break\nelse:\n    best = M\nres = best\n#print(res)\ns_a = 0\nfor i in range(N+1):\n   # print(\"i\", i)\n    s_a += A[i]\n    if s_a > K:\n        break\n    for j in reversed(range(best+1)):\n        #print(\"j\",j)\n        if s_b <= K - s_a:\n            if i + j > res:\n                res = i + j\n            best = j\n            #print(i, j, s_a, s_b)\n            break\n        else:\n            s_b -= B[j]\n        \nprint(res)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\na = [0] + list(map(int, input().split()))\nb = [0] + list(map(int, input().split()))\n\nfor i in range(1, n + 1):\n    a[i] += a[i - 1]\n\nfor i in range(1, m + 1):\n    b[i] += b[i - 1]\n\nans = 0\n\nb_cnt = m\n\nfor a_cnt in range(n + 1):\n    if a[a_cnt] > k:\n        continue\n\n    while a[a_cnt] + b[b_cnt] > k:\n        b_cnt -= 1\n\n    ans = max(ans, a_cnt + b_cnt)\n\nprint(ans)\n\n", "passed": true, "time": 0.14, "memory": 14112.0, "status": "done"}, {"code": "from itertools import accumulate\nimport bisect\nn,m,k = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\na_c = [0] + list(accumulate(a))\nb_c = [0] + list(accumulate(b))\n\nresult = []\n\nfor i in range(n+1):\n    if k >= a_c[i]:\n        k_temp = k - a_c[i]\n        b_idx = bisect.bisect_left(b_c, k_temp+1)\n        result.append(i + b_idx - 1)\n    else:\n        pass\nresult.append(0)\nprint(max(result))", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect\n#from operator import itemgetter\n#from heapq import heappush, heappop\n#import numpy as np\n#import sympy\n#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson\n#from scipy.sparse import csr_matrix\nfrom decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN\nimport sys\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nnf = lambda: float(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nnb = lambda: list(map(float, stdin.readline().split()))\nns = lambda: stdin.readline().rstrip()  # ignore trailing spaces\n\nN, M, K = na()\nA = na()\nB = na()\nnow = 0\nct = 0\nx = -1\ny = 0\nans = 0\nfor i in range(N):\n    if A[i] + now <= K:\n        now += A[i]\n        ct += 1\n        x += 1\n    else:\n        break\nres = K - now\nans = ct\nwhile y < M:\n    if res - B[y] >= 0:\n        ct += 1\n        ans = max(ct, ans)\n        res -= B[y]\n        y += 1\n    elif res - B[y] < 0 and x >= 0:\n        res += A[x]\n        ct -= 1\n        x -= 1\n    else:\n        break\nprint(ans)", "passed": true, "time": 0.16, "memory": 14176.0, "status": "done"}, {"code": "n, m , k = map(int, input().split())\n\na = list(map(int, input().split()))\n\nb = list(map(int, input().split()))\n\nA, B = [0], [0]\n\nfor i in range(n):\n    A.append(A[i] + a[i])\nfor i in range(m):\n    B.append(B[i] + b[i])\n\nans, j = 0, m\n\nfor i in range(n+1):\n    if A[i] > k:\n        break\n    while B[j] > k - A[i]:\n        j -= 1\n    ans = max(ans,i+ j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14356.0, "status": "done"}, {"code": "n,m,k = map(int,input().split())\ntmp_a = list(map(int,input().split()))\ntmp_b = list(map(int,input().split()))\na = [0]\nb = [0]\nfor i in range(n):\n    a.append(a[i]+tmp_a[i])\nfor i in range(m):\n    b.append(b[i]+tmp_b[i])\n#print(a)\n#print(b)\nans = 0\nj = m\nfor i in range(n+1):\n    if a[i] > k:\n        break\n    while b[j] > k - a[i]:\n        j -= 1\n    ans = max(ans,i+j)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "from itertools import accumulate\nimport bisect\nn, m, k = list(map(int, input().split()))\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nA = list(accumulate(A, initial=0))\nB = list(accumulate(B, initial=0))\nans = 0\nfor i, a in enumerate(A):\n    remain = k - a\n    if remain < 0:\n        break\n    tmp = i\n    tmp += bisect.bisect_right(B, remain) - 1\n    ans = max(ans, tmp)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split(\" \")))\na = [int(i) for i in input().split(\" \")]\nb = [int(i) for i in input().split(\" \")]\nA = [0]\nB = [0]\nfor i in a:\n    if A[-1] > k:\n        break\n    A.append(A[-1] + i)\nfor i in b:\n    if B[-1] > k:\n        break\n    B.append(B[-1] + i)\n\nans = 0\nj = len(B) - 1\n\nfor i in range(len(A)):\n    if A[i] > k:\n        break\n    while A[i] + B[j] > k:\n        j -= 1\n    ans = max(ans, i + j)\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\naArr = list(map(int, input().split()))\nbArr = list(map(int, input().split()))\n\nt = sum(bArr)\nans = 0\nj = m\n\nfor i in range(n + 1):\n  while j > 0 and t > k:\n    j -= 1\n    t -= bArr[j]\n  if t > k:\n    break\n  ans = max(ans, i + j)\n  if i == n:\n    break\n  t += aArr[i]\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14068.0, "status": "done"}]