Problem:


Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Wrong Answer

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

for i in range(1, a + 1):
    while np.any(x[i] == 1):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        
ans = 0
print(x)
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)
        
for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

for i in range(1, a + 1):
    while np.any(x[i] == 1):
        x[i] += 1
        x[i + 1:] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
ans = 0

print(x)
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = (n[0] % 10000) // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    f = n[0] // 10000
    
    if f != 0 and np.any(d == f):
        n[0] = (f + 1) * 10000
    elif f == 0 and a != 0 and np.any(d == a):
        n[0] = f * 10000 + (a + 1) * 1000
    elif f == 0 and a == 0 and b != 0 and np.any(d == b):
        n[0] = f * 10000 + a * 1000 + (b + 1) * 100
    elif f == 0 and a == 0 and b == 0 and c != 0 and np.any(d == c):
        n[0] = f * 10000 + a * 1000 + b * 100 + (c + 1) * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = (n[0] % 10000) // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    f = n[0] // 10000
    
    if f != 0 and np.any(d == f):
        n[0] = (f + 1) * 10000
    elif np.any(d == a):
        n[0] = f * 10000 + (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = f * 10000 + a * 1000 + (b + 1) * 100
    elif np.any(d == c):
        n[0] = f * 10000 + a * 1000 + b * 100 + (c + 1) * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = (n[0] % 10000) // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    f = n[0] // 10000
    
    if np.any(d == f):
        n[0] = (f + 1) * 10000
    elif np.any(d == a):
        n[0] = f * 10000 + (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = f * 10000 + a * 1000 + (b + 1) * 100
    elif np.any(d == c):
        n[0] = f * 10000 + a * 1000 + b * 100 + (c + 1) * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = n[0] // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    
    if np.any(d == a):
        n[0] = (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = a * 1000 + (b + 1) * 100
    elif np.any(d == c):
        n[0] = a * 1000 + b * 100 + (c + 1) * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = n[0] // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    
    if np.any(d == a):
        n[0] += 1000 - (n[0] % 1000)
    elif  np.any(d == b):
        n[0] += 100 - (n[0] % 100)
    elif np.any(d == c):
        n[0] += 10 - (n[0] % 10)
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    if np.any(d == (n[0] // 1000)):
        n[0] += 1000 - (n[0] % 1000)
    elif np.any(d == (n[0] % 1000) // 100):
        n[0] += 100 - (n[0] % 100)
    elif np.any(d == (n[0] % 100) // 10):
        n[0] += 10 - (n[0] % 10)
    elif np.any(d == n[0] % 10):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    if np.any(d == n[0] % 10):
        n[0] += 1
    elif np.any(d == (n[0] % 100) // 10):
        n[0] += 10 - (n[0] % 10)
    elif np.any(d == (n[0] % 1000) // 100):
        n[0] += 100 - (n[0] % 100)
    elif np.any(d == (n[0] // 1000)):
        n[0] += 1000 - (n[0] % 1000)
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    if np.any(d == n[0] % 10):
        n[0] += 1
    elif np.any(d == (n[0] % 100) // 10):
        n[0] += 10
    elif np.any(d == (n[0] % 1000) // 100):
        n[0] += 100
    elif np.any(d == (n[0] // 1000)):
        n[0] += 1000
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    if np.any(d == (n[0] // 1000)):
        n[0] += 1000
    elif np.any(d == (n[0] % 1000) // 100):
        n[0] += 100
    elif np.any(d == (n[0] % 100) // 10):
        n[0] += 10
    elif np.any(d == n[0] % 10):
        n[0] += 1
    else:
        print(n[0])
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))

n = [i for i in str(N)]
L = []
for d in range(10):
    if d not in D:
        L.append(d)

for i in range(len(n)):
    if int(n[i]) not in L:
        for l in L:
            if int(n[i]) < l:
                n[i] = str(l)

print(*n, sep='')

Submission status: Wrong Answer

Solution code:
N, K = tuple(map(int, input().split()))
D = list(map(int, input().split()))
set_D = set(D)
for i in range(N, 10000):
    tmp_set = set([int(c) for c in str(i)])
    if len(set_D.intersection(tmp_set)) > 0:
        continue
    else:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N, K = tuple(map(int, input().split()))
D = list(map(int, input().split()))
set_D = set(D)
for i in range(N, 10001):
    tmp_set = set([int(c) for c in str(i)])
    if len(set_D.intersection(tmp_set)) > 0:
        continue
    else:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=input().split(" ")
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if len(n)==1:
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                try:
                    return n[0]+search_min(n[1:],like)
                except TypeError:
                    return None
            else:
                j=like.index(n[0])
                if j+1<len(like):
                    return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
if search_min(N,like)==None:
    print(search_min(10000,like))
else:
    print(search_min(N,like))

Submission status: Wrong Answer

Solution code:
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=input().split(" ")
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if len(n)==1:
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                try:
                    return n[0]+search_min(n[1:],like)
                except TypeError:
                    return None
            else:
                j=like.index(n[0])
                if j+1<len(like):
                    return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
print(search_min(N,like))

Submission status: Wrong Answer

Solution code:
# O(k + log(n))

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

E = [0] * 20
for i in D:
    j = int(i)
    E[j] = 1
    E[10 + j] = 1

# print(E)

F = [0] * 10
r = 0
for l in range(10):
    # print(l, r)
    while l > r or E[r] == 1:
        r += 1
    F[l] = r-l

# print(F)

ke = 0
while True:
    #print(n)
    sn = str(n)
    for i in range(len(sn)-1-ke, -1, -1):
        #print(i)
        if F[int(sn[i])] != 0:
            n += int(str(F[int(sn[i])]) + "0" * (len(sn)-i-1))
            ke += 1
            break
    if n == int(sn):
        break

print(n)

Submission status: Wrong Answer

Solution code:
# O(k + log(n))

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

E = [0] * 20
for i in D:
    j = int(i)
    E[j] = 1
    E[10 + j] = 1

# print(E)

F = [0] * 10
r = 0
for l in range(10):
    # print(l, r)
    while l > r or E[r] == 1:
        r += 1
    F[l] = r-l

# print(F)

while True:
    #print(n)
    sn = str(n)
    for i in range(len(sn)-1, -1, -1):
        #print(i)
        if F[int(sn[i])] != 0:
            n += int(str(F[int(sn[i])]) + "0" * (len(sn)-i-1))
            break
    if n == int(sn):
        break

print(n)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
D = list(input().split())

while True:
    #print(n)
    sn = str(n)
    for i in range(len(sn)):
        #print(i)
        if sn[i] in D:
            n += 10 ** (len(sn)-i-1)
            break
    if n == int(sn):
        break

print(n)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
D = set(map(int, input().split()))

INF = 10**9
ans = INF
def dfs(price):
    if price > 2*N: return INF

    if not D & set(map(int, list(str(price)))):
        return price

    return dfs(price + 1)

ans = min(ans, dfs(N))
print(ans)

Submission status: Wrong Answer

Solution code:
n, k=map(int, input().split())
d=[ int(i) for i in input().split()]
avl = []
pay=[]
for i in range(10):
  if i not in d:
    avl.append(i)


def dps(s):
  if  len(s)== 4 :
    pay.append(s)
    return
  for i in avl:
    dps(s+str(i))
dps("")

for i in pay:
  if int(i)>=n:
    print(int(i))
    exit()
print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n,k=map(int,input().split())
d=list(input().split())
for _ in range(n,10000):
    string=str(_)
    check=0
    for i in string:
        if i in d:
            check=1
    if check==0:
        print(_)
        break

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split(" "))

D=list(input().split(" "))

for i in range(1,K+1):
	Sum=str(N*i)
	No=True
	for n in D:
		if  n in Sum:
			No=False
			break

	if  No:
		print(N*i)
		break

Submission status: Wrong Answer

Solution code:
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=inp[2:]
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if len(n)==1:
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                return n[0]+search_min(n[1:],like)
            else:
                j=like.index(n[0])
                return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
search_min(N,like)

Submission status: Wrong Answer

Solution code:
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=input().split(" ")
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if n<="9":
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                return n[0]+search_min(n[1:],like)
            else:
                j=like.index(n[0])
                return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
search_min(N,like)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
d = inpl()
d = set(d)
for i in range(n,10001):
    flag = True
    t = i
    while i:
        tmp = i%10
        if tmp in d:
            flag = False
        i //= 10
    if flag:
        print(t)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = {str(x) for x in input().split()}
a = {int(x) for x in range(10)}
l = a - d

for i in range(n,10000+1):
    i2 = str(i)
    for j in range(len(i2))[::-1]:
        if i2[j] in d:
            break
    else:
        print(i2)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))

l = list(range(10))
c = list(filter(lambda x: x not in d, l))

num = list(str(n))
for i in range(len(num)):
	x = int(num[i])
	if x not in c:
		for j in c:
			if j > x:
				num[i] = str(j)
				break

print("".join(num))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))

for i in range(10):
    if i ==0 or not i in D:
        for j in range(10):
            if not j in D:
                for k in range(10):
                    if not k in D:
                        for l in range(10):
                            if not l in D:
                                for m in range(10):
                                    if not m in D:
                                        temp=10000*i+1000*j+100*k+10*l+m
                                        if temp>=N:
                                            print(temp)
                                            exit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))

num=[0,1,2,3,4,5,6,7,8,9]
num0=[0]

for i in range(K):
    num.pop(num.index(D[i]))

num0.extend(num)

for i in num0:
    for j in num:
        for k in num:
            for l in num:
                for m in num:
                    if i*10000+j*1000+k*100+l*10+m>=N:
                        ans=i*10000+j*1000+k*100+l*10+m
                        print(ans)
                        exit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))

num=[0,1,2,3,4,5,6,7,8,9]

for i in range(K):
    num.pop(num.index(D[i]))

L=len(num)

if N==9999:
    if num[0]==0:
        ans=num[1]*10000
    elif 9 in num:
        ans=9999
    else:
        ans=num[0]*11111
    print(ans)
    exit()

for i in num:
    for j in num:
        for k in num:
            for l in num:
                if i*1000+j*100+k*10+l>=N:
                    ans=i*1000+j*100+k*10+l
                    print(ans)
                    exit()

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
d = list(map(str,input().split()))

ans=0
for i in range (n,100000):
  s=str(i)
  pay=True
  for j in range(len(s)):
    if s[j] in d:
      pay = False
      break
    
    if pay:
      ans = i
      break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+10**(q-c-1)
                t=1
                break
    if t==0:
        break
print(n)

Submission status: Wrong Answer

Solution code:
n,k =map(int, input().split())
#d = list(map(int, input().split()))
d = list(input().split())
#print(d)

def check(kakaku, negative_number):
  check_sum = 1
  for i in negative_number:
    if i in str(kakaku):
      check_sum = 0
      break
    else:
      pass
  return check_sum

k = n

while check(k, d) == 0:
  k += n

print(k)

Submission status: Wrong Answer

Solution code:
n,k =map(int, input().split())
#d = list(map(int, input().split()))
d = list(input().split())
#print(d)

def check(kakaku, negative_number):
  check_sum = 1
  for i in negative_number:
    if i in str(kakaku):
      #print(i)
      check_sum = 0
      break
    else:
      pass
  return check_sum

kingaku = n

while check(kingaku, d) == 0:
  kingaku += n

print(kingaku)

Submission status: Wrong Answer

Solution code:
n,k =map(int, input().split())
#d = list(map(int, input().split()))
d = list(input().split())
#print(d)

def check(kakaku, negative_number):
  check_sum = 1
  for i in negative_number:
    if i in str(kakaku):
      check_sum = 0
      break
    else:
      pass
  return check_sum

k = n

while check(k, d) == 0:
  k += n

print(k)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split()) 
li1 = set(map(int,input().split()))
li2 = {1,2,3,4,5,6,7,8,9,0}
nu = list(li1^li2)

i = 1
while True:
    a += i
    aa = list(str(a))
    aa = [int(x) for x in aa]
    if set(aa) == set(nu):
        print(a)
        break

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())

d = [i for i in range(10)]
din = list(map(int,input().split()))

for i in din:
    d.remove(i)

flg = 0

for i in range(n,10001):
    for j in range(len(din)):
        #嫌いな数値が居た場合
        if str(din[j]) in str(i):
            flg=1
            break
    if flg == 0:
        print(i)
        break
    else:
        flg=0

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))

isNotMin = True

temp = N * 1

while isNotMin:
    for i in str(temp):
        if int(i) in D:
            temp += 1
            break
        else:
            print(temp)
            isNotMin = False
            break

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))

allnum = {0,1,2,3,4,5,6,7,8,9}

usenum = allnum - set(D)
usenum = list(usenum)

isMin = False

for i in range(10000):
    temp1 = N + i
    res = N + i
    for j in range(6):
        temp2 = temp1 % 10
        if temp2 in D:
            isMin = False
            break
        else:
            isMin = True
            temp1 = temp1 // 10
            if temp1 == 0:
                break
    if isMin:
        print(res)
        break

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))

