Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
A = sorted(list(map(int,input().split())))
def gcdaaaaaaaaa(L):
    nextminb = L[0]
    nextn = len(L)
    while True:
        n = nextn
        minb = nextminb
        for l in L[:n]:
            nextn = 0
            r= l % minb
            
            if r != 0:
                L[nextn] = r
                nextn += 1
                if r < nextminb :
                    nextminb = r
        if minb == nextminb:
            return minb
        
def gcd(a,b):
    if b == 0:
        return a
    else:
        r = a % b
        a = b
        b = r
        return gcd(a,b)
def gcdL(L):
    g = L[0]
    if len(L) > 1:
        for l in L[1:]:
            g = gcd(g,l)
    return g



lgcd = [0] * N
rgcd = [0] * N

for i in range(N):
    lgcd[i] = gcdL(A[0:i+1])
    rgcd[i] = gcdL(A[i:])
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd(lgcd[i-1],rgcd[i+1])
    if maxg < g:
        maxg = g

print(maxg)


### FIXED CODE ###

N = int(input())
A = sorted(list(map(int,input().split())))
def gcdaaaaaaaaa(L):
    nextminb = L[0]
    nextn = len(L)
    while True:
        n = nextn
        minb = nextminb
        for l in L[:n]:
            nextn = 0
            r= l % minb
            
            if r != 0:
                L[nextn] = r
                nextn += 1
                if r < nextminb :
                    nextminb = r
        if minb == nextminb:
            return minb
        
def gcd(a,b):
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b,r)
def gcdL(L):
    g = L[0]
    for l in L:
        g = gcd(g,l)
    return g



lgcd = [0] * N
rgcd = [0] * N

lg = A[0]
rg = A[-1]
for i in range(N):
    
    lg = gcd(lg,A[i])
    lgcd[i] = lg
    rg = gcd(rg,A[N-i-1])
    rgcd[N-i-1] = rg
    
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd(lgcd[i-1],rgcd[i+1])
    if maxg < g:
        maxg = g

print(maxg)
### BUGGY CODE ###

import itertools

def f(n):
  out = sum([True for x, y, z in itertools.product(range(1, n+1), repeat=3) if x**2+y**2+z**2+x*y+y*z+z*x==n])
  return out

N = int(input())
for n in range(1, N+1):
  print(f(n))

### FIXED CODE ###

import itertools
import collections



N = int(input())
count = [0]*N*100
m = int(N**0.5)
for x, y, z in itertools.combinations_with_replacement(range(1, m+1), 3):
  n = x**2+y**2+z**2+x*y+y*z+z*x
  k = len(set({x, y, z}))
  if k == 1:
    count[n] += 1
  elif k == 2:
    count[n] += 3
  else:
    count[n] += 6

for n in range(1, N+1):
  print(count[n])
### BUGGY CODE ###

n = int(input())
s = input()
cntList = []
for i in range(n):
    cnt = 0
    for j in range(i):
        if s[j] == "W":
            cnt += 1
    for k in range(i + 1, n):
        if s[k] == "E":
            cnt += 1

    cntList.append(cnt)

print(min(cntList))

### FIXED CODE ###

n = int(input())
s = input()

w_e = [0] * n
e_w = [0] * n
ans = []

for i in range(n - 1):
    if s[i] == 'W':
        w_e[i + 1] = w_e[i] + 1
    else:
        w_e[i + 1] = w_e[i] + 0

for i in range(n - 2, -1, -1): 
    if s[i + 1] == 'E':
        e_w[i] = e_w[i + 1] + 1
    else:
        e_w[i] = e_w[i + 1] + 0

for i in range(n):
    ans.append(w_e[i] + e_w[i])

print(min(ans))
### BUGGY CODE ###

from sys import stdin
x = int(stdin.readline().rstrip())

if x == 1:
    print(0,-1)


for i in range(1,x):
    if x%i==0:
        for a in range(i):
            b = a-i
            if int(a**4 + a**3*b + a**2*b**2 + a*b**3 + b**4) == int(x/i):
                print(a,b)
                exit()
    else:
        pass


### FIXED CODE ###

from sys import stdin
x = int(stdin.readline().rstrip())

