Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    if len(set(s))!=len(set(c)) or N>max(set(s)):
        print(-1)
        exit()
    a=[0]*N
    for i in range(len(s)):
        a[s[i]-1]=c[i]
    print("".join(map(str,a)))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    sc=[]
    for i in range(M):
        sc.append([s[i],c[i]])
    sc=list(map(list,set(map(tuple,sc))))
    sc.sort()
    for i in range(len(sc)):
        if sc[i][0]==1 and sc[i][1]==0 and not N==1:
            print(-1)
            exit()
    if M==0 and N==1:
        print(0)
        exit()
    if M==0 or len(sc)==1 and c[0]==0 and not s[0]==1:
        q=[1]
        for i in range(N-1):
            q.append(0)
        print("".join(map(str,q)))
        exit()
    for i in range(len(sc)-1):
        if sc[i][0]==sc[i+1][0]:
            print(-1)
            exit()
    #if N>max(set(s)):
    #    print(-1)
    #    exit()
    a=[0]*N
    for i in range(len(s)):
        a[s[i]-1]=c[i]
    if a[0]==0 and not N==1:
        a[0]=1
    print("".join(map(str,a)))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()
h,w = [int(i) for i in input().split()]

s = [['#']*(w+2)] + [['#']+list(input())+['#'] for _ in range(h)] + [['#']*(w+2)]
#print(s)

cost = [[-1 if s[y][x] == '#' else float('inf') for x in range(w+2)] for y in range(h+2)]
cost[1][1] = 0
#print(cost)

def list_flatten(nested_list):
  flat_list = []
  fringe = [nested_list]
  
  while len(fringe) > 0:
    node = fringe.pop(0)
    if isinstance(node, list):
      fringe = node + fringe
    else:
      flat_list.append(node)

  return(flat_list)
      
def move(y,x):
  if cost[y+1][x] != -1:
    if cost[y+1][x] > cost[y][x]+1:
      cost[y+1][x] = cost[y][x]+1
      move(y+1,x)
  
  if cost[y][x+1] != -1:
    if cost[y][x+1] > cost[y][x]+1:
      cost[y][x+1] = cost[y][x]+1
      move(y,x+1)
      
  if cost[y-1][x] != -1:
    if cost[y-1][x] > cost[y][x]+1:
      cost[y-1][x] = cost[y][x]+1
      move(y-1,x)
  
  if cost[y][x-1] != -1:
    if cost[y][x-1] > cost[y][x]+1:
      cost[y][x-1] = cost[y][x]+1
      move(y,x-1)
  

move(1,1)

#print(cost)

if cost[h][w] == float('inf'):
  print(-1)
else:
  while_num = list_flatten(s).count('.')
  print(while_num - (cost[h][w]+1))


### FIXED CODE ###

import sys

h,w = [int(i) for i in input().split()]

sys.setrecursionlimit(100000)

s = [['#']*(w+2)] + [['#']+list(input())+['#'] for _ in range(h)] + [['#']*(w+2)]
#print(s)

cost = [[-1 if s[y][x] == '#' else float('inf') for x in range(w+2)] for y in range(h+2)]
cost[1][1] = 0
#print(cost)

def list_flatten(nested_list):
  flat_list = []
  fringe = [nested_list]
  
  while len(fringe) > 0:
    node = fringe.pop(0)
    if isinstance(node, list):
      fringe = node + fringe
    else:
      flat_list.append(node)

  return(flat_list)
      
def move(y,x):
  if cost[y+1][x] != -1:
    if cost[y+1][x] > cost[y][x]+1:
      cost[y+1][x] = cost[y][x]+1
      move(y+1,x)
      
  if cost[y-1][x] != -1:
    if cost[y-1][x] > cost[y][x]+1:
      cost[y-1][x] = cost[y][x]+1
      move(y-1,x)
  
  if cost[y][x+1] != -1:
    if cost[y][x+1] > cost[y][x]+1:
      cost[y][x+1] = cost[y][x]+1
      move(y,x+1)
  
  if cost[y][x-1] != -1:
    if cost[y][x-1] > cost[y][x]+1:
      cost[y][x-1] = cost[y][x]+1
      move(y,x-1)
  

move(1,1)

#print(cost)

if cost[h][w] == float('inf'):
  print(-1)
else:
  while_num = list_flatten(s).count('.')
  print(while_num - (cost[h][w]+1))
