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 math

total = list(map(lambda x: int(x), input().split()))
possible = list({0,1,2,3,4,5,6,7,8,9} - set(list(map(lambda x: int(x), input().split()))))
yen = [int(d) for d in str(total[0])]

i = 0
if yen[0] == 9 and 9 not in possible:
    zeros = [0] * len(yen)
    yen = [1] + zeros
    print(int(''.join(map(str, yen))))


while i < len(yen):
    if yen[i] not in possible:
        if yen[i] == 9 and i != 0:
            yen[i - 1] += 1
            for i in range(i, len(yen)):
                yen[i] = 0
        elif yen[i] != 9:
            for j in possible:
                if j > i:
                    yen[i] = j
    i = i + 1
        
                
                
            
            




print(int(''.join(map(str, yen))))

Submission status: Wrong Answer

Solution code:
import math

total = list(map(lambda x: int(x), input().split()))
possible = list({0,1,2,3,4,5,6,7,8,9} - set(list(map(lambda x: int(x), input().split()))))
yen = [int(d) for d in str(total[0])]




for index, i in enumerate(yen):
    if i not in possible:
        for j in possible:
            if j > i:
                yen[index] = j

print(int(''.join(map(str, yen))))

Submission status: Wrong Answer

Solution code:
n = list(map(int, input().split()))
a = list(map(int, input().split()))
c = [1,2,3,4,5,6,7,8,9]
b = list(set(a) ^ set(c))
print(b[0] * n[0])

Submission status: Wrong Answer

Solution code:
n,thevailladadu = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
m = n
 
while(n>=10):
    n=n//10
check = n
while check in d:
    check=(check+1)%10
if check>n:
    a = 0
    while a in d:
        a+=1
    while check<m:
        check=(check*10)+a
    print(check)
elif check<n:
    a=1
    while a in d:
        a+=1
    b = 0
    while b in d:
        b+=1
    while a<m:
        a=(a*10)+b
    print(a)
else:
    i=0
    ans=0
    while (m>0):
        a = m%10
    #print(a)
        while a in d:
            a=(a+1)%10
        ans+=(a*(10**i))
        m//=10
        i+=1
    
    #if ans<m:
    #    j=1
    #    while j in d:
    #        j+=1
    #    ans+=(j*(10**i))
    print(ans)

Submission status: Wrong Answer

Solution code:
n,thevailladadu = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
m = n

while(n>0):
    n=n//10
check = n
while check in d:
    check+=1
if check>n:
    a = 0
    while a in d:
        a+=1
    while check<m:
        check=(check*10)+a
    print(check)
else:
    a=1
    while a in d:
        a+=1
    b = 0
    while b in d:
        b+=1
    while a<m:
        a=(a*10)+b
    print(a)

Submission status: Wrong Answer

Solution code:
n,thevailladadu = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
m = n

while(n>0):
    n=n//10
check = n
while check in d:
    check+=1
if check>n:
    a = 0
    while a in d:
        a+=1
    while n<m:
        n=(n*10)+a
    print(n)
else:
    a=1
    while a in d:
        a+=1
    b = 0
    while b in d:
        b+=1
    while a<m:
        a=(a*10)+b
    print(a)

Submission status: Wrong Answer

Solution code:
n,thevailladadu = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
m = n

i=0
ans=0
while (n>0):
    a = n%10
    #print(a)
    while a in d:
        a=(a+1)%10
    ans+=(a*(10**i))
    n//=10
    i+=1
    
if ans<m:
    j=1
    while j in d:
        j+=1
    ans+=(j*(10**i))
    
print(ans)

Submission status: Wrong Answer

Solution code:
import re

N, K = map(int, input().split())
unlike_list = set(map(str, input().split()))
unlike_nums = ''.join(unlike_list)

ans = False
while not ans:
    if re.match(r'([' + unlike_nums + ']+)', str(N)):
        N += 1
    else:
        ans = True
print(N)

Submission status: Wrong Answer

