Harryxun/stf_run huggingface dataset:
def prf(m):
    pf = {}
    for i in range(2,int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i,0)+1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf
def inpl(): return [int(i) for i in input().split()]
mod = 10**9+7
N, M = inpl()
fac = [1 for _ in range(2*N+1)]
for i in range(2*N):
    fac[i+1] = (i+1)*fac[i]%mod

inv = [1 for _ in range(2*N+1)]
for i in range(2,2*N+1):
    inv[i] = (-(mod//i) * inv[mod%i]) %mod    

facinv = [1 for _ in range(2*N+1)]
for i in range(2*N):
    facinv[i+1] = inv[i+1]*facinv[i]%mod

ans = 1
for i in prf(M).values():
    ans = ans*fac[N+i-1]*facinv[i]*facinv[N-1]%mod
print(ans)

### FIXED CODE ###

def prf(m):
    pf = {}
    for i in range(2, int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i, 0)+1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf
def inpl(): return [int(i) for i in input().split()]
def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

mod = 10**9+7
N, M = inpl()

ans = 1
for i in prf(M).values():
    ans = ans*comb(N+i-1, i)%mod
print(ans)
N = int(input())
A = list(map(int, input().split()))
 
ans = [0] * N
for i in range(len(A)):
    ans[A[i]-1] = i + 1
 
  for a in ans:
    print(a, end=' ')

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
 
ans = [0] * N
for i in range(len(A)):
    ans[A[i]-1] = i + 1
 
for a in ans:
    print(a, end=' ')
#
line=(input())
line.split()

a=int(line[0])
b=int(line[2])

p=(a+b)*2
Area=a*b

print(Area,p)



### FIXED CODE ###

a,b=map(int,input().split())
p=(a+b)*2
Area=a*b
print(Area,p)
n=int(input())
l=list(map(int,input().split()))

count=0
for i in l:
  for j in l:
    if i%j==0:
      if i!=j:
        count+=1
        break
      
print(n-count)

### FIXED CODE ###

lis=list(map(int,input().split()))

print(lis.index(0)+1)
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

N,M=input2()
L,R=[],[]
for i in range(M):
	l,r=input2()
	L.append(l)
	R.append(r)

MIN=0
MAX=N

for j in range(M):
	if L[j]>MIN and :
		MIN=L[j]
	if R[j]<MAX:
		MAX=R[j]

if MAX<MIN:
	print(0)
else:
	print((MAX-MIN)+1)

### FIXED CODE ###

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

N,M=input2()
L,R=[],[]
for i in range(M):
	l,r=input2()
	L.append(l)
	R.append(r)

MIN=0
MAX=N

for j in range(M):
	if L[j]>MIN:
		MIN=L[j]
	if R[j]<MAX:
		MAX=R[j]

if MAX<MIN:
	print(0)
else:
	print((MAX-MIN)+1)
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
B = [[0,0,0],[0,0,0],[0,0,0]]

ans = 'No'
for i, row in enumerate(A):
    for j, value in enumerate(row):
        if value in b:
            B[i][j] = 1

if aB[0][0]==B[0][1]==B[0][2]==1 or B[1][0]==B[1][1]==B[1][2]==1 or B[2][0]==B[2][1]==B[2][2]==1:
    ans = 'Yes'
elif B[0][0]==B[1][0]==B[2][0]==1 or B[0][1]==B[1][1]==B[2][1]==1 or B[0][2]==B[1][2]==B[2][2]==1:
    ans = 'Yes'
elif B[0][0]==B[1][1]==B[2][2]==1 or B[2][2]==B[1][1]==B[2][0]==1:
    ans = 'Yes'
print(ans)

### FIXED CODE ###

A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
B = [[0,0,0],[0,0,0],[0,0,0]]

ans = 'No'
for i, row in enumerate(A):
    for j, value in enumerate(row):
        if value in b:
            B[i][j] = 1
#print(B)
if B[0][0]==B[0][1]==B[0][2]==1 or B[1][0]==B[1][1]==B[1][2]==1 or B[2][0]==B[2][1]==B[2][2]==1:
    ans = 'Yes'
elif B[0][0]==B[1][0]==B[2][0]==1 or B[0][1]==B[1][1]==B[2][1]==1 or B[0][2]==B[1][2]==B[2][2]==1:
    ans = 'Yes'
elif B[0][0]==B[1][1]==B[2][2]==1 or B[0][2]==B[1][1]==B[2][0]==1:
    ans = 'Yes'
print(ans)
n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
M=n[1]
def kyoukai(lis,m):
    s=0
    for i in range(n):
        s+=math.log2(lis[i])
        if s>=n[1]*2:
            boundary=i+1
            break
    return boundary
d=kyoukai(a,M)
for i in range(d):
    a[i]=int(a[i]/2)
    if M-d>0:
        M-=d
        d=kyoukai(a,M)
    else:
        break
print(sum(a))
        

### FIXED CODE ###

import heapq

N, M= map(int, input().split())
A = list(map(int, input().split()))
a=[-1*i for i in A]
heapq.heapify(a)
for i in range(M):
    m=int(heapq.heappop(a)/2)
    heapq.heappush(a, m)

print(-1*sum(a))
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  s=list(S())
  t=summarize_list(s)

  if len(s)==1:
    return 'YES'
  if len(s)==2:
    if len(t)==2:
      return 'YES'
    return 'NO'
  if len(t)==2:
    return 'NO'

  t=sorted(t,key=lambda x:x[1])
  # print(t)
  if t[2][1]-t[0][1]>=2:
    return 'NO'
  return 'YES'

# main()
print(main())


### FIXED CODE ###

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  s=list(S())
  t=summarize_list(s)

  if len(s)==1:
    return 'YES'
  if len(s)==2:
    if len(t)==2:
      return 'YES'
    return 'NO'
  if len(t)<=2:
    return 'NO'

  t=sorted(t,key=lambda x:x[1])
  # print(t)
  if t[2][1]-t[0][1]>=2:
    return 'NO'
  return 'YES'

# main()
print(main())
W = input()
ans = 0
count = 0
for i in range(len(W)):
  if W[i] == R:
    count += 1
    ans = max(ans,count)
  else:
    count = 0
print(ans)

### FIXED CODE ###

W = input()
ans = 0
count = 0
for i in range(len(W)):
  if W[i] == "R":
    count += 1
    ans = max(ans,count)
  else:
    count = 0
print(ans)
S = input()
N = len(S)
K = int(input())

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

def rec(i, k, isSmaller):
    if i == N:
        if k == 0:
            return 1
        else:
            return 0
    
    if k == 0:
        return 1
    
    if isSmaller:
        return cmb(N-i, k) * pow(9, k)
    else:
        if S[i] == '0':
            return rec(i+1, k, False)
        else:
            zero = rec(i+1, k, True)
            between = rec(i+1, k-1, True) * (int(S[i]) - 1)
            same = rec(i+1, k-1, False)
            return zero + between + same

print(rec(0, K, False))


### FIXED CODE ###

S = input()
N = len(S)
K = int(input())

MOD = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

# 必要なだけforを回す
for i in range(2, 10 ** 6):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

# nCr n個から重複を許さずr個の組み合わせを選ぶ
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % MOD

def rec(i, k, isSmaller):
    if i == N:
        if k == 0:
            return 1
        else:
            return 0
    
    if k == 0:
        return 1
    
    if isSmaller:
        return cmb(N-i, k) * pow(9, k)
    else:
        if S[i] == '0':
            return rec(i+1, k, False)
        else:
            zero = rec(i+1, k, True)
            between = rec(i+1, k-1, True) * (int(S[i]) - 1)
            same = rec(i+1, k-1, False)
            return zero + between + same

print(rec(0, K, False))
x = input()
if x in 753:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

x = input()
if x in "753":
  print("YES")
else:
  print("NO")
def main():
    LR = open(0).read().split()[2:]
    max_L = max(map(int, LR[::2]))
    min_R = min(map(int, LR[1::2]))
    print(min_R - max_L + 1 if max_L <= min_M else 0)
    return


main()

### FIXED CODE ###

def main():
    LRm = open(0).read().split()[2:]
    max_L = max(map(int, LRm[::2]))
    min_M = min(map(int, LRm[1::2]))
    print(min_M - max_L + 1 if max_L <= min_M else 0)
    return


main()
s = raw_input()
k = input()

def solve(s, k, i):
    if i >= len(s):
        # print "over"
        return s
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= (ord("z") - ord("a")+1)
        s = s[:i] + chr(t)
        # print s, k
    elif ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    return solve(s,k,i+1)
    
print solve(s,k,0)

### FIXED CODE ###

s = raw_input()
k = input()
i = 0
while True:
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= ord("a")
            t %= (ord("z")-ord("a") + 1)
            t += ord("a")
        s = s[:i] + chr(t)
        print s
        exit()
        # print s, k
    elif s[i] != "a" and ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    i += 1
s=input(),u=input()
a,b=map(int,input().split())
u=input()
print(a-1 b if s==u else a b-1)


### FIXED CODE ###

s,t=input().split()
a,b=map(int,input().split())
u=input()
print(a-1, b) if u==s else print(a, b-1)
import numpy as np
S = np.array(list(map(str, input().rstrip())))
K = int(input())

cnt = 0

for i, s in enumerate(S):
    if s != "1":
        cnt = i+1
        ans = s
        break

if cnt > K:
    print(1)
else:
    print(int(ans))

### FIXED CODE ###

import numpy as np
S = np.array(list(map(str, input().rstrip())))
K = int(input())

cnt = 0
ans = 1

for i, s in enumerate(S):
    if s != "1":
        cnt = i+1
        ans = s
        break

if cnt > K:
    print(1)
else:
    print(int(ans))
def main():
    from sys import stdin
    input = lambda:stdin.readline().rstrip()
    H,W,K = map(int,input().split())
    S = []
    num_strawberry = [0]*W
    for i in range(H):
        line = list(map(lambda  x: True if x=='#' else False,list(input())))
        S.append(line)
        num_strawberry[i] = line.count(True)
    
    segment = 0
    ans = []
    for i in range(H):
        ans.append([0]*W)
    for i in range(H):

        if num_strawberry[i] != 0:
            segment += 1
            cake = S[i]
            ansline = ans[i]
            num_s = 0
            for j in range(W):
                ansline[j] = segment
                if cake[j] and num_s < num_strawberry[i] -1:
                    num_s += 1
                    segment += 1
    
    determined = -1
    for i in range(H):
        if num_strawberry[i] != 0:
            determined = i
            break
    if determined > 0:
        for i in range(determined):
            ans[i] = ans[determined]
    for i in range(determined+1,H):
        if num_strawberry[i] != 0:
            determined = i
        else:
            ans[i] = ans[determined]



    for line in ans:
        print(*line)


        



main()

### FIXED CODE ###

def main():
    from sys import stdin
    input = lambda:stdin.readline().rstrip()
    H,W,K = map(int,input().split())
    S = []
    num_strawberry = [0]*H
    for i in range(H):
        line = list(map(lambda  x: True if x=='#' else False,list(input())))
        S.append(line)
        num_strawberry[i] = line.count(True)
    
    segment = 0
    ans = []
    for i in range(H):
        ans.append([0]*W)
    for i in range(H):

        if num_strawberry[i] != 0:
            segment += 1
            cake = S[i]
            ansline = ans[i]
            num_s = 0
            for j in range(W):
                ansline[j] = segment
                if cake[j] and num_s < num_strawberry[i] -1:
                    num_s += 1
                    segment += 1
    
    determined = -1
    for i in range(H):
        if num_strawberry[i] != 0:
            determined = i
            break
    if determined > 0:
        for i in range(determined):
            ans[i] = ans[determined]
    for i in range(determined+1,H):
        if num_strawberry[i] != 0:
            determined = i
        else:
            ans[i] = ans[determined]



    for line in ans:
        print(*line)


        



main()
import math
import collections
def main():

    N = int(input())
    A = list(map(int, input().split()))
    mod = pow(10, 9) + 7

    def primes(n):
        b = [True] * (n//2)
        for i in range(3, int(n**0.5)+1, 2):
            if b[i//2]:
                b[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1)

        return [2] + [2*i + 1 for i in range(1, n//2) if b]

    def isprime(n):
        if n == 1: return False
        for i in range(2, int(math.sqrt(n))+1):
            if n % i == 0:
                return False
        return True

    A = sorted(list(set(A)))
    N = len(A)

    ps = primes(int(math.sqrt(max(A))))

    d = dict()
    di = collections.defaultdict(dict)
    for i in range(N):
        if isprime(A[i]):
            if A[i] not in d:
                d[A[i]] = 1
            di[i][A[i]] = 1
        else:
            v = A[i]
            for p in ps:
                if p > v: break
                cnt = 0
                while v > 1 and v % p == 0:
                    cnt += 1
                    v //= p
                if p in d:
                    d[p] = max(d[p], cnt)
                else:
                    d[p] = cnt
                di[i][p] = cnt
            if v > 1:
                di[i][v] = 1
                if v not in d:
                    d[v] = 1

    ans = 0
    for i in range(N):
        b = 1
        for p in d:
            if p in di[i]:
                b *= pow(p, d[p]-di[i][p])
            else:
                b *= pow(p, d[p])
            b %= mod
        ans += b
        ans %= mod

    return ans

if __name__ == '__main__':
    print(main())

### FIXED CODE ###

def main():

    N, M = map(int, input().split())
    if N == M:
        return "Yes"
    return "No"

if __name__ == '__main__':
    print(main())
n = int( input())
a = list( map(int(input().split())))
cnt = 0

for i in range ( 1, len(a)-1):
  if (a[i-1]<a[i]<a[i+1]) or (a[i+1]<a[i]<a[i-1]):
    cnt += 1
    
print (cnt)    


### FIXED CODE ###

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

for i in range ( 1, len(a)-1):
  if (a[i-1]<a[i]<a[i+1]) or (a[i+1]<a[i]<a[i-1]):
    cnt += 1
    
print (cnt)
S = list(input())
cnt = 0
i = 0
while True:
    if S[i] != S[i + 1]:
        del S[i:i+2]
        cnt += 1
        i = 0
        continue
    elif i + 2 == len(S):
        print(cnt * 2)
        exit()
    i += 1







### FIXED CODE ###

S = list(input())

zero_S = S.count('0')
one_S = S.count('1')

print(min(zero_S, one_S) * 2)
from math import gcd

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

    m = a[0]
    maxx = a[0]
    for i in range(1, n):
        m = gcd(m, a[i])
        if a[i] > maxx:
            maxx = a[i]

    if k % m == 0 and k <= maxx:
        return "POSSIBLE"
    else:
        return "IMPOSSIBLE"

print(solve())

### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

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

    m = a[0]
    maxx = a[0]
    for i in range(1, n):
        m = gcd(m, a[i])
        if a[i] > maxx:
            maxx = a[i]

    if k % m == 0 and k <= maxx:
        return "POSSIBLE"
    else:
        return "IMPOSSIBLE"

print(solve())
N = int(input())
W = []
W.append(input())
for n in range(N):
  w = input()
  if w[0] != W[-1][-1]:
    print("No")
    break
  elif W.count(w) != 0:
    print("No")
    break
  W.append(w)
else:
  print("Yes")
  

### FIXED CODE ###

N = int(input())
W = []
W.append(input())
for n in range(N-1):
  w = input()
  if w[0] != W[-1][-1]:
    print("No")
    break
  elif W.count(w) != 0:
    print("No")
    break
  W.append(w)
else:
  print("Yes")
x,y,z = map(int(input()))
print(str(z)+" " +str(x)+" "+str(y) )

### FIXED CODE ###

x,y,z = map(int,input().split())
print(str(z)+" " +str(x)+" "+str(y) )
n,y = map(int,input().split())
y //= 1000
a,b,c = 0,0,0

for i in range(n):
    for j in range(n-j):
        if 10*i + 5*j + (n-i-j) == y:
            print(i,j,n-i-j)
            exit()
print('-1 -1 -1')

### FIXED CODE ###

n,y = map(int,input().split())
y //= 1000

for i in range(n+1):
    for j in range(n-i+1):
        if 10*i + 5*j + (n-i-j) == y:
            print(i,j,n-i-j)
            exit()
print('-1 -1 -1')
s = input().split()

for i in s:
    sum += int(i)

print(sum)


### FIXED CODE ###

s = list(input())
ball = 0
for i in s:
    ball = ball + int(i)

print(ball)
A,B,C,D = map(int,input().split())
if A+B = C+D:
  print("Balanced")
elif A+B < C+D:
  print("Right")
else:
  print("Left")


### FIXED CODE ###

A,B,C,D = map(int,input().split())
if (A+B) == (C+D):
  print("Balanced")
elif (A+B) < (C+D):
  print("Right")
else:
  print("Left")
N,M = map(int,input().split())
A = list(map(int,input().split()))

s = sum(A)
A.sort(reverse=True)

for i in range(1,N+1):
    if i == M:
        if (s/(4*M))>A[i]:
            print('No')
        else:
            print('Yes')

### FIXED CODE ###

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

s = sum(A)
A = sorted(A,reverse=True)

for i in range(N):
    if i == M-1:
        if (s/(4*M))>A[i]:
            print('No')
        else:
            print('Yes')
import sys

input = sys.stdin.readline

def main():
    def hash_ini(t):
        h = t[0]
        hash_table[0] = h
        p = 1
        for i in range(1, len(t)+1):
            h = hash_table[i] = (h * base + t[i]) % hash_md
            p = pw[i] = p * base % hash_md

    def hash(s):
        res = 0
        for i, c in enumerate(s[::-1]):
            res = (res + pw[i] * (ord(c) - ord_a)) % hash_md
        return res

    # インデックスがi以上j未満の文字列のハッシュ
    def hash_ij(i, j):
        return (hash_table[j] - hash_table[i] * pw[j - i]) % hash_md

    n = int(input())
    s = input()[:-1]

    # 初期化
    base = 29
    hash_md = pow(3, 19)
    ord_a = ord('a')
    t = [ord(c) - ord_a for c in s]
    hash_table = [0] * (len(t)+1)
    pw = [1] * (len(t)+1)
    hash_ini(t)

    ok = 0
    ng = n // 2 + 1
    while ok + 1 < ng:
        br = False
        w = (ok + ng) // 2
        for i in range(n - 2 * w + 1):
            ptn = hash_ij(i, i + w)
            for j in range(i + w, n - w + 1):
                if hash_ij(j, j + w) == ptn:
                    ok = w
                    br = True
                    break
            if br: break
        else:
            ng = w
    print(ok)

main()


### FIXED CODE ###

# YouTube
def main():
    n = int(input())
    s = input()
    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i, c in enumerate(s):
        for j in range(n):
            if c == s[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
    ans = 0
    for i in range(n):
        for j in range(i+1,n+1):
            tmp=min(dp[i][j],j-i)
            ans=max(tmp,ans)
    print(ans)

main()
queue = deque()
# sy,sx = 0,0
# gy,gx = H-1,W-1
queue = deque([(i, j) for i in range(H) for j in range(W) if field[i][j]])
# for i in range(H):
#     for j in range(W):
#         if field[i][j] == True:
#             queue.append([i,j])
# queue = [[sy,sx]]
flag = False
count = 0
while True:
    count += 1
    nqueue = deque()
    while queue:
        h,w = queue.popleft()
        for i in range(4):
            nh = h + dy[i]
            nw = w + dx[i]
            if (0<=nh<H) and (0<=nw<W):
                if field[nh][nw] == False:
                    field[nh][nw] = True
                    nqueue.append([nh,nw])
    if nqueue:
        queue = copy.copy(nqueue)
    else:
        break
print(count-1)

### FIXED CODE ###

from collections import deque
import copy

def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]


    # スタート地点をqueueに追加
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))

        if nque:
            que = copy.copy(nque)
        else:
            break

    print(count - 1)

if __name__ == '__main__':
    main()
import collections

N = int(input())
A = list(map(int, input().split()))
A = collections.Counter(A)
B = []
C = []
for i in A:
    if A[i] == 1:
        B.append(i)
    else:
        C.append(i)
B = sorted(B)
if len(B) == 0:
    print(0)
    exit()
mb = B[-1]
ok = [True] * (mb+1)

C = sorted(C)
for c in C:
    if not ok[c]:
        continue
    k = 2
    while k*c <= mb:
        ok[k*c] = False
        k += 1

for b in B:
    if not ok[b]:
        continue
    k = 2
    while k*b <= mb:
        ok[k*b] = False
        k += 1

ans = 0
for b in B:
    if ok[b]:
        ans += 1

print(ans)


### FIXED CODE ###

import collections

N = int(input())
A = list(map(int, input().split()))
A = collections.Counter(A)
B = []
C = []
for i in A:
    if A[i] == 1:
        B.append(i)
    else:
        C.append(i)
B = sorted(B)
if len(B) == 0:
    print(0)
    exit()
mb = 1000000
ok = [True] * (mb+1)

if len(C) > 0:
    C = sorted(C)
    for c in C:
        if not ok[c]:
            continue
        k = 2
        while k*c <= mb:
            ok[k*c] = False
            k += 1

for b in B:
    if not ok[b]:
        continue
    k = 2
    while k*b <= mb:
        ok[k*b] = False
        k += 1

ans = 0
for b in B:
    if ok[b]:
        ans += 1

print(ans)
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]

    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()


### FIXED CODE ###

#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    ANS = []
    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()