#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
def tasitekesu(data,n):#dataの中で足したらnになるやつを消し、消した結果とペア数を報告する
    result=[]
    kosu=0
    for i in range(len(data)):
        if i in result:
            continue
        for j in range(i):
            if j in result:
                continue
            if data[i]+data[j]==n:
                result.append(i)
                result.append(j)
                kosu=kosu+1
                break
    result.sort(reverse=True)
    for i in result:
        del data[i]
    return [data,kosu]

N=int(input())
A=input().split()
ans=0
for i in range(N):
    A[i]=int(A[i])
for i in (reversed(beki)):
    R=tasitekesu(A,i)
    A=R[0]
    ans=ans+R[1]
print(ans)

### FIXED CODE ###

#AGC029 A - Irreversible operation
def countB(data):#dataのBの個数kosuとiの総和sumを返す
    sum=0
    kosu=0
    for i in range(len(data)):
        if data[i]=="B":
            kosu=kosu+1
            sum=sum+i
    return[sum,kosu]

text=input()
S=[]
N=len(text)
for i in range(N):
    S.append(text[i])
result=countB(S)
x=result[1]
Ans=int((2*N-x-1)*x/2-result[0])
print(Ans)
N = int(input())
H = list(map(int, input().split()))
 
if N == 1:
    print(0)
    quit()

start = 0
moves = []
for i, (h0, h1) in enumerate(zip(H,H[1:]), start=1):
    moves.append(i - start)
    if H[i] < H[i+1]:
        start = i + 1
print(max(moves))


### FIXED CODE ###

def solve(string):
    n, *h = map(int, string.split())
    ans = count = 0
    for h0, h1 in zip(h, h[1:]):
        if h0 >= h1:
            count += 1
        else:
            ans = max(ans, count)
            count = 0
    return str(max(ans, count))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
import numpy as np
import math
import itertools
import networkx as nx
import matplotlib.pyplot as plt

s = input().split()
a=int(s[0])
s = input().split()
b = int(s[0])
print(6-a-b)

### FIXED CODE ###

s = input().split()
a=int(s[0])
s = input().split()
b = int(s[0])
print(6-a-b)
# import math
# import bisect
#import numpy as np
import itertools
import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    if k > 1:
            for ele in cmb:
                prc = 0
                prev = a[0]
                acp = a.copy()
                for idx in ele:
                    if acp[idx] - prev <= 0:
                        prc += prev - acp[idx] + 1
                        acp[idx] = prev + 1
                    prev = acp[idx]
                cnt = 1
                mh = acp[0]
                for i in range(1, n):
                    if mh < acp[i]:
                        cnt += 1
                        mh = acp[i]
                if cnt >= k:
                    ans = min(ans, prc)
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

# import math
# import bisect
#import numpy as np
import itertools
import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    if k > 1:
            for ele in cmb:
                prc = 0
                prev = a[0]
                acp = copy.copy(a)
                for idx in ele:
                    if acp[idx] - prev <= 0:
                        prc += prev - acp[idx] + 1
                        acp[idx] = prev + 1
                    prev = acp[idx]
                cnt = 1
                mh = acp[0]
                for i in range(1, n):
                    if mh < acp[i]:
                        cnt += 1
                        mh = acp[i]
                if cnt >= k:
                    ans = min(ans, prc)
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()
x=int(input())
y=int(input())
if x<y:
    print(x,y)
else:
    print(y,x)

### FIXED CODE ###

while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    if a>b:
        b,a=a,b
    print(a,b)
import sys
2. 
3.stdin = sys.stdin
4.na = lambda: list(map(int, stdin.readline().split()))
5. 
6.k,s = na()
7.ans = 0
8.for x in range(k+1):
9.    for y in range(k+1):
10.        z = s - (x+y)
11.        if z >= 0 and z <= k:
12.            ans += 1
13.print(ans)


### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def main():
    sx,sy,tx,ty = na()
    ret = ""
    for i in range(tx-sx):
        ret += "R"
    for i in range(ty-sy):
        ret += "U"
    for i in range(tx-sx):
        ret += "L"
    for i in range(ty-sy):
        ret += "D"
    ret += "L"
    for i in range(ty-sy+1):
        ret += "U"
    for i in range(tx-sx+1):
        ret += "R"
    ret += "D"
    ret += "R"
    for i in range(ty-sy+1): ret += "D"
    for i in range(tx-sx+1): ret += "L"
    ret += "U"
    print(ret)
    pass


if __name__ == "__main__":
    main()
def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

def unite(x, y):
    x = find(x)
    y = find(y)

    if x != y:
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1

def same(x, y):
    return find(x) == find(y)

#初期化
n, m = map(int, input().split())
par = [0]*n
for i in range(n):
    par[i] = i　#まず全ての値を根に置く