Solution code:
import re

N, K = map(int, input().split())
unlike_list = list(map(str, input().split()))
unlike_nums = ''.join(unlike_list)

ans = False
while not ans:
    if re.match(r'([' + unlike_nums + ']+)', str(N)):
        N += 1
    else:
        ans = True
print(N)

Submission status: Wrong Answer

Solution code:
def check(n,l):
	
	r=str(n)
	for i in range(len(r)):
		if int(r[i]) not in l:
			return 0
	return 1
n,k=map(int,input().split())
c=set(map(int,input().split()))
d=set(range(0,10))

l=list(d-c)

index=1
while check(n,l)==0:
	n+=n
	
	
print(n)

Submission status: Wrong Answer

Solution code:
import sys
import logging
logging.basicConfig(level=logging.DEBUG)


N,K=list(map(int,input().split()))
num=list(input().split())

i=0
while True:
   for j in str(N+i):
       #logging.debug('j={}'.format(j))
       if j in num:
           i+=1
           break
       else:
           print(N+i)
           sys.exit()

Submission status: Wrong Answer

Solution code:
# N, Kの入力受付
N, K = map(int, input().split())
# Dの入力受付
D = set(input().split())
# 0-9とDの差集合作成、リスト化してEに代入
E = list({"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D)
# Eの要素の組み合わせのリストF作成、整数化
F = list((i+j+k+l+n) for i in E for j in E for k in E for l in E for n in E)
F = list(map(int, F))
# Fの要素でN以上の最小値を出力
result = min([m for m in F if m >= N])
print(result)

Submission status: Wrong Answer

Solution code:
# N, Kの入力受付
N, K = map(int, input().split())
# Dの入力受付
D = set(input().split())
# 0-9とDの差集合作成、リスト化してEに代入
E = list({"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D)
# Eの要素の組み合わせのリストF作成、整数化
F = list((i+j+k+l) for i in E for j in E for k in E for l in E)
F = list(map(int, F))
# Fの最大値10000追加
F.append(10000)
# Fの要素でN以上の最小値を出力
result = min([n for n in F if n >= N])
print(result)

Submission status: Wrong Answer

Solution code:
n, k= input().split()
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
for i in range(len(n)):
    first=int(n[i])
    k=find(first)
    if k==first:
        fin+=str(k)
    else:
        if k!=10:
            fin+=str(k)
            i+=1
        else:
            fin=str(find(1))+str(find(0))*len(n)

        break

print(fin)

Submission status: Wrong Answer

Solution code:
n, k= input().split()
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
for i in range(len(n)):
    first=int(n[i])
    k=find(first)
    if k==first:
        fin+=str(k)
    else:
        if k!=10:
            fin+=str(k)
            i+=1
        else:fin+=str(find(1))
        fin+=str(find(0))*(len(n)-i)
        break

print(fin)

Submission status: Wrong Answer

Solution code:
n, k= map(int,input().split())
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
remain=0

if n==0:
    fin=str(find(0))

while n>0 or remain>0:
    last=n%10
    k=find(last+remain)
    remain=0
    if k!=10:
        fin=str(k)+fin
    else:
        remain+=1
        fin=str(find(0))+fin
    n//=10
print(fin)

Submission status: Wrong Answer

Solution code:
n, k= map(int,input().split())
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]
for i in l:
    checkNum[i]=checkNum[i+1]
def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x
fin=""
remain=0
while n>0 or remain>0:
    last=n%10
    k=find(last+remain)
    remain=0
    if k!=10:
        fin=str(k)+fin
    else:
        remain+=1
        fin=str(find(0))+fin
    n//=10
print(fin)

Submission status: Wrong Answer

Solution code:
n, k= map(int,input().split())
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]
for i in l:
    checkNum[i]=checkNum[i+1]
def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x
fin=""
remain=0
while n>0 or remain>0:
    last=n%10
    k=find(last+remain)
    remain=0
    if last!=10:
        fin=str(k)+fin
    else:
        remain+=1
        fin=str(find(0))+fin
    n//=10
print(fin)

Submission status: Wrong Answer

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

for i in range(n, 10001):
    money = list(map(int, str(i)))
    for m in money:
        if dl.count(m) != 0:
            break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())

#dic = defaultdict(int)
n,k = readInts()
D = Counter(readInts())
def ok(n):
    while n:
        v = n%10
        if D[v]:
            return False
        n //= 10
    return True
ans = n
for i in range(n, 10000):
    if ok(i):
        ans = i
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

n,k = MI()
d = RI()

for i in range(n,10000):
    a = str(i)
    flag = True
    for j in a:
        if int(j) in d:
            flag = False
            break
    if flag:
        print(i)
        exit()

Submission status: Wrong Answer

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

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

f_inf = float('inf')


def main():

    N, K = MAPINT()
    D = LMAPSTR()
    
    str_n = str(N)
    
    for i in range(N, 10001):
      str_i = str(i)
      for s in str_i:
        if s in D:
          break
      else:
        print(str_i)
        exit()

        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

f_inf = float('inf')


def main():

    N, K = MAPINT()
    D = LMAPSTR()
    
    str_n = str(N)
    
    for i in range(N, 10000):
      str_i = str(i)
      for s in str_i:
        if s in D:
          break
      else:
        print(str_i)
        exit()

        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)