for i in range(-120,120):
    for j in range(-120,120):
        if i**5 - j**5 == x:
            print(i, j)
            exit()
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n):
      if (i//2)*2+1!=l[i]:
        return 0
    x=1
    for _ in range(n//2):
      x*=2
      x%=mod
    return x

  else:
    if l[0]!=0:
      return 0
    for i in range(n-1):
      if (i//2)*2+2!=l[1:][i]:
        return 0
    x=1
    for _ in range(n//2):
      x*=2
      x%=mod
    return x

print(main())


### FIXED CODE ###

a=1000000007
n=int(input())
l=list(map(int,input().split()))
l.sort()
if n%2==1:
  if l[0]!=0:
    print(0)
    exit()
  else:
    l.remove(0)
    sh=2
    f=0
    for i in l:
      if f==0:
        if i!=sh:
          print(0)
          exit()
        else:
          f=1
      else:
        if i!=sh:
          print(0)
          exit()
        else:
          sh+=2
          f=0
  sh=(n-1)//2
  b=1
  for i in range(sh):
    b*=2
    b%=a
  print(b)
else:
  sh=1
  f=0
  for i in l:
    if f==0:
      if i!=sh:
        print(0)
        exit()
      else:
        f=1
    else:
      if i!=sh:
        print(0)
        exit()
      else:
        sh+=2
        f=0
  sh=n//2
  b=1
  for i in range(sh):
    b*=2
    b%=a
  print(b)
### BUGGY CODE ###

N, K = map(int, input().split())
l = []
Ap = 0
An = 0
As = list(map(int, input().split()))
for i in range(N):
    A = As[i]
    l.append(A)
    if i < K:
        Ap = Ap + A
    else:
        An = Ap - l.pop(0) + A
        if An > Ap:
            print("Yes")
        else:
            print("No")
        Ap = An


### FIXED CODE ###

N, K = map(int, input().split())
l = []
i = 0
for x in input().split():
    A = int(x)
    if K < N - i:
        l.insert(0, A)
    if i >= K:
        if l.pop() < A:
            print("Yes")
        else:
            print("No")
    i = i + 1
### BUGGY CODE ###

n = int(input())
t = []
c = 0
for i in range(n):
    s = input()
    for j in range(len(t)):
        if s == t[j][0]:
            t[j][1] += 1
            c = 1
            break
    if c == 0:
        t.append([s, 1])
    c = 0
a = []
b = 0
for i in range(len(t)):
    if b < t[i][1]:
        b = t[i][1]
        a = [t[i][0]]
    elif b == t[i][1]:
        a.append(t[i][0])
a.sort()
for i in a:
    print(i)

### FIXED CODE ###

n = int(input())
s = {}
m = 1
for _ in range(n):
    t = input()
    if t in s:
        s[t] += 1
        if s[t] > m:
            m = s[t]
    else:
        s.update({t : 1})
ans = [i for i, j in s.items() if j == m]
ans.sort()
for i in ans:
    print(i)
### BUGGY CODE ###

import sys
from collections import Counter

input = sys.stdin.readline
cache = {}


def dfs(n):
    ret = cache.get(n)
    if ret is not None:
        return ret
    ret = 0
    for i in range(1, n + 1):
        ret += (i - 1)
        cache[i] = ret
    return ret


def get_ans(counter):
    ret = 0
    for key, value in counter.items():
        ret += dfs(value)
    return ret


def main():
    _ = int(input())
    nums = list(map(int, input().split()))

    counter = Counter()
    for num in nums:
        counter[num] += 1

    for num in nums:
        counter[num] -= 1
        print(get_ans(counter))
        counter[num] += 1


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import Counter

input = sys.stdin.readline


def main():
    int(input())
    nums = list(map(int, input().split()))

    counter = Counter()
    ret = 0
    for num in nums:
        counter[num] += 1
        ret += (counter[num] - 1)

    for num in nums:
        ret -= (counter[num] - 1)
        print(ret)
        ret += (counter[num] - 1)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import bisect
sys.setrecursionlimit(10**8)

N,Q=map(int,input().split())
S=input().strip()
S=[ord(s)-65 for s in S]
M=[input().split() for i in range(Q)]

MLIST=[[] for i in range(26)]

for i in range(Q):
    m,lr=M[i][0],M[i][1]
    MLIST[ord(m)-65].append(i)

dist=dict()
def distinct(PLACE,TURN):
    #print(PLACE,TURN)

    x=bisect.bisect_left(MLIST[S[PLACE]],TURN)

    if x==len(MLIST[S[PLACE]]):
        #dist[(PLACE,TURN)]=1
        return 1

    TURN=MLIST[S[PLACE]][x]

    if dist.get((PLACE,TURN))!=None:
        return dist.get((PLACE,TURN))
    
    if PLACE==0 and M[TURN][1]=="L":
        dist[(PLACE,TURN)]=0
        return 0
    
    if PLACE==N-1 and M[TURN][1]=="R":
        dist[(PLACE,TURN)]=0
        return 0

    if M[TURN][1]=="L":
        dist[(PLACE,TURN)]=distinct(PLACE-1,TURN+1)
        return dist[(PLACE,TURN)]

    if M[TURN][1]=="R":
        dist[(PLACE,TURN)]=distinct(PLACE+1,TURN+1)
        return dist[(PLACE,TURN)]

ANS=0
for i in range(N):
    ANS+=distinct(i,0)
    #print(i,dist)

print(ANS)
    

### FIXED CODE ###

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
S=input().strip()
M=[input().split() for i in range(Q)]

PLACE=-1

for i in range(Q-1,-1,-1):

    if PLACE+1<N and M[i][0]==S[PLACE+1] and M[i][1]=="L":
        PLACE+=1

    elif PLACE>=0 and M[i][0]==S[PLACE] and M[i][1]=="R":
        PLACE-=1

    if PLACE==N:
        print(0)
        sys.exit()

PLACE2=N

for i in range(Q-1,-1,-1):

    if PLACE2-1>=0 and M[i][0]==S[PLACE2-1] and M[i][1]=="R":
        PLACE2-=1

    elif PLACE2<=N-1 and M[i][0]==S[PLACE2] and M[i][1]=="L":
        PLACE2+=1

    if PLACE==-1:
        print(0)
        sys.exit()

print(max(0,N-(PLACE+1+(N-PLACE2))))
### BUGGY CODE ###

a = int(input())
p = list(map(int,input().split()))
mod = 10**9 + 7
t = 1
sum_list = []
for i in range(a):
    for t in range(a):
        if i <= t and not i ==t:
            w = p[i]*p[t]
            sum_list.append(w)

print(sum(sum_list)%mod)

### FIXED CODE ###

import itertools as itr

a = int(input())
p = list(map(int,input().split()))
mod = 10**9 + 7
ans =0
sum_list = list(itr.accumulate(p))
for i in range(len(p)-1):
    o = p[i+1]
    w =sum_list[i]
    ans = (ans+o*w%mod)%mod
print(ans)
### BUGGY CODE ###

def main():
    import sys
    sys.setrecursionlimit(10**7)
    input = sys.stdin.readline
    n = int(input())
    l = [list(map(int,input().split())) for i in range(n)]
    v = n*(n-1)//2
    E = [[] for i in range(v)]
    dic = {}
    c = 0
    for i in range(n):
        for j in range(n-1):
            a,b = i,l[i][j]-1
            if a > b:
                a,b = b,a
            if (a,b) in dic:
                l[i][j] = dic[(a,b)]
            else:
                dic[(a,b)] = c
                l[i][j] = dic[(a,b)]
                c += 1
        for j in range(n-2):
            E[l[i][j]].append(l[i][j+1])

    def dfs(i):
        if visit[i]:
            if dis[i] == -1:
                return -1
            else:
                return dis[i]
        visit[i] = True
        d = 1
        for nex in E[i]:
            res = dfs(nex)
            if res == -1:
                return -1
            d = max(d,res+1)

        dis[i] = d
        return d
    ans = 0
    done = []
    for i in range(n):
        if l[i][0] in done:
            continue
        visit = [False]*v
        dis = [-1]*v
        count = dfs(l[i][0])
        if count == -1:
            print(-1)
            exit()
        else:
            ans = max(ans,count)
        done.append(l[i][0])
    print(ans)
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(10**7)
    input = sys.stdin.readline
    n = int(input())
    l = [list(map(int,input().split())) for i in range(n)]
    ans = 1
    count = [0]*n
    check = set()
    game = []
    for i in range(n):
        if count[i] >= n-1 or i in check:
            continue
        ind = l[i][count[i]]-1
        if ind in check:
            continue
        if l[ind].index(i+1) == count[ind]:
            check |= set([i,ind])
            game.append([i,ind])
            count[i] += 1
            count[ind] += 1
    while True:
        gamepre = game
        check = set()
        game = []
        for i,j in gamepre:
            ci = True
            cj = True
            if count[i] >= n-1 or i in check:
                ci = False
            if count[j] >= n-1 or j in check:
                cj = False
            if ci:
                ci = True
                ind = l[i][count[i]]-1
                if ind in check:
                    ci = False
                if ci and l[ind].index(i+1) == count[ind]:
                    check |= set([i,ind])
                    game.append([i,ind])
                    count[i] += 1
                    count[ind] += 1
            if cj:
                cj = True
                ind = l[j][count[j]]-1
                if ind in check:
                    cj = False
                if cj and l[ind].index(j+1) == count[ind]:
                    check |= set([j,ind])
                    game.append([j,ind])
                    count[j] += 1
                    count[ind] += 1
        if not check:
            if sum(count) != n*(n-1):
                print(-1)
                exit()
            else:
                print(ans)
                exit()
        ans += 1
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n=int(input())
h=list(map(int,input().split()))
li=[0]
for i in range(n-1):
  if not(h[i]<h[i+1]) and (i==0 or h[i-1]<h[i]):
    k=0
    while i+k<n-1 and not(h[i+k]<h[i+k+1]):
      k+=1
    li=li+[k]
  if sum(li)>n/2:
    break
print(max(li))

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
li=[0]
while len(h)>1:
  for i in range(len(h)):
    if i==len(h)-1:
      li += [len(h)-1]
      del h[1:]
    elif h[i]<h[i+1]:
      li += [len(h[0:i+1])-1]
      del h[0:i+1]
      break
print(max(li))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        total+=((L[i]%mod)*(L[j]%mod))%mod
print(total%mod)





### FIXED CODE ###

import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
hb = sum(L)
val = 0
for i in range(n-1):
    val +=L[i]
    total += L[i]*(hb-val)
print(total%mod)
### BUGGY CODE ###

# 2019/08/11

from fractions import gcd

n,m=map(int,input().split())
s=input()
t=input()
lcd=(n*m)//gcd(n,m)
x=['' for _ in range(lcd)]
aa=(lcd//n)
bb=(lcd//m)
for i in range(max(n,m)):
    if i<n:
        a=i*aa
        if x[a]==s[i] or x[a]=='':
            x[a]=s[i]
        else:
            print(-1)
            exit()
    if i<m:
        b=i*bb
        if x[b]==t[i] or x[b]=='':
            x[b]=t[i]
        else:
            print(-1)
            exit()
        
print(lcd)


### FIXED CODE ###

# 2019/08/11

from fractions import gcd

n,m=map(int,input().split())
s=input()
t=input()
lcd=(n*m)//gcd(n,m)
x={}
aa=(lcd//n)
bb=(lcd//m)
for i in range(n):
    a=i*aa
    x[a]=s[i]

for i in range(m):
    b=i*bb
    if b in x and x[b]!=t[i]:
        print(-1)
        exit()
    
print(lcd)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = ["Yes"]*(n-k)
s = []

for i in range(n-k+1):
  m = 1
  for j in range(k):
    m *= a[j]
  s.append(m)
  a.pop(0)

for i in range(n-k):
  if s[i] >= s[i+1]:
    ans[i] = "No"

for i in range(len(ans)):
    print(ans[i])


### FIXED CODE ###

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

for i in range(n-k):
  if a[i] < a[i + k]:
      print("Yes")
  else:
      print("No")
### BUGGY CODE ###

A = input()

S = [0]
dic = {0:1}

for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))
    sm = S[-1] % 2019
    S.pop(0)
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for num in dic:
    n = dic[num]
    result += (n*(n-1)/2)


print(int(result))


### FIXED CODE ###

S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)
### BUGGY CODE ###

#https://atcoder.jp/contests/abc125/tasks/abc125_c

import math

N = int(input())
A = [int(i) for i in input().split()]

i=2
b=[1]#a=0
c=[1]
#d=[]
while True:
    a = 0
    for j in range(N):
        if A[j] % i != 0:
            a += 1
        #print(i,A[j],a)
        if a > 1:
            break

    if a == 0:
        b.append(i) #white list
        for j in range(len(A)):
            A[j] = int(A[j] / i)
        i = 2
    if a == 1:
        c.append(i) #gray list
    if a > 0:
        i += 1

    if i > min(A):
        break

bs = 1
for i in range(len(b)):
    bs *= b[i]
print(bs * max(c))

'''
a=[]
for i in range(0,N,2):
    if i == N-1:
        a.append(A[i])
        break
    else:
        a.append(math.gcd(A[i],A[i+1]))
'''

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
arr1 = [0 for _ in range(n)]
arr2 = [0 for _ in range(n)]
arr1[0] = a[0]
arr2[-1] = a[-1]
for i in range(1, n):
    arr1[i] = gcd(arr1[i - 1], a[i])
for i in reversed(range(n - 1)):
    arr2[i] = gcd(arr2[i + 1], a[i])
ans = arr1[-1]
for i in range(n): #delete a[i]
    if 0 < i < n - 1:
        ans = max(ans, gcd(arr1[i - 1], arr2[i + 1]))
    elif i == 0:
        ans = max(ans, arr2[1])
    elif i == n - 1:
        ans = max(ans, arr1[n - 2])
print(ans)
### BUGGY CODE ###

def main():
    K = int(input())
    firstPlace = K % 10

    if firstPlace == 1:
        seed = 7
    elif firstPlace == 3:
        seed = 9
    elif firstPlace == 7:
        seed = 1
    elif firstPlace == 9:
        seed = 3
    else:
        return -1

    while True:
        verifiStr = str(K * seed)
        lenVerifiStr = len(verifiStr)

        if(verifiStr.count("7") == lenVerifiStr):
            return lenVerifiStr           

        seed = seed + 10

if __name__ == "__main__":
    answer = main()
    print(answer)

### FIXED CODE ###

def main():
    K = int(input())

    if K % 2 == 0:
        return -1
    elif K % 5 == 0:
        return -1

    an = 7
    counter = 1

    while True:
        modan = an % K

        if modan == 0:
            return counter

        an = modan * 10 + 7
        counter = counter + 1

if __name__ == "__main__":
    answer = main()
    print(answer)
### BUGGY CODE ###

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

num = 1
for k in range(n):
	num *= a[k]

if num > 10**18:
	print("-1")
else:
	print(num)

### FIXED CODE ###

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

num = 1
if 0 in a:
  num = 0
  
else:
  for k in range(n):
      num *= a[k]
      if num > 10**18:
        num = "-1"
        break

print(num)
### BUGGY CODE ###

s=input()
b=0
m=len(s)
c=0
for i in range(m-1,2,-1):
    a=s[i-2]+s[i-1]+s[i]
    for j in range(i-3,-1,-1):
        # if c==1 and int(s[j])%3!=0:
        #     c=0
        #     continue
        a=str(a)
        a=int(s[j]+a)
        # print(a)
        # c=0
        # if a%3!=0:
        #     continue
        # c=1
        if a%2019==0:
            # print(b)
            b+=1

            if i>=3:
                c=int(s[i-3]+s[i-2]+s[i-1]+s[i])
                if c%2019==0:

                    b+=1
            break
        # print(a)

print(b)


### FIXED CODE ###

s=input()
b=0
m=len(s)
c=[0 for i in range(2019)]
c[0]=c[0]+1
a=""
e=0
f=1
s= ''.join(list(reversed(s)))
for i in s:
    e+=int(i)*f
    g=e%2019
    c[g]+=1
    f*=10
    f%=2019
e = sum(i * (i - 1) // 2 for i in c)
print(e)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))

counter = 1

for i in range(2, len(P) + 1, 1):
    for j in range(i):
        if P[j] < P[i-1]:
            break
    else:
        counter += 1

print(counter)

### FIXED CODE ###

N = int(input())

nums = input().split()
nums = [int(x) for x in nums]

min = None
count = 0

for idx, num in enumerate(nums):
    if idx == 0:
        min = num
        count += 1
        continue

    if min >= num:
        count += 1
        min = num

print(count)
### BUGGY CODE ###

import bisect


def m():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    while M > 0:
        tmp = A[N - 1] = A[N - 1] >> 1
        M -= 1
        i = bisect.bisect_left(A, A[N - 1])
        A.insert(i, tmp)
        A.pop()
    return sum(A)
print(m())


### FIXED CODE ###

import queue


def m():
    N, M = map(int, input().split())
    q = queue.PriorityQueue()
    A = list(map(int, input().split()))
    ans = []
    for a in A:
        q.put(-a)
    while M > 0:
        x = -q.get()
        x = -(x >> 1)
        M -= 1
        q.put(x)
    while not q.empty(): ans.append(q.get())
    return abs(sum(ans))


print(m())
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.insert(0, 0)
    b.insert(0, 0)
    ans = 0
    at = 0
    for i in range(n+1):
        at += a[i]
        bt = at
        for j in range(m+1):
            if bt + b[j] > k:
                break
            bt += b[j]
            if ans < i+j:
                ans = i+j
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

INF = 10**11


def main(input, print):
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    at = [0] * (n+1)
    bt = [0] * (m+1)
    for i in range(1, n+1):
        at[i] = at[i-1]+a[i-1]
    for i in range(1, m+1):
        bt[i] = bt[i-1]+b[i-1]

    ans = 0
    j = m
    for i in range(n+1):
        if at[i] > k:
            break
        while k < at[i] + bt[j]:
            j -= 1
        ans = max(ans, i+j)

    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)