rank = [1]*n #深さ
size = [1]*n #根iにおけるグループサイズ

edge = [tuple(map(int, input().split())) for i in range(m)]
edge = edge[::-1]
for i in range(m):
    edge[i] = (edge[i][0]-1, edge[i][1]-1)

res = []
for i in range(m):
    fi = find(edge[i][0])
    se = find(edge[i][1])
    if fi == se:
        res.append(0)
    else:
        rs.append(size[fi]*size[se])
        unite(fi, se)
ass = 0
for i in range(m):
    ass += res[m-1-i]
    print(ass)


### FIXED CODE ###

def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

def unite(x, y):
    x = find(x)
    y = find(y)

    if x != y:
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1

def same(x, y):
    return find(x) == find(y)

#初期化
n, m = map(int, input().split())
par = [0]*n
for i in range(n):
    par[i] = i #まず全ての値を根に置く
rank = [1]*n #深さ
size = [1]*n #根iにおけるグループサイズ

edge = [tuple(map(int, input().split())) for i in range(m)]
edge = edge[::-1]
for i in range(m):
    edge[i] = (edge[i][0]-1, edge[i][1]-1)

res = []
for i in range(m):
    fi = find(edge[i][0])
    se = find(edge[i][1])
    if fi == se:
        res.append(0)
    else:
        res.append(size[fi]*size[se])
        unite(fi, se)
ass = 0
for i in range(m):
    ass += res[m-1-i]
    print(ass)
import itertools

n,k=map(int,input().split())
s=map(int,input().split())

t=[]

for a,b in itertools.combinations(s,2):
  t.append(a*b)

t.sort()

print(t[k-1])


### FIXED CODE ###

a,b,c = map(int,input().split())

n=set([a,b,c])

if len(n)==2:
  print("Yes")
else:
  print("No")
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N = int(input())
    S = input()
    cnt0 = S.count("1")

    if cnt0 == 0:
        print(*[1]*N, sep="\n")
        raise 1
        return

    X = int(S, 2)

    def f2():
        cache = [-1] * max(9, cnt0+1)
        cache[0] = 0
        for i in range(4): cache[1<<i] = 1
        def f2(x):
            if cache[x] != -1:
                return cache[x]

            y = bin(x).count("1")
            z = 1 + f2(x % y)
            cache[x] = z

            return z
        f2.cache = cache
        return f2
    f2 = f2()

    dc = []
    for v in [1, -1]:
        x = cnt0 + v
        y = X % x if x else 0
        dc.append((x, v, y, [1, N-1]))

    ans = [0] * N
    for i in reversed(range(N)):
        cnt, v, n, m1 = dc[0 if S[i] == "0" else 1]

        if cnt == 0:
            ans[i] = 0
            continue

        m2 = (m1[0]<<(m1[1]-i)) % cnt
        n = (n + v*m2) % cnt
        m1[0], m1[1] =  m2, i

        ans[i] = 1 + f2(n)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from functools import lru_cache


@lru_cache(maxsize=2*10**5)
def f2(x):
    if x == 0: return 0
    y = bin(x).count("1")
    return 1 + f2(x % y)

def resolve():
    N = int(input())
    W = 16
    S = input()
    cnt0 = S.count("1")

    if cnt0 == 0:
        print(*[1]*N, sep="\n")
        return

    X = int(S, 2)

    dc = {}
    for k, v in (("0", 1), ("1", -1)):
        x = cnt0 + v
        y = X % x if x else 0
        dc[k] = (x, v, y)

    ans = []
    for i, si in enumerate(S):
        cnt, v, n = dc[si]

        if cnt == 0:
            ans.append(0)
            continue

        ni = N - i - 1
        n = (n + v * pow(2, ni, cnt)) % cnt

        ans.append(1+f2(n))

    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()
first = []
second = []
for _ in range(M):
  a, b = map(int, input().split())
  if a == 1:
  	first.append(b)
  elif b == N:
    second.append(a)

ans = 0
for i in first:
  if i in second:
    ans = 1
    break
if ans:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

### FIXED CODE ###

N, M = map(int, input().split())
first = set()
second = set()
for _ in range(M):
  a, b = map(int, input().split())
  if a == 1:
    first.add(b)
  elif b == N:
    second.add(a)

ans = 0
for i in first:
  if i in second:
    ans = 1
    break
if ans:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
a=input()
s=input()
if a>=3200:
    print(s)
else:
    print("red")

### FIXED CODE ###

a=int(input())
s=str(input())
if a>=3200:
    print(s)