if __name__ == '__main__':
    # ------ 入力 ------#
    nk = list(map(int, input().split()))     # スペース区切り連続数字

    x = nk[1]
    dList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    f = 0
    n = nk[0]
    while f == 0:
        nList = [int(c) for c in str(n)]  # 数字→単数字リスト変換
        b = 1
        for i in nList:
            for j in dList:
                if i == j:
                    b = 0
                    break
        if b == 1:
            break
        else:
            n += n

    # ------ 出力 ------#
    print("{}".format(n))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")

Submission status: Wrong Answer

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


def f(n, x):
    if n==0:
        if x >= N:
            print(x)
            exit()
        return
    
    for i in range(10):
        if i in D:
            continue
        f(n-1, x*10+i)

f(len(str(N)), 0)
ans = ""
for i in range(1, 10):
    if i not in D:
        ans = str(i)
for i in range(10):
    if i not in D:
        ans += str(i)*len(str(N))
print(ans)

Submission status: Wrong Answer

Solution code:


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


def validate(strNum):
    for i in range(0, len(strNum)):
        if strNum[i] in d:
            return False
    return True


for i in range(0, 10001):
    tf = validate(str(n))
    # print(tf)
    if tf:
        print(n)
        exit()
    n += 1

Submission status: Wrong Answer

Solution code:


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


def validate(strNum):
    for i in range(0, len(strNum)):
        if strNum[i] in d:
            return False
    return True


for i in range(0, 1001):
    tf = validate(str(n))
    # print(tf)
    if tf:
        print(n)
        exit()
    n += 1

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
if k == 0:
  print(n)
  exit()
dislike = list(map(int,input().split()))

ref = [0,1,2,3,4,5,6,7,8,9,0]
for i in range(10):
  while ref[i] in dislike:
    ref[i] = (ref[i]+1)%10

ans = ''
for i in str(n):
  ans += str(ref[int(i)])

if int(ans)<n:
  ans = str(ref[1])+str(ref[0])*len(str(n))
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
if k == 0:
  print(n)
  exit()
dislike = list(map(int,input().split()))

ref = [0,1,2,3,4,5,6,7,8,9,0]
for i in range(10):
  while ref[i] in dislike:
    ref[i] = (ref[i]+1)%10

ans = ''
for i in str(n):
  ans += str(ref[int(i)])

if int(ans)<n:
  ans = str(ref[1])+ans
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
if k == 0:
  print(n)
  exit()
dislike = list(map(int,input().split()))
usable = []
for i in range(10):
  if i not in dislike:
    usable.append(i)