allnum = {0,1,2,3,4,5,6,7,8,9}

usenum = allnum - set(D)
usenum = list(usenum)

isMin = False

for i in range(10000):
    temp1 = N + i
    res = N + i
    for j in range(5):
        temp2 = temp1 % 10
        if temp2 in D:
            isMin = False
            break
        else:
            isMin = True
            temp1 = temp1 // 10
            if temp1 == 0:
                break
    if isMin:
        print(res)
        break

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))

allnum = {0,1,2,3,4,5,6,7,8,9}

usenum = allnum - set(D)
usenum = list(usenum)

isMin = False

for i in range(10000):
    temp1 = N + i
    res = N + i
    for j in range(5):
        temp2 = temp1 % 10
        if temp2 in D:
            isMin = False
            break
        else:
            isMin = True
            temp1 = (temp1-temp2)//10
            if temp1 == 0:
                break
    if isMin:
        print(res)
        break

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
array = list(map(int,input().split()))
# N=1000
# K=8
# array = [1,3,4,5,6,7,8,9]

# Farray = [0,1,2,3,4,5,6,7,8,9]
# array = set(Farray)-set(array)
# array = list(map(int,array))
i=0
result=[]

#桁上がり未考慮だった。
# while i<len(str(N)):
#     j=0
#     for j in range(len(array)):
#         if int(str(N)[i]) <= array[j]:
#             result.append(array[j])
#             break
#     i+=1
flag=False
while flag == False :
    print(N)
    for i in range(len(str(N))):
        if int(str(N)[i]) in array:
            break
    else:
        flag=True

    N+=1