else:
    print("red")
import math
from functools import reduce
a,b=input().split()
l=sorted([int(x)-int(b) for x in input().split()])
print(abs(reduce(math.gcd, l)))



### FIXED CODE ###


import math
from functools import reduce
a,b=input().split()
l=sorted([abs(int(x)-int(b)) for x in input().split()])

def gcd(a,b):
    if a < b:
        a,b = b,a
    if  b==0:
        return a
    c = a % b
    return gcd(b,c)
while len(l)!=1:
    l.append(gcd(l.pop(0),l.pop(-1)))
print(sum(l))
r=int(input())
s=list(input())
t=int(input())
i=0
for i in range(r):
    if s[i]!=s[t]:
        s[i]=s[t]
          
print(s)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
for i in range(N):
  if S[i] != S[K-1]:
    S = S.replace(S[i],'*')
print(S)
import sys
sys.setrecursionlimit(500000)

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
vs = n * (n - 1) // 2

vmap = {}
c = 0
for i in range(n):
    for j in range(i):
        vmap[(i, j)] = c
        vmap[(j, i)] = c
        c += 1

edges = [[] for _ in range(vs)]
numin = [0] * vs
for i in range(n):
    for j in range(n - 2):
        j1 = a[i][j] - 1
	j2 = a[i][j + 1] - 1
	edges[vmap[(i, j1)]].append(vmap[(i, j2)])
	numin[vmap[(i, j2)]] += 1

order = []
day = [1] * vs
q = [i for i in range(vs) if numin[i] == 0]
while len(q) > 0:
    index = q.pop(0)
    order.append(index)
    d = day[index]
    for i in edges[index]:
	numin[i] -= 1
	if numin[i] == 0:
            q.append(i)
            day[i] = max(day[i], d + 1)

print(max(day) if len(order) == vs else -1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
vs = n * (n - 1) // 2

vmap = {}
c = 0
for i in range(n):
    for j in range(i):
        vmap[(i, j)] = c
        vmap[(j, i)] = c
        c += 1

edges = [[] for _ in range(vs)]
numin = [0] * vs
for i in range(n):
    for j in range(n - 2):
        j1 = a[i][j] - 1
        j2 = a[i][j + 1] - 1
        edges[vmap[(i, j1)]].append(vmap[(i, j2)])
        numin[vmap[(i, j2)]] += 1

order = []
day = [1] * vs
q = [i for i in range(vs) if numin[i] == 0]
while len(q) > 0:
    index = q.pop(0)
    order.append(index)
    d = day[index]
    for i in edges[index]:
        numin[i] -= 1
        if numin[i] == 0:
            q.append(i)
            day[i] = max(day[i], d + 1)

print(max(day) if len(order) == vs else -1)
import os
import sys

for i,n in enumerate(int(sys.stdin.readlines())):
    if n!=0:
        print "Case %d: %d" % (i, n)

### FIXED CODE ###

import sys

i = 1

while(1):
    a = raw_input()
    if('0'==a):
        break
    else:
        print "Case %d: %s" % (i, a)
        i += 1
'''input
5
2 5 2
2 3 10
1 3 8
3 4 2
'''

N = int(input())

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

for i in range(N-1):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	edges[a].append((b, w))
	edges[b].append((a, w))


color = [None]*N

color[0] = 0

def dfs(curr, prev):
	
	for i in edges[curr]:
		if i[0] == prev: continue

		color[i[0]] = color[curr] if i[1] % 2 == 0 else 1 - color[curr]
		dfs(i[0], curr)

dfs(0, -1)

for i in color:
	print(i)

### FIXED CODE ###

'''input
3
1 2 2
2 3 1
'''
import sys
sys.setrecursionlimit(100100)
N = int(input())

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

for i in range(N-1):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	edges[a].append((b, w))
	edges[b].append((a, w))


color = [None]*N

color[0] = 0

def dfs(curr, prev):
	for i in edges[curr]:
		if i[0] == prev: continue

		if i[1] % 2 == 0: color[i[0]] = color[curr]
		else: color[i[0]] = 1 - color[curr]

		dfs(i[0], curr)

dfs(0, -1)

for i in color:
	print(i)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)
S = input()
if S ='ABC':
 print('ARC')
else:
 print('ABC')

### FIXED CODE ###

s=input()
print("ABC" if s=="ARC" else "ARC")
s = input()

if set(s) == {'h', 'i'}:
    print("Yes")
else:z
    print("No")

### FIXED CODE ###