print(usable)
ans = ''
for i in str(n):
  while int(i) not in usable:
    i = str((int(i)+1)%10)
  ans+=i
  
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = [int(x) for x in input().split()]
ds = {int(x) for x in input().split()}
ns = {0,1,2,3,4,5,6,7,8,9} -ds
#print(ds)
#print(ns-ds)
temp=0
d ={}
a=1
b = {}
m = len(str(n)) +1 
over=False
while(a<=m and not over ):
  c = []
  d = 10**(a-1) 
  for v in ns:
    if a>1:
      for bv in b[a-1]:
        t = v*d + bv
        c += [t]
        if t >= n:
          print(t)
          over=True
          break
      if over:
        break
    else:
      c += [v*d]
      
  b[a] = c
  a+=1
  
#for j in b:    
#    print(j,b[j])

Submission status: Wrong Answer

Solution code:
n,k = [int(x) for x in input().split()]
ds = {int(x) for x in input().split()}
ns = {0,1,2,3,4,5,6,7,8,9} -ds
#print(ds)
#print(ns-ds)
temp=0
d ={}
a=1
b = {}
m = len(str(n)) +1 
over=False
while(a<m and not over ):
  c = []
  d = 10**(a-1) 
  for v in ns:
    if a>1:
      for bv in b[a-1]:
        t = v*d + bv
        if t >= n:
          print(t)
          over=True
          break
        c += [t]
      if over:
        break
    else:
      c += [v*d]
      
  b[a] = c
  a+=1
  

#for k in b:
#	print(k,b[k])

Submission status: Wrong Answer

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

while True:
  S=str(N)
  flag=True
  for x in S:
    if x in D:
      flag=False
  if flag==True:
    break;
  N+=1
print(N)

Submission status: Wrong Answer

Solution code:
def answer(n: str, k: str, d: []) -> int:
    numbers = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ^ set(d))
    payment = ''

    if int(str(numbers[-1]) * len(n)) < int(n):
        if numbers[0] == 0:
            payment = str(numbers[1]) + str('0' * len(n))
        else:
            payment = str(numbers[0]) * (len(n) + 1)
        return int(payment)

    for i in n:
        for num in numbers:
            if int(i) <= num:
                payment += str(num)
                break
    return int(payment)


def main():
    n, k = input().split()
    d = map(int, input().split())
    print(answer(n, k, d))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
from time import perf_counter

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





n,k = map(int,input().split())
d= list(map(int,input().split()))
test = [1,2,3,4,5,6,7,8,9]

for item in range(k):
    if d[item]==0:
        print(n)
        exit()

result =[]
for item in test:
    if item not in d:
        result.append(item)
n= list(str(n))
# final_result =[]
for item in range(len(n)):
    if int(n[item])>0:
        if n[item] != result[0]:
            n[item] = str(result[0])
ans = "".join(n)
print(ans)

Submission status: Wrong Answer

Solution code:
def price(N,K):
    Kn = input().split()
    Flag = False

    for i in range(N,10001,1):
        value = str(i)
        for j in range(K):
            if(Kn[j] not in value):
                Flag = True
            elif(Kn[j] in value):
                Flag = False
                break

        if(Flag == True):
            print(i)
            break

N,K = (int(x) for x in input().split()) # N,K 入力
price(N,K)

Submission status: Wrong Answer

Solution code:
import sys
N , K = map(int,input().split())
D = list(map(int,input().split()))
L = [i for i in range(10)]
for i in D:
  L.remove(i)
c = []
for i1 in L:
  for i2 in L:
    for i3 in L:
      for i4 in L:
        k = i1*1000 + i2*100 + i3*10 + i4
        c.append(k)
c.sort()
for i in range(len(c)):
  if c[i] >= N:
    print(c[i])
    sys.exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
Ds = list(map(int, input().split()))
N2 = ''
for d in str(N):
	intd = int(d)
	for i in range(intd, 10):
		if not i in Ds:
			N2 += str(i)
			break