print(N-1)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
array = list(map(int,input().split()))
# N=1000
# K=8
# array = [1,3,4,5,6,7,8,9]

Farray = [0,1,2,3,4,5,6,7,8,9]
array = set(Farray)-set(array)
array = list(map(int,array))
i=0
result=[]

while i<len(str(N)):
    j=0
    for j in range(len(array)):
        if int(str(N)[i]) <= array[j]:
            result.append(array[j])
            break
    i+=1
print(*result,sep=(""))
print()

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
array = list(map(int,input().split()))
# N=1000
# K=8
# array = [1,3,4,5,6,7,8,9]

Farray = [0,1,2,3,4,5,6,7,8,9]
array = set(Farray)-set(array)
array = list(map(int,array))
i=0
result=[]

while i<len(str(N)):
    j=0
    for j in range(len(array)):
        if int(str(N)[i]) <= array[j]:
            result.append(array[j])
            break
    i+=1
print(*result,sep=(""))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools,pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()
D = LI()
nums = [str(i) for i in range(0, 10) if i not in D]

"""
使える数字の中で一番低いものから試していく
見つかったら各桁試していく

"""

all_nums = []
for i in range(N, 10000+1):
    # 全数字の列挙
    all_nums.append(i)
answers = []
for num in all_nums:
    if num >= N:
        answers.append(num)
