Harryxun/stf_run huggingface dataset:
import sys

ar = []
x = sys.stdin.readline()
x = x.split(' ')
(n,m)=[int(str) for str in x]

ret = 0
chk = []
for i in range(m):
  x = sys.stdin.readline()
  x = x.split(' ')
  (s,c)=[int(str) for str in x]
  if not ( s in chk):
    if(n-s>=0):
      ret += c*10**(n-s)
      chk.append(s)
  else:
      if( c != int(ret/10**(n-s))):
        print("-1")
        exit(0)

if( ret == 0 and n == 1):
  print("0")
  exit(0)
if( ret < 10**(n-1)):
  if not ( n-1 in chk):
    print(ret+10**(n-1))
  else:
    print("-1")
else:
  print(ret)
sys.stdout.flush()


### FIXED CODE ###

import sys

x = sys.stdin.readline()
x = int((int(x)+1)/2)
print(x)

sys.stdout.flush()
x=input()
if x.isupper() is True:
    print(A)
else:
    print(a)


### FIXED CODE ###

x=input()

if x.isupper() is True:
    print("A")
else:
    print("a")
#n = int(input())
a = list(map(int,input().split()))

a.sort()

if a[0]+a[1]==a[2]:
    print("Yes")
elif:
    print("No")

### FIXED CODE ###

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

a.sort()

if a[0]+a[1]==a[2]:
    print("Yes")
else:
    print("No")
print("YNEOS"[1-input()in'357'::2])

### FIXED CODE ###

print("YNEOS"[input()not in'357'::2])
a = int(input())
b = int(input())
X = b - a 
s = (X*(X+1))/2 - b
print(s)

### FIXED CODE ###

N = int(input())
if N > 999:
    print('ABD')
elif N <= 999:
    print('ABC')
class Fibonacci(object):
    memo = [1, 1]
    def __init__(self):
        pass

    def get_nth(self, n):
        if n <= len(Fibonacci.memo):
            return Fibonacci.memo[n]
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
        return Fibonacci.memo[n]


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())

    # ?????£??????????????°????¨????
    f = Fibonacci()
    result = f.get_nth(num)

    # ???????????????
    print('{0}'.format(result))

### FIXED CODE ###

from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    """ http://docs.python.jp/3/library/functools.html """
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)


class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n < len(Fibonacci.memo):
            return Fibonacci.memo[n]
        # print('fib({0}) not found'.format(n))
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            # print('fib({0})={1} append'.format(i, result))
        return Fibonacci.memo[n]


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())

    # ?????£??????????????°????¨????
    # f = Fibonacci()
    # result = f.get_nth(num)
    result = fib(num+1)

    # ???????????????
    print('{0}'.format(result))
def gcd(x,y):
     if x%y==0:
             return y
     else:
             return gcd(y, x%y)

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(abs(x[i]-x[i+1]))
temp=abs(min(x))
li.append(temp)
try:
    x.remove(temp)
except:
    x.remove(-temp)
temp=abs(min(x))
li.append(temp)



if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)


### FIXED CODE ###

def gcd(x,y):
     if x%y==0:
             return y
     else:
             return gcd(y, x%y)

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(max(abs(x[i]-x[i+1]), (abs(x[i+1]-x[i]))))
temp=abs(min(x))
li.append(temp)


if f:
    a=li[0]
    for i in range(len(li)-1):
        a=gcd(a, li[i+1])
    print(a)
A , B , C , D = map(int,input().split())
lst = []
list= [i for i in range(A,B) i % C != 0]
for i in list:
    if  i % D != 0:
        lst.append(i)
print(len(lst))


### FIXED CODE ###

N = list(map(int,input()))
bool = 0
for i in range(len(N) - 1):
    if N[i] != N[i+1]:
        bool = 1
    else:
        print("Bad")
        exit()
if bool == 1:
    print("Good")
M = (10**9+7)
s = list(input())[::-1]

mo = []
fixed = 0
for i in range(len(s)):
  if s[i]!='?':
    t = int(s[i])
    fixed += (t*pow(10,i,13))%13
  else:
    t = []
    for j in range(10):
      t.append((j*pow(10,i,13)%13))
    mo.append(tuple(t))
    
dp = [[-1]*13 for _ in range(len(mo))]

for m in mo[0]:
  dp[0][m] = 1
for i in range(len(mo)-1):
  for j in range(13):
    if dp[i][j]==-1:
      continue
    for m in mo[i+1]:
      p = (j-m)%13
      if dp[i+1][p] == -1:
        dp[i+1][p] = dp[i][j] % M
      else:
        dp[i+1][p] += dp[i][j] 
ans = dp[-1][(18-fixed)%13] % M 
print(ans)


  


### FIXED CODE ###

M = (10**9+7)
s = list(input())[::-1]

mo = []
fixed = 0
for i in range(len(s)):
  if s[i]!='?':
    t = int(s[i])
    fixed += (t*pow(10,i,13))
    fixed %= 13
  else:
    t = []
    for j in range(10):
      t.append((j*pow(10,i,13)%13))
    mo.append(tuple(t))

if len(mo)==0:
  if fixed == 5:
    print(1)
  else:
    print(0)
  exit()
  
dp = [[-1]*13 for _ in range(len(mo))]

for m in mo[0]:
  dp[0][m] = 1
for i in range(len(mo)-1):
  for j in range(13):
    if dp[i][j]==-1:
      continue
    dp_i = dp[i+1]
    dp_j = dp[i]
    for m in mo[i+1]:
      p = (j+m)%13
      if dp_i[p] == -1:
        dp_i[p] = 0
      dp_i[p] += dp_j[j]
      dp_i[p]  %= M

ans = dp[-1][(18-fixed)%13] % M 
if dp[-1][(18-fixed)%13] == -1:
  print(0)
  exit()
print(ans)
a, b = map(int, input().split())
if (a+b)%2 == 0:
	print((a+b)//2)
else:
  	print(IMPOSSIBLE)

### FIXED CODE ###

a, b = map(int, input().split())
if (a+b)%2 == 0:
	print((a+b)//2)
else:
  	print('IMPOSSIBLE')
square = []
while True:
    data = [int(e) for e in input().split()]
    if data == 0:
        break
    square.append(data)
    
for i in range(len(square)):
    for j in range(square[i][0]):
        for k in range(square[i][1]):
            print("#", end="")
        print()


### FIXED CODE ###

square = []
while True:
    data = [int(e) for e in input().split()]
    if data[0]==0 and data[1]==0:
        break
    square.append(data)
    
for i in range(len(square)):
    for j in range(square[i][0]):
        for k in range(square[i][1]):
            print("#", end="")
        print()
    print()
N=int(input())

R=[[] for i in range(N)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    R[a-1].append([b-1,c])
    R[b-1].append([a-1,c])

Q,K=map(int,input().split())

def dfs(s,g,d):
    chk[s]=1
    for j,c in R[s]:
        if j==g:
            return d+c
        else:
            if chk[j]:
                continue
            else:
                temp=dfs(j,g,d+c)
                if temp!=None:
                    return temp
                else:continue

C=[0]*N
for i in range(N):
    if i==K-1:
        C[i]=0
    else:
        chk = [0] * N
        C[i]=dfs(K-1,i,0)

for i in range(Q):
    x,y=map(int,input().split())
    print(C[x-1]+C[y-1])



### FIXED CODE ###

N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])

Q,K=map(int,input().split())

SD=[0]*N
seen=[0]*N
stack=[]
stack.append([K-1,0])
seen[K-1]=1
while stack:
    x,d=stack.pop()
    for y,d0 in G[x]:
        if seen[y]==0:
            SD[y]=d+d0
            stack.append([y,d+d0])
            seen[y]=1
for i in range(Q):
    x,y=map(int,input().split())
    ans=SD[x-1]+SD[y-1]
    print(ans)
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
dp=[N]*(N+1)
#dp[i];=i個目まで選んで交換したときの最大
C=[B[i]-A[i] for i in range(3)]
for i in range(N):
    dp[i+1]=max(dp[i+1],dp[i])
    for j in range(3):
        if i+1-A[j]>=0:
            dp[i+1]=max(dp[i+1],dp[i+1-A[j]]+C[j])
M=dp[N]
dp=[0]*(M+1)
C=[A[i]-B[i] for i in range(3) if A[i]-B[i]>=0]
for i in range(M):
    dp[i+1]=max(dp[i+1],dp[i])
    for j in range(len(C)):
        if i+1-B[j]>=0:
            dp[i+1]=max(dp[i+1],dp[i+1-B[j]]+C[j])
print(M+dp[M])


### FIXED CODE ###

N,K=map(int,input().split())
if K==1:
    print(0)
else:
    print(N-K)
A,B=map(int,input().split())

a=bin(0)
for i in range(A,B+1):
    i=bin(i)
    a=bin(a^i)
print(a)

### FIXED CODE ###

def xy(a):
    if a % 4 == 1:
        return 1
    elif a % 4 == 2:
        return a + 1
    elif a % 4 == 3 or a == 0:
        return 0
    else:
        return a

a, b = map(int, input().split())
ans = xy(b) ^ xy(a - 1)
print(ans)
from collections import deque
from typing import List, Optional, Tuple


def cycle_detectable_topological_sort(
    graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> Tuple[Optional[List[int]], Optional[List[int]]]:
    """Topological sort that uses Kahn's algorithm and detects a loop (DAG or not).
    Returns:
        if the given graph is DAG, a list of sorted vertices and a list of depths of
        each vertex is returned.
        Otherwise, (None, None) is returned.
    """
    V = len(graph) + first_index
    order = []
    depths = [-1] * V  # depths[i] := the length of the longest path to V_i
    for i in range(first_index, V):
        if not in_degrees[i]:
            order.append(i)
            depths[i] = 0

    queue = deque(order)
    while queue:
        u = queue.popleft()
        cur_depth = depths[u]
        for v in graph[u]:
            in_degrees[v] -= 1
            if not in_degrees[v]:
                depths[v] = max(depths[v], cur_depth + 1)
                queue.append(v), order.append(v)
    return (order, depths) if len(order) + first_index == V else (None, None)


def abc139_e():
    N, *A = map(int, open(0).read().split())

    ids = [[-1] * (N + 1) for _ in range(N + 1)]
    cur_id = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            ids[i][j] = ids[j][i] = cur_id
            cur_id += 1

    graph = [[] for _ in range(N * (N - 1) // 2)]
    in_degrees = [0] * (N * (N - 1) // 2)
    for i, a in enumerate(zip(*[iter(A)] * (N - 1)), 1):
        prev_id = -1
        for j in a:
            cur_id = ids[i][j]
            if prev_id != -1:
                graph[prev_id].append(cur_id)
                in_degrees[cur_id] += 1
            prev_id = cur_id

    _, depths = cycle_detectable_topological_sort(graph, in_degrees, 1)
    print(max(depths) + 1 if depths is not None else -1)


if __name__ == "__main__":
    abc139_e()


### FIXED CODE ###

# ABC139E - League
from collections import deque


def main():
    N, *A = map(int, open(0).read().split())
    B = {}
    for i in range(N):
        x = i * (N - 1)
        B[i + 1] = deque(A[x : x + N - 1])
    ans, cnt, matched = 0, 0, set()
    q = [i for i in range(1, N + 1)]
    while q:
        ans += 1
        next_q = []
        for i in q:
            if i in B and i not in matched:
                x = B[i][0]
                if x in B and x not in matched and B[x][0] == i:
                    B[i].popleft(), B[x].popleft()
                    matched |= {i, x}
                    cnt += 1
                    if not B[i]:
                        del B[i]
                    else:
                        next_q += [i]
                    if not B[x]:
                        del B[x]
                    else:
                        next_q += [x]
        q = next_q
        matched = set()
    flg = cnt == N * (N - 1) // 2
    print(ans if flg else -1)


if __name__ == "__main__":
    main()
import random
print(random.randint() % 2)

### FIXED CODE ###

N = int(input())
A = list(map(lambda a: int(a) - 1, input()))

prd = 1
if all(a % 2 == 0 for a in A):
    prd = 2
    A = [a // 2 for a in A]

ans = 0
for i in range(N):
    if (N - 1) & i == i:
        ans ^= A[i] % 2

print(prd * ans)
n=int(input())
*a,=map(int,input().split())
mod=10**9+7
col=[0]*n
col[0]=3

ans=1

for i in range(n):
    ans*=col[a[i]]
    col[a[i]]-=1
    col[a[i]+1]+=1
    ans%=mod

print(ans%mod)

### FIXED CODE ###

n=int(input())
*a,=map(int,input().split())
mod=10**9+7
col=[0]*(n+1)
col[0]=3

ans=1

for i in range(n):
    ans*=col[a[i]]
    col[a[i]]-=1
    col[a[i]+1]+=1
    ans%=mod

print(ans%mod)
arr = input() for i in range(4)
count = 0
sum = 0
for fihun in range(int(arr[0]) + 1):
    for hun in range(int(arr[1]) + 1):
        for fi in range(int(arr[2]) + 1):
            sum = fihun * 500 + hun * 100 + fi * 50
            if sum == int(range[3]):
                count += 1
print(count)


### FIXED CODE ###

arr = [input() for i in range(4)]
count = 0
sum = 0
for fihun in range(int(arr[0]) + 1):
    for hun in range(int(arr[1]) + 1):
        for fi in range(int(arr[2]) + 1):
            sum = fihun * 500 + hun * 100 + fi * 50
            if sum == int(arr[3]):
                count += 1
print(count)
def dfs1(v):
  if len(g[v])==0:
    return 0
  for u in g[v]:
    if checked[u]==0:
      checked[u]=1
      g2[v].append(u)
      dfs1(u)
      g3[v].append(u)
      g3[u].append(v)
      
def dfs2(v):
  if len(g2[v])==0:
    return 0
  for u in g2[v]:
    if checked[u]==0:
      checked[u]=1
      dfs2(u)
      if cnt[u]%2==1:
        ans.append((u,v))
        cnt[u]+=1
      else:
        ans.append((v,u))
        cnt[v]+=1
      
n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
g2=[[] for _ in range(n+1)]
g3=[[] for _ in range(n+1)]
g4=[[] for _ in range(n+1)]
cnt=[0]*(n+1)
ans=[]
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
if m%2==1:
  print(-1)
else:
  checked=[0]*(n+1)
  checked[1]=1
  dfs1(1)
  for v in range(1,n+1):
    for u in g[v]:
      if u not in g3[v]:
        g4[v].append(u)
  for v in range(1,n+1):
    for u in g4[v]:
      ans.append((v,u))
      cnt[v]+=1
      g4[v].remove(u)
      g4[u].remove(v)
  checked=[0]*(n+1)
  checked[1]=1
  dfs2(1)
  for v,u in ans:
    print(v,u)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def dfs1(v):
  for u in g[v]:
    if checked[u]==0:
      checked[u]=1
      g2[v].append(u)
      g3[v].append(u)
      g3[u].append(v)
      dfs1(u)
      
def dfs2(v):
  for u in g2[v]:
    if checked[u]==0:
      checked[u]=1
      dfs2(u)
      if cnt[u]%2==1:
        ans.append((u,v))
        cnt[u]+=1
      else:
        ans.append((v,u))
        cnt[v]+=1
      
n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
g2=[[] for _ in range(n+1)]
g3=[[] for _ in range(n+1)]
cnt=[0]*(n+1)
ans=[]
ansset=set()
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
if m%2==1:
  print(-1)
else:
  checked=[0]*(n+1)
  checked[1]=1
  dfs1(1)
  for v in range(1,n+1):
    for u in g[v]:
      if u not in g3[v]:
        if (u,v) not in ansset:
          ans.append((v,u))
          ansset.add((v,u))
          cnt[v]+=1
  checked=[0]*(n+1)
  checked[1]=1
  dfs2(1)
  for v,u in ans:
    print(v,u)
a, b = map(int, input())
print('Yay' if a <= 8 and b <= 8 else ':(')


### FIXED CODE ###

a, b = map(int, input().split())
print('Yay!' if a <= 8 and b <= 8 else ':(')
from itertools import combinations
N = int(input())
names = {}
for _ in range(N):
    S = input()
    if S[0] in 'MARCH':
        if S[0] not in names:
            names[S[0]] = 1
        else:
            names[S[0]] += 1
comb = len(names)
if comb <= 2:
    print(0)
elif comb == 3:
    ret = 1
    for v in names.values():
        ret *= v
    print(ret)
elif comb == 4:
    tmp = 1
    for v in names.values():
        tmp *= v
    ret = 0
    for v in names.values():
        ret += tmp // v
    print(ret)
else:
    ret = 0
    for comb in combinations('MARCH', 3):
        tmp = 1
        for c in comb:
            tmp *= names[c]
        ret += comb
    print(ret)

### FIXED CODE ###

from itertools import combinations
N = int(input())
names = {}
for _ in range(N):
    S = input()
    if S[0] in 'MARCH':
        if S[0] not in names:
            names[S[0]] = 1
        else:
            names[S[0]] += 1
comb = len(names)
if comb <= 2:
    print(0)
elif comb == 3:
    ret = 1
    for v in names.values():
        ret *= v
    print(ret)
elif comb == 4:
    tmp = 1
    for v in names.values():
        tmp *= v
    ret = 0
    for v in names.values():
        ret += tmp // v
    print(ret)
else:
    ret = 0
    for comb in combinations('MARCH', 3):
        tmp = 1
        for c in comb:
            tmp *= names[c]
        ret += tmp
    print(ret)
import math
a,b,c = map(int,input().split())
if a + b + 2*math.squrt(a*b) < c:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b,c=map(int,input().split())
if c-a-b>0 and 4*a*b<(c-a-b)**2:
    print('Yes')
else:
    print("No")
#Colorful Leaderboard
N = int(input())
a = list(map(int, input().split()))
L = [0 for i in range(9)]
for i in range(N):
    L[a[i]//400] = L[a[i]//400] + 1
n = 0
for i in range(8):
    if L[i] > 0:
        n = n + 1
nmin = n
nmax = n + L[8]
if nmax > 9:
    nmax = 9
print(str(nmin)+" "+str(nmax))

### FIXED CODE ###

#Colorful Leaderboard
N = int(input())
a = list(map(int, input().split()))
L = [0 for i in range(8)]
s = 0
for i in range(N):
    if a[i] < 3200:
        L[a[i]//400] = L[a[i]//400] + 1
    else:
        s = s + 1
n = 0
for i in range(8):
    if L[i] > 0:
        n = n + 1
nmin = n
nmax = n + s
if nmin == 0:
    nmin = 1
print(str(nmin)+" "+str(nmax))
y = [int(z) for z in input().split()]
l = [int(z) for z in input().split()]
c = 0
d = 0
i=0
while (d<=y[1]):
      d = d+l[i]
      i+=1
if (i>y[0]+1):
      print(y[0]+1)
else:
      print(i)


### FIXED CODE ###

y = [int(z) for z in input().split()]
l = [int(z) for z in input().split()]
d = [0]*(y[0]+1)
c = 1
for i in range(1,y[0]+1):
      d[i] = d[i-1]+l[i-1]
      if (d[i]<=y[1]):
            c+=1
print(c)
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]

    def dp(i,k):
        if k<=0:
            return 0
        tmp=N-i
        if k>tmp//2+tmp%2:
            return -float('inf')
        return max(A[i]+dp(i+2,k-1),dp(i+1,k))

    print(dp(0,N//2))

main()

### FIXED CODE ###

def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    dp=[[0,0,0] for _ in range(N//2+1)]
    for i in range(N//2):
        dp[i+1][0]=dp[i][0]+A[i*2]
        dp[i+1][1]=max(dp[i][1],dp[i][0])+A[i*2+1]
        if N%2:
            dp[i+1][2]=max(dp[i][2],dp[i][1],dp[i][0])+A[i*2+2]
    if N%2:
        print(max(dp[-1]))
    else:
        print(max(dp[-1][:2]))

main()
import numpy as np
import os

def bcount(C):
    u, counts = np.unique(C, return_counts=True)
    return counts[0]


def main():
    H, W, K = map(int,input().split())
    C = []
    form1 = '0'+str(W)+'b'
    form2 = '0'+str(H)+'b'
    h2 = [str(format(i, form2)).split('b')[0] for i in range(2**H)]
    w2 = [str(format(i, form1)).split('b')[0] for i in range(2**W)]
    default_count = 0
    black_count = 0
    for i in range(H):
        C.append(list(map(str, list(input()))))
        default_count += C[i].count("#")
    print(default_count)
    
    if default_count == K:
        print(1)
        os._exit(1)
    elif default_count < K:
        print(0)
        os._exit(1)
    C = np.array(C,dtype = str)

    for i in range(len(h2)):
        co = np.copy(C)
        tmp = list(h2[i])
        for j in range(len(tmp)):
            if(tmp[j] == '1'):
                co[j,:] = "%"
        if (bcount(co) == K):
            black_count += 1

        for k in range(len(w2)):
            co2 = np.copy(co)
            tmp = list(w2[k])
            for j in range(len(tmp)):
                if(tmp[j] == '1'):
                    co2[:,j] = "%"
            if (bcount(co2) == K):
                black_count += 1

    print(black_count)

if __name__ == "__main__":
    main()

### FIXED CODE ###


import numpy as np

H, W, K = map(int,input().split())
D = np.zeros([H,W])

black_count = 0
for i in range(H):
    C = list(input())
    for j in range(len(C)):
        if(C[j] == "#"):
            D[i][j] = 1


#print(D)
for i in range(2**H):
    h = format(i, '06b')
    for j in range(2**W):
        w = format(j, '06b')
        d = D.copy()

        for hi in range(H):
            if(h[5-hi] == '1'):
                d[hi,:]=0
        for wi in range(W):
            if(w[5-wi] == '1'):
                d[:,wi]=0
            
        if (d.sum() == K):
            black_count += 1

print(black_count)
A,B = int(input())
o = -1
if A >= 10 or B>=10
    print(o)
else:
print(A*B)



### FIXED CODE ###

A,B = map(int,input().split())
o = -1
if A >= 10 or B >= 10:
    print(o)
else:
    print(A*B)
import sys

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ak=[]
aa=0
for i in a:
    aa+=i
    ak.append(aa)
bk=[]
bb=0
for i in b:
    bb+=i
    bk.append(bb)
ass=bs=0
for i in range(len(ak)):
    if ak[i]<=k:
        ass=i+1
    else:
        break
for i in range(len(bk)):
    if bk[i]+ak[ass-1]<=k:
        bs=i+1
    else:
        break
wk=ass+bs
aswk=ass
bswk=bs
if wk==n+m:
    print(n+m)
    sys.exit()

while aswk>1:
    aswk-=1
    while k< ak[aswk-1]+bk[bswk-1]:
        if bswk <=m:
            bswk+=1
        else:
            break
    if bs<=bswk-1:
        bs=bswk
        ass=aswk
    else:
        break        
print(ass+bs)

### FIXED CODE ###

import numpy as np

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

ak=np.cumsum(a,dtype=np.int64)
bk=np.cumsum(b,dtype=np.int64)
ak=ak[ak<=k]
bk=bk[bk<=k]
lak=len(ak)
lbk=len(bk)

an=lak
j=0
for i in range(lak-1,-1,-1):
    while bk[j]+ak[i]<=k:
        an=max(an,i+j+2)
        j+=1
        if j>=lbk:
            j-=1
            break
an=max(an,lbk)

print(an)
s = input()
n = len(s) - 1 #隙間の数

for i in range(2**3):
    tmp = s[0]
    for j in range(n):
        if (i >> j) & 1:
            tmp += "+"

        else:
            tmp += "-"

        tmp += s[j+1]

    list_tmp = [tmp[0], tmp[1:3], tmp[3:5], tmp[5:7]]

    for j in list_tmp:
        res += int(j)

    if res == 7:

        print(tmp + "=7")
        exit()

### FIXED CODE ###

s = input()
n = len(s) - 1 #隙間の数

for i in range(2**3):
    tmp = s[0]
    for j in range(n):
        if (i >> j) & 1:
            tmp += "+"

        else:
            tmp += "-"

        tmp += s[j+1]

    list_tmp = [tmp[0], tmp[1:3], tmp[3:5], tmp[5:7]]

    res = 0
    for j in list_tmp:
        res += int(j)

    if res == 7:

        print(tmp + "=7")
        exit()
N=input()
if any(c=='9'):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N=input()
if '9' in N:
  print("Yes")
else:
  print("No")
A,B = map(int,input().split())
if A = B:
    print(1)
elif B = 1:
    print(0)
else:
    print((B-1)//(A-1)+1)

### FIXED CODE ###

A,B = map(int,input().split())
if round((B-1)%(A-1)) == 0:
  print((B - 1)//(A - 1))
else:
  print((B-1)//(A-1)+1)
s = input()
t = ""
ans = 0
for i in range(len(s)):
    t += s[i]
    #print(t)
    if i+1 = len(s) or i+1+len(t) > len(s):
        ans += 1
        t = ""
    elif s[i+1:i+1+len(t)] != t:
        ans += 1
        t = ""

print(ans)

### FIXED CODE ###

s = input()
t = ""
ans = 0
prev = 2
i = 0
while i < len(s):
    if prev == 2:
        ans += 1
        prev = 1
        i += 1
    elif s[i-1] != s[i]:
        ans += 1
        prev = 1
        i += 1
    elif (i+1) == len(s):
        break
    else:
        ans += 1
        prev = 2
        i += 2
            

print(ans)
# -*- coding: utf-8 -*-
"""
Challenge A
"""

def bus(stations):
    a = np.array(("","",""))
    for i in range(3):
        a[i] = stations[i]
    s = np.unique(a)
    if len(s)==1:
        return "No"
    elif len(s) > 1:
        return "Yes"
    else:
        return "Problem"
        
"""
my_strings = np.array(("AAA","AAB","ABA","BAA","ABB","BBA","BBB"))
for i in my_strings:
    print(i)
    print(bus(i))
"""
    
i = input("give station: ")
print(i)
print(bus(i))


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Challenge A
"""
import numpy as np

def bus(stations):
    a = np.array(("","",""))
    for i in range(3):
        a[i] = stations[i]
    s = np.unique(a)
    if len(s)==1:
        return "No"
    elif len(s) > 1:
        return "Yes"
    else:
        return "Problem"
        
"""
my_strings = np.array(("AAA","AAB","ABA","BAA","ABB","BBA","BBB"))
for i in my_strings:
    print(i)
    print(bus(i))
"""
    
i = input()
#print(i)
print(bus(i))