print(N2)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(input().split())
n = 1000
flag = True
while flag:
    flag2 = True
    for si in str(n):
        if si in d:
            n += 1
            flag2 = False
            break
    if flag2:
        break
    else:
        flag = True
            
print(n)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(input().split())
#n = 1000
flag1 = True
while flag1:
    for si in str(n):
        if si in d:
            n += 1
            break
    flag1 = False
print(n)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(input().split())
#n = 1000
flag1 = True
while flag1:
    for si in str(n):
        if si in d:
            n += 1
            break
        flag1 = False
print(n)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
    num.remove(d[i])
    
import itertools, heapq
ans = []
heapq.heapify(ans)
for i in itertools.product(num, repeat=len(str(n))):
    s = int(''.join(i))
    if s >= n:
        heapq.heappush(ans, -s)
        
if len(ans) == 0:
    for i in itertools.product(num, repeat=len(str(n)) + 1):
        s = int(''.join(i))
        if s >= n:
            heapq.heappush(ans, -s)
    print(-heapq.heappop(ans))
    
else:
    print(-heapq.heappop(ans))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
    num.remove(d[i])
    
import itertools, heapq
ans = []
heapq.heapify(ans)
for i in itertools.product(num, repeat=len(str(n))):
    s = int(''.join(i))
    if s >= n:
        heapq.heappush(ans, -s)
        
if len(ans) == 0:
    for i in itertools.product(num, repeat=len(str(n)) + 1):
        s = int(''.join(i))
        if s >= n:
            heapq.heappush(ans, -s)
    print(-heapq.heappop(ans))
    