answers.sort()
for ans in answers:
    if all(i in nums for i in str(ans)):
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dislike = [str(i) for i in input().split()]
strn = str(n)

while(n<=10000):
  flag = 1
  for i in range(len(strn)):
    if strn[i] in dislike:
      flag = 0
  if flag == 1:
    print(n)
    break
  else:
    n += 1
    strn = str(n)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]
ans = 10 ** 7


def dfs(n):
    global ans
    if len(n) >= len(str(N)):
        if int(n) >= N:
            return int(n)
        else:
            return 10 ** 7
    output = 10 ** 7
    for l in L:
        output = min(dfs(n + str(l)), output)
    return output


print(dfs(''))

Submission status: Wrong Answer

Solution code:
def main():
    n,k=map(int,input().split())
    a=input()
    for i in range(n,10000):
        bl = 1
        for j in str(i):
            if j in a:
                bl=0
                continue
        if bl:
            return i
print(main())

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=input()
for i in range(n,10001):
    bl = 1
    for j in str(i):
        if j in a:
            bl=0
            continue
    if bl:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))

M = N

while M//10000 != 0 and ( (M//10000 in D) or ((M//1000)%10 in D) and ((M//100)%10 in D) and ((M//10)%10 in D) and (M%10 in D) ):
  M -= 10000

while M//1000 != 0 and ( (M//10000 in D) or ((M//1000)%10 in D) and ((M//100)%10 in D) and ((M//10)%10 in D) and (M%10 in D) ):
  M -= 1000

while M//100 != 0 and ( (M//10000 in D) or ((M//1000)%10 in D) and ((M//100)%10 in D) and ((M//10)%10 in D) and (M%10 in D) ):
  M -= 100