s = input()
if s == "hi" *(len(s)//2):
    print("Yes")
else:
    print("No")
import math
A, B, C, D = (int(x) for x in input().split())
x = (B // C) - (A // C)
x += (B // D) - (A // D)
lcm = (C * D) // math.gcd(C, D)
x -= (B // lcm) - (A // lcm)
print((B - A + 1) - x)

### FIXED CODE ###

import fractions
A, B, C, D = (int(x) for x in input().split())
x = (B // C) - ((A - 1) // C)
x += (B // D) - ((A - 1) // D)
lcm = (C * D) // fractions.gcd(C, D)
x -= (B // lcm) - ((A - 1) // lcm)
print((B - A + 1) - x)
N, M, K = map(int, input().split())

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
num_books = 0
allot_to_A = 0
allot_to_B = K
time_bankB = allot_to_B
read_in_B = []
baf_timeB = 0

for i in range(len(time_B)):
    if time_B[i] <= time_bankB:
        time_bankB -= time_B[i]
        num_books += 1
        read_in_B.append(time_B[i])
    else:
        baf_timeB = time_bankB
if baf_timeB == 0:
    baf_timeB = K - sum(time_B)

max_books = num_books
tmp = max_books


for i in range(len(time_A)):
    tmp = max_books
    dif = 1
    allot_to_A += time_A[i]
    allot_to_B -= time_A[i]
    if allot_to_B < 0:
        break
    time_to_reduce = time_A[i]
    while time_to_reduce > 0:
        if time_to_reduce <= baf_timeB:
            baf_timeB -= time_to_reduce
            break
        else:
            baf_timeB += read_in_B[-1]
            dif -= 1
            del read_in_B[-1]
    tmp += dif
    max_books = max(tmp, max_books)

print(max_books)


### FIXED CODE ###

N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)
for i in range(1,10):
??for j in range(1,10):
????print "%dx%d=%d"%(i,j,i*j)

### FIXED CODE ###

for i in range(1,10):
    for j in range(1,10):
       print("{0}x{1}={2}".format(i,j,i*j))
n = int(input())
a = list(map(int, input().split()))
while len(a) > 0:
  m = min(a)
  a = [a[i]%m for i in range(n) if a[i]%m > 0]
print(m)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
while len(a) > 1:
  m = min(a)
  a = [a[i]%m for i in range(len(a)) if a[i]%m > 0]
  a.append(m)
print(m)
n,a,b=map(int,input().split())
s=["b"]*a+["r"]*b 
rupu= n//len(s)
amari=n%len(s)
if amari>a :
    print(rupu*a+a)
else:
    print(rupu*a+amari)

### FIXED CODE ###

n,a,b=map(int,input().split())
rupu= n//(a+b)
amari=n%(a+b)
if amari>a :
    print(rupu*a+a)
else:
    print(rupu*a+amari)
mat = [[map(int,input().split())] for i in range(3)]
mat = mat[0]+mat[1]+mat[2]

n = int(input())
for _ in range(n):
  m = int(input())
  for i in range(9):
    if mat[i] == m:
      mat[i] = 1000

if sum(mat[:3])>=3000:
  print("Yes")
elif sum(mat[3:6])>=3000:
  print("Yes")
elif sum(mat[6:])>=3000:
  print("Yes")
elif sum(mat[::3])>=3000:
  print("Yes")
elif sum(mat[1::3])>=3000:
  print("Yes")
elif sum(mat[2::3])>=3000:
  print("Yes")
elif sum(mat[::4])>=3000:
  print("Yes")
elif sum(mat[2:7:2])>=3000:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

mat = [list(map(int,input().split())) for i in range(3)]
mat = mat[0]+mat[1]+mat[2]

n = int(input())
for _ in range(n):
  m = int(input())
  for i in range(9):
    if mat[i] == m:
      mat[i] = 1000

if sum(mat[:3])>=3000:
  print("Yes")
elif sum(mat[3:6])>=3000:
  print("Yes")
elif sum(mat[6:])>=3000:
  print("Yes")
elif sum(mat[::3])>=3000:
  print("Yes")
elif sum(mat[1::3])>=3000:
  print("Yes")
elif sum(mat[2::3])>=3000:
  print("Yes")
elif sum(mat[::4])>=3000:
  print("Yes")
elif sum(mat[2:7:2])>=3000:
  print("Yes")
else:
  print("No")
n,k=map(int,input().split())
count=0
while m!=0:
    int(m) = n/k
    n=m
    count += 1
print(count)

### FIXED CODE ###

n,k=map(int,input().split())
count=0
while n !=0:
    n //= k
    count += 1
print(count)