else:
  print(-heapq.heappop(ans))

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    N = str(N)
    l = len(N)
    if int(str(ok[-1]) * l) < int(N):
        if ok[0] == 0:
            ans = ok[1] * 10 ** l
            print(ans)
        else:
            ans = str(ok[0]) * (l + 1)
            print(ans)
    else:
        kuriagari = False
        ans = 0
        for i, c in enumerate(N):
            ans *= 10
            if kuriagari and ok[-1] < int(c):
                ans += ok[0]
            elif kuriagari:
                idx = bisect_left(ok, int(c))
                ans += ok[idx]
            elif ok[-1] < int(c):
                cnt = 0
                ans //= 10
                while ok[-1] <= ans % 10:
                    ans //= 10
                    cnt += 1
                last = ans % 10
                idx = bisect_left(ok, last + 1)
                ans = (ans // 10) * 10 + ok[idx]
                for _ in range(cnt):
                    ans = ans * 10 + ok[0]
                kuriagari = True
            else:
                idx = bisect_left(ok, int(c))
                ans += ok[idx]
        print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    N = str(N)
    l = len(N)
    if int(str(ok[-1]) * l) < int(N):
        if ok[0] == 0:
            ans = ok[1] * 10 ** l
            print(ans)
        else:
            ans = str(ok[0]) * (l + 1)
            print(ans)
    else:
        kuriagari = False
        ans = 0
        for i, c in enumerate(N):
            ans *= 10
            if kuriagari and ok[-1] < c:
                ans += ok[0]
            elif kuriagari:
                idx = bisect_left(ok, int(c))
                ans += ok[idx]
            elif ok[-1] < int(c):
                cnt = 0
                ans //= 10
                while ok[-1] <= ans % 10:
                    ans //= 10
                    cnt += 1
                last = ans % 10
                idx = bisect_left(ok, last + 1)
                ans = (ans // 10) * 10 + ok[idx]
                for _ in range(cnt + 1):
                    ans = ans * 10 + ok[0]
                kuriagari = True
            else:
                idx = bisect_left(ok, int(c))
                ans += ok[idx]
        print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    N = str(N)
    l = len(N)
    if int(str(ok[-1]) * l) < int(N):
        if ok[0] == 0:
            ans = ok[1] * 10 ** l
            print(ans)
        else:
            ans = str(ok[0]) * (l + 1)
            print(ans)
    else:
        kuriagari = False
        ans = 0
        for i, c in enumerate(N):
            ans *= 10
            if kuriagari and ok[-1] < c:
                ans += ok[0]
            elif kuriagari:
                idx = bisect_left(ok, int(c))
                ans += ok[idx]
            elif ok[-1] < int(c):
                cnt = 0
                ans //= 10
                while ok[-1] <= ans % 10:
                    ans //= 10
                    cnt += 1
                last = ans % 10
                idx = bisect_left(ok, last + 1)
                ans = (ans // 10) * 10 + ok[idx]
                for _ in range(cnt):
                    ans = ans * 10 + ok[0]
                kuriagari = True
            else:
                idx = bisect_left(ok, int(c))
                ans += ok[idx]
        print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
dislikes = [False] * 10
dislike_nums = [int(x) for x in input().split()]
for n in dislike_nums:
    dislikes[n] = True

# Add '0' in the beginning of N for carrying up
N = "0" + str(N)

# Create a list of numbers consists N
n_list = []
for n in N:
    n_list.append(int(n))
# Create a list of carrying up numbers
c_list = [0] * len(n_list)

# Create the smallest payment
payment = ""
for i in range(len(n_list) - 1, -1, -1):
    n = n_list[i] + c_list[i]
    if i == 0 and n == 0:
        break
    # Find an equal or larger number than n and not in dislikes
    x = -1
    for m in range(n, 10):
        if not dislikes[m]:
            x = m
            break
    if x >= 0:
        # found a number
        payment = str(m) + payment
        continue

    # Carry a number to the previous (x10) digit
    if i > 0:
        c_list[i - 1] += 1

    # Find a smaller number than n and not in dislikes
    for m in range(0, n):
        if not dislikes[m]:
            payment = str(m) + payment
            break
print(int(payment))

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
dislikes = [False] * 10
dislike_nums = [int(x) for x in input().split()]
for n in dislike_nums:
    dislikes[n] = True

# Add '0' in the beginning of N for carrying up
N = "0" + str(N)

# Create a list of numbers consists N
n_list = []
for n in N:
    n_list.append(int(n))
# Create a list of carrying up numbers
c_list = [0] * len(n_list)

# Create the smallest payment
payment = ""
for i in range(len(n_list) - 1, -1, -1):
    n = n_list[i] + c_list[i]
    if i == 0 & n == 0:
        break
    # Find an equal or larger number than n and not in dislikes
    x = -1
    for m in range(n, 10):
        if not dislikes[m]:
            x = m
            break
    if x >= 0:
        # found a number
        payment = str(m) + payment
        continue

    # Carry a number to the previous (x10) digit
    if i > 0:
        c_list[i - 1] += 1

    # Find a smaller number than n and not in dislikes
    for m in range(0, n):
        if not dislikes[m]:
            payment = str(m) + payment
            break
print(int(payment))

Submission status: Wrong Answer

Solution code:
def minN(N:int, usable:list, restrict=True):
    usable.sort()
    if restrict:
        for i in usable:
            if i >= N:
                return str(i)
        # 桁が増えるとき
        if usable[0] != 0:
            return str(usable[0]) + str(usable[0])
        else:
            return str(usable[1]) + str(usable[0])
    else:
        return str(usable[0])


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = list(numset.difference(D))
    d.sort()

    Nstr = list(str(N))
    ans = ''
    flag = True
    for n in Nstr:
        n = int(n)
        if flag:
            if n in D:
                ans += minN(n, d)
                flag = False
            else:
                ans += str(n)
        else:
            ans += str(min(d))
    print(int(ans))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set(map(int, input().split()))
if k == 9:
    print(n+1)
    exit(0)
for ans in range(n,10000):
    for c in str(ans):
        if int(c) in D:
            break
    else:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set(map(int, input().split()))
if k == 9:
    print(n)
    exit(0)
for ans in range(n,10000):
    for c in str(ans):
        if int(c) in D:
            break
    else:
        print(ans)
        break