while M//10 != 0 and ( (M//10000 in D) or ((M//1000)%10 in D) and ((M//100)%10 in D) and ((M//10)%10 in D) and (M%10 in D) ):
  M -= 10

while M != 0 and ( (M//10000 in D) or ((M//1000)%10 in D) and ((M//100)%10 in D) and ((M//10)%10 in D) and (M%10 in D) ):
  M -= 1

print(M)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
D=list(map(int,input().split()))
D.extend(list(range(0,10)))
D1 = [x for x in set(D) if D.count(x) < 2]
n_0 = D1[0]*1000
for x in D1:
        if abs(n_0 -N ) >=abs(x*1000-N) :
            n_0= x*1000
n_1=n_0

for y in D1:
    if abs(n_1 -N ) >=abs(n_0+100*y-N) :
        n_1 =n_0+100*y
n_2=n_1
for z in D1:
    if abs(n_2 -N ) >=abs(n_1+10*z-N) :
        n_2 =n_1+10*z
n_3=n_2
for a in D1:
    if abs(n_3 -N ) >=abs(n_2+a-N) :
        n_3 =n_2+a


print(n_3)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
D=list(map(int,input().split()))
D.extend(list(range(1,10)))
D1 = [x for x in set(D) if D.count(x) < 2]
for x in D1:
    if x >= math.floor(N/1000):
        n_0= x*1000
        if abs(n_0 -N ) >=abs(x*1000-N) :
            n_0= x*1000
n_1=n_0

for y in D1:
    if abs(n_1 -N ) >=abs(n_0+100*y-N) :
        n_1 =n_0+100*y
n_2=n_1
for z in D1:
    if abs(n_2 -N ) >=abs(n_1+10*z-N) :
        n_2 =n_1+10*z
n_3=n_2
for a in D1:
    if abs(n_3 -N ) >=abs(n_2+a-N) :
        n_3 =n_2+a


print(n_3)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
D=list(map(int,input().split()))
D.extend(list(range(0,10)))
D1 = [x for x in set(D) if D.count(x) < 2]
for x in D1:
    if x >= math.floor(N/1000):
        n_0= x*1000
        if abs(n_0 -N ) >=abs(x*1000-N) :
            n_0= x*1000
n_1=n_0

for y in D1:
    if abs(n_1 -N ) >=abs(n_0+100*y-N) :
        n_1 =n_0+100*y
n_2=n_1
for z in D1:
    if abs(n_2 -N ) >=abs(n_1+10*z-N) :
        n_2 =n_1+10*z
n_3=n_2
for a in D1:
    if abs(n_3 -N ) >=abs(n_2+a-N) :
        n_3 =n_2+a


print(n_3)

Submission status: Wrong Answer

Solution code:
def run():
    N, K = map(int, input().split())
    d_list = set(map(int, input().split()))
    all_list = set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    use_list = sorted(list(all_list - d_list))
    n_list = [int(i) for i in list(str(N))]
    ans = ''
    for n in n_list:
      for u in use_list:
        if u >= n: ans += str(u); break
      else: ans += str(use_list[0])
    if N > int(ans):
      if use_list[0] == 0:
        ans = str(use_list[1])+'0'*len(n_list)
      else:
        ans = str(use_list[0])*(len(n_list)+1)
      
    print(ans)

run()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
li = [i for i in range(10)]
s = list(set(li)-set(D))
s.sort()
s = [str(a) for a in s]
for i in range(len(s)):
    for j in range(len(s)):
        for k in range(len(s)):
            for l in range(len(s)):
                ans = int(s[i]+s[j]+s[k]+s[l])
                if ans>=N:
                    print(ans)
                    exit()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
li = [i for i in range(10)]
s = list(set(li)-set(D))
for a in range(len(s)):#頭悪い
    for b in range(len(s)):
        for c in range(len(s)):
            for d in range(len(s)):
                ans = int(str(s[a])+str(s[b])+str(s[c])+str(s[d]))
                if ans>=N:
                    print(ans)
                    exit()

Submission status: Wrong Answer

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
plus=2
for i in range(money,money+plus):
    flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            plus+=1
            break
    if flag==0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
flag=0
for i in range(money,100000):
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
flag=0
for i in range(money,10000):
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
#import sys
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
#if len(no_list)!=num:
#    sys.exit()
for i in range(money,10000):
    flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import sys
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
if len(no_list)!=num:
    sys.exit()
for i in range(money,10000):
    flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break