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:
s = input()
s = s.split(" ")
N = s[0]
K = int(s[1])

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

allows = [10] * 11
for i in range(9, -1, -1):
  allows[i] = i if i not in ds else allows[i+1]

minNum = min(allows)

states = [int(digit) for digit in N]

for index in range(len(states)-1, 0, -1):
  states[index] = allows[states[index]]
  
  if states[index] == 10:
    states[index-1] += 1

states[0] = allows[states[0]]

for index in range(0, len(states)):
  if states[index] > int(N[index]):
    for i in range(index+1, len(states)):
      states[i] = minNum

if states[0] == 10:
  states = [minNum] + states
    
print("".join([str(digit) for digit in states]))

Submission status: Wrong Answer

Solution code:
s = input()
s = s.split(" ")
N = s[0]
K = int(s[1])

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

allows = [10] * 11
for i in range(9, -1, -1):
  allows[i] = i if i not in ds else allows[i+1]

minNum = min(allows)

states = [int(digit) for digit in N]

for index in range(len(states)-1, 0, -1):
  states[index] = allows[states[index]]
  
  if states[index] == 10:
    states[index-1] += 1
    states[index] = minNum

states[0] = allows[states[0]]
if states[0] == 10:
  states[0] = minNum
  states = [minNum] + states

print("".join([str(digit) for digit in states]))

Submission status: Wrong Answer

Solution code:

s = input()
s = s.split(" ")
N = s[0]
K = int(s[1])

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

allows = [10] * 11
for i in range(9, -1, -1):
  allows[i] = i if i not in ds else allows[i+1]


minNum = 0
for i in range(0, 10):
  if allows[i] == i:
    minNum = i
    break

states = [int(digit) for digit in N]

for index in range(len(states)-1, -1, -1):
  states[index] = allows[states[index]]
  
  if states[index] == 10:
    states[index-1] += 1
    states[index] = minNum

if states[0] == 10:
  states[0] = minNum
  states = [minNum] + states

print("".join([str(digit) for digit in states]))

Submission status: Wrong Answer

Solution code:
def ume(n):
  st = str(n)
  le = len(st)
  re = ["0"]*le
  for i in range(le):
    if st[i]=="0":
      re[i]=str(m)
    else:
      re[i]=st[i]
  return int("".join(re))


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

#使える文字をリスト化
for i in range(10):
  if not i in d:
    num.append(i)

ds = str(n)#nを文字列にしたもの
l = len(ds)#nの桁数
m = min(num)#numのうち最小の数

if l == 1:
  for i in num:
    if i>=n:
      print(i)
      quit()

dp0=[0]*(l+1)
dp1=[0]*(l+1)

for i in num:
  if i != 0:
    ans = ume(i*(10**(l)))

for i in num:
  flg = True
  if i == int(ds[0]):
    dp1[1]=i*(10**(l-1))
    flg = False
  if i > int(ds[0]):
    ans = ume(i*(10**(l-1)))
    break
    
if flg:
  print(ans)
  quit()

for i in range(1, l):
  flg = True
  flg2 = True
  for j in num:
    if j == int(ds[i]):
      dp1[i+1]=dp1[i]+j*(10**(l-1-i))
      flg = False
      flg2 = False
    if j > int(ds[i]):
      flg2 = False
      ans = ume(dp1[i]+j*(10**(l-1-i)))
      if flg:
        print(ans)
        quit()
      break
  if flg2:
    print(ans)
    quit()
  #print(dp1[i+1])
print(dp1[l])

Submission status: Wrong Answer

Solution code:
def ume(n):
  st = str(n)
  le = len(st)
  re = ["0"]*le
  for i in range(le):
    if st[i]=="0":
      re[i]=str(m)
    else:
      re[i]=st[i]
  return int("".join(re))


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

#使える文字をリスト化
for i in range(10):
  if not i in d:
    num.append(i)

ds = str(n)#nを文字列にしたもの
l = len(ds)#nの桁数
m = min(num)#numのうち最小の数

dp0=[0]*(l+1)
dp1=[0]*(l+1)

for i in num:
  if i != 0:
    ans = ume(i*(10**(l)))

for i in num:
  flg = True
  if i == int(ds[0]):
    dp1[1]=i*(10**(l-1))
    flg = False
  if i > int(ds[0]):
    ans = ume(i*(10**(l-1)))
    break
    
if flg:
  print(ans)
  quit()

for i in range(1, l):
  flg = True
  flg2 = True
  for j in num:
    if j == int(ds[i]):
      dp1[i+1]=dp1[i]+j*(10**(l-1-i))
      flg = False
      flg2 = False
    if j > int(ds[i]):
      flg2 = False
      ans = ume(dp1[i]+j*(10**(l-1-i)))
      if flg:
        print(ans)
        quit()
      break
  if flg2:
    print(ans)
    quit()
  #print(dp1[i+1])
print(dp1[l])

Submission status: Wrong Answer

Solution code:
# ARC058A

n, k = map(int, input().split())
d = set(input().split())
valid = {'0', '1', '2', '3', '4', '5', '7', '6', '7', '8', '9'}
d2 = list(valid - d)
d2 = sorted(d2)
n2 = list(str(n))
for i, c in enumerate(n2):
    if c in d:
        for j, c2 in enumerate(d2):
            if c2 > c:
                n2[i] = c2
                break
print(str(''.join(n2)))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = list(map(int,input().split()))

for i in range(n,10001):
    k = i
    c=0
    while k>0:
        if k%10 not in l:
            c+=1
        else:
            break
        k = k//10
    if len(str(i))==c:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
from itertools import product

n, k = map(int, input().split())
d = set(range(10)) - set(map(int, input().split()))

for i in product(d | set([0]), repeat=len(str(n)) + 1):
    i = int("".join(str(j) for j in i))
    print(i, d)
    if (i >= n) and all(int(k) in d for k in str(i)):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n, k = input().split()
k = int(k)
D = tuple(map(int, input().split()))
ND = [i for i in range(10) if not i in D]
minND = ND[0]

nl = list(n)
kuriage = 0
ans = []
for nd in nl[::-1]:
    nd = int(nd) + kuriage
    if nd == 10:
        ans.append(str(minND))
        kuriage = 1
        continue

    if nd in D:
        # ndが嫌い
        # Dの中にndnより大きい数字全て入っていたら
        for ndn in range(nd, 10):
            if ndn in ND:
                ans.append(str(ndn))
                kuriage = 0
                break
        else:
            ans.append(str(minND))
            kuriage = 1
    else:
        # ndはOK
        ans.append(str(nd))
        kuriage = 0

if kuriage == 1:
    if ND[0] == 0:
        minND = ND[1]
    ans.append(str(minND))

print(''.join(ans[::-1]))

Submission status: Wrong Answer

Solution code:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)


def FindFirstBig(okLines, m, FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig


for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines, m, FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0 and ProblemFlag is not -1:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag, len(newMoney), 1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        if okLines[0] is not "0":
            newMoney.insert(0, okLines[0])
        else:
            newMoney.insert(0, okLines[1])
        for i in range(ProblemFlag, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Submission status: Wrong Answer

Solution code:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)


def FindFirstBig(okLines, m, FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig


for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines, m, FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0 and ProblemFlag is not -1:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag, len(newMoney), 1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        newMoney.insert(0, okLines[0])
        for i in range(ProblemFlag, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Submission status: Wrong Answer

Solution code:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
for i in range(10):
    if str(i) not in hateLines and str(i) > oldMoney[0]:
        okLines.append(i)
for index,m in enumerate(oldMoney):
    if m in hateLines and len(okLines) > 0:
        oldMoney[index] = str(okLines[0])
result = "".join(oldMoney)
print(result)

Submission status: Wrong Answer

Solution code:
input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

for ans in range(int(N), 10000):
    flg = True
    for i in range(len(str(ans))):
        if str(ans)[i] in D:
          flg = False
          break

    if flg:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

for ans in range(int(N), 10000):
    flg = True
    for cal in str(ans):
        if cal in D:
          flg = False
          break

    if flg:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

for ans in range(int(N)+1, int(N)*10):
    flg = 0
    tmp = str(ans)
    for moji in tmp:
        if moji in D:
            flg = 1
            break
    if flg == 0:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
import re

#input_1st="1000 8"
#input_2nd="1 3 4 5 6 7 8 9"
input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

pattern = re.compile("|".join(D))
#print(pattern)

for ans in range(int(N), 10000):
    result = re.findall(pattern, str(ans))
    if not result:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
import re

#input_1st="1000 8"
#input_2nd="1 3 4 5 6 7 8 9"
input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

pattern = re.compile("|".join(D))
print(pattern)

for ans in range(int(N), 10000):
    result = re.findall(pattern, str(ans))
    if not result:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
A,B = list(map(int,input().split()))
l_n = list(map(int,input().split()))
l = list(range(0,10))
for i in l_n:
    l.remove(i)
l.sort()
ans = 0
for i in l:
    for j in l:
        for k in l:
            for n in l:
                for m in l:
                    ans=i* 10000+j* 1000+k* 100+n*10+m
                    if ans >= A:
                        print(ans)
                        exit()

Submission status: Wrong Answer

Solution code:
A,B = list(map(int,input().split()))
l_n = list(map(int,input().split()))
l = list(range(0,10))
for i in l_n:
    l.remove(i)
l.sort()
ans = 0
for i in l:
    for j in l:
        for k in l:
            for n in l:
                ans=i* 1000+j* 100+k* 10+n
                if ans >= A:
                    print(ans)
                    exit()
                ans = 0

Submission status: Wrong Answer

Solution code:
b, k = map(int, input().split())
a=[0]*k
a=list(map(int, input().split()))
box=[0,1,2,3,4,5,6,7,8,9,10]
for i in range(k):
    box.remove(a[i])
for i in range(len(str(b))):
    for j in range(len(box)):
        if int(str(b)[i])==box[j]:
            break
        b=b+1
print(int(b))

Submission status: Wrong Answer

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


for i in range(n, n + 1000000000000):
    #各桁を確かめる
        str_i = str(i)
        if str_i[0] in d:
            continue
        if len(str(i))==2:
            if str_i[1] in d:
                continue
        if len(str(i))==3:
            if str_i[2] in d:
                continue
        if len(str(i))==4:
            if str_i[3] in d:
                continue
        if len(str(i))==5:
            if str_i[4] in d:
                continue
        print(i)
        break

Submission status: Wrong Answer

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


for i in range(n, n + 10000):
    #各桁を確かめる
        str_i = str(i)
        if str_i[0] in d:
            continue
        if len(str(i))==2:
            if str_i[1] in d:
                continue
        if len(str(i))==3:
            if str_i[2] in d:
                continue
        if len(str(i))==4:
            if str_i[3] in d:
                continue
        if len(str(i))==5:
            if str_i[4] in d:
                continue
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(input().split())
ans = 100000
for i in range(n, 10001):
    for j in range(k):
        if d[j] in str(i):
            break
    else:
        if ans > i:
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
num=[]
ans=""

for i in [0,1,2,3,4,5,6,7,8,9]:
  if i not in d:
    num.append(i)

n=str(n)
for i in range(len(str(n))):
  for j in num:
    if j>=int(n[i]):
      ans+=str(j)
      break
      
print(ans)

Submission status: Wrong Answer

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

for i in range(N, 10*N+1):
    s = str(i)
    for j in range(len(str(i))):
        if(s[j] in D):
            break
        print(i)
        quit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=[1]*10
for i in map(int,input().split()):
  D[i]=0
ans=''
while N>0:
  n=N%10
  N=N//10
  while D[n%10]==0:
    n+=1
  ans+=str(n%10)
  if n>9:
    N+=1
if ans=='':
  print(N)
else:
  print(ans[::-1])

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=[1]*10
for i in map(int,input().split()):
  D[i]=0
ans=''
while N>0:
  n=N%10
  N=N//10
  while D[n%10]==0:
    n+=1
  ans+=str(n%10)
  if n>9:
    N+=1
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
n, k = input().split()
X = set(map(int, input().split()))
rs = ["0"]*len(n)
for i, c in enumerate(n):
    c = int(c)
    if c in X:
        rs[i] = str(c+1)
        break
    rs[i] = str(c)
print("".join(rs))

Submission status: Wrong Answer

Solution code:
n,m = input().split()
k=int(n)
li = list(input().split())

for i in range(k,10000):
    for e in li:
        if e in str(i):
            break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
# cook your dish here
s=input()
m=s.split()
n,k=m[0],m[1];
s=input()
m=s.split()
list=[]
nlist=[]

    
    
for i in m:
    list.append(int(i))
for i in range(0,10):
    if i not in list:
        nlist.append(i)

num=[int(d) for d in str(n)]
for i in range(len(num)):
    if (num[(-1)*i]) not in list:
        continue
    else:
        for j in nlist:
            if(j>num[(-1)*i]):
                num[(-1)*i]=j
for i in num:
    print(i,end="")

Submission status: Wrong Answer

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

nD = sorted([i for i in range(10) if i not in D])
con = 5
s = ""

M = list(set(str(N)))

flag = 0

for i in M:
  if int(i) in D:
    flag = 1
    break
else:
  print(N)

if flag == 1:
  while con > 0:
    if con == 5 and nD[0] == 0:
      s += str(nD[1])
    else:
      s += str(nD[0])
    num = int(s)
    if num >= N:
      break
    con -= 1
  
  print(num)

Submission status: Wrong Answer

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

nD = sorted([i for i in range(10) if i not in D])
con = 5
s = ""

M = list(set(str(N)))

flag = 0

for i in M:
  if i in D:
    flag = 1
    break
  else:
    print(N)

if flag == 1:
  while con > 0:
    if con == 5 and nD[0] == 0:
      s += str(nD[1])
    else:
      s += str(nD[0])
    num = int(s)
    if num >= N:
      break
    con -= 1
  
  print(num)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
*D, = map(int, input().split())
D = set(D)
L = {1,2,3,4,5,6,7,8,9,0} - D
for i in range(N, N*10):
    num = {i//10000 %10, i//1000 %10, i//100 %10, i//10 %10, i%10}
    if num.isdisjoint(D):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
*D, = map(int, input().split())
D = set(D)
L = {1,2,3,4,5,6,7,8,9,0} - D
for i in range(N, N*10):
    num = {i//1000 %10, i//100 %10, i//10 %10, i%10}
    if num.isdisjoint(D):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
s=sorted([str(i) for i in [0,1,2,3,4,5,6,7,8,9] if i not in d])
if s[0]==0:
    s[0],s[1]=s[1],s[0]
cnt=0
for i in d:
    if str(i) not in str(n):
        cnt+=1
if cnt==len(d):
    print(n)
    exit()
for i in s:
    for j in s:
        for k in s:
            for l in s:
                for m in s:
                    x=int(i+j+k+l+m)
                    if x>=n:
                        print(x)
                        exit()

Submission status: Wrong Answer

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

if N<10:
    while N%10 in D:
        N+=1
if 10<=N<100:
    while (N//10)%10 in D:
        N+=10
if 100<=N<1000:
    while (N//100)%10 in D:
        N+=100
if 1000<=N<10000:
    while (N//1000)%10 in D:
        N+=1000
if 10000<=N:
    while N//10000 in D:
        N+=10000
print(N)

Submission status: Wrong Answer

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

x=0
a=N//1000
b=(N//100)%10
c=(N//10)%10
d=N%10

while d%10 in D:
    d+=1
if d>=10:
    c+=1
while c%10 in D:
    c+=1
if c>=10:
    b+=1
while b%10 in D:
    b+=1
if b>=10:
    a+=1
while a%10 in D:
    a+=1
if a>=10:
    x=1
    while x in D:
        x+=1

ans=x*10000+(a%10)*1000+(b%10)*100+(c%10)*10+(d%10)
print(ans)

Submission status: Wrong Answer

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

a=N//1000
b=(N//100)%10
c=(N//10)%10
d=N%10

while d%10 in D:
    d+=1
if d>=10:
    c+=1
while c%10 in D:
    c+=1
if c>=10:
    b+=1
while b%10 in D:
    b+=1
if b>=10:
    a+=1
while a%10 in D:
    a+=1
ans=a*1000+(b%10)*100+(c%10)*10+(d%10)
print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    while N//(10**i)%10 in D:
        N+=10**i

if len(str(N))>m:
    while N//(10**m)%10 in D:
        N+=10**m

print(N)

Submission status: Wrong Answer

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

for i in range(len(str(N))):
    while N//(10**i)%10 in D:
        N+=10**i
print(N)

Submission status: Wrong Answer

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

for i in range(n, n*11):
  for d in Ds:
    if d in list(str(i)):
      break
  else:
    print(i)
    exit(0)

Submission status: Wrong Answer

Solution code:
#1000 8
#1 3 4 5 6 7 8 9

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

for i in range(n, n*10+2):
  for d in Ds:
    if d in list(str(i)):
      break
  else:
    print(i)
    exit(0)

Submission status: Wrong Answer

Solution code:
# ABC042C - こだわり者いろはちゃん / Iroha's Obsession (ARC058)
def main():
    N, K, *D = map(int, open(0).read().split())
    available = {str(i) for i in set(range(10)) - set([1, 3])}
    while True:
        used = set(str(N))
        if used <= available:
            print(N)
            break
        N += 1


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def isntD(n):
    c = 0
    for i in range(len(str(n))):
        if D.count(int(str(n)[i])) == 1:
            c += 1
    return c
    

while N < 10000:
    if isntD(N) == 0:
        print(N)
        break
    N += 1

Submission status: Wrong Answer

Solution code:
MAX_N = 10005

n, _ = input().split(' ')
n = int(n)

dislikes = set(input().split(' '))

for num in range(n, MAX_N):
    num_set = set(str(num))
    if len(dislikes & num_set) > 0:
        continue
    print(num)
    break

Submission status: Wrong Answer

Solution code:
MAX_N = 10005

n, _ = input().split(' ')
n = int(n)

dislikes = set(map(int, input().split(' ')))

for num in range(n, MAX_N):
    num_set = set(str(num))
    if len(dislikes & num_set) > 0:
        continue
    print(num)
    break

Submission status: Wrong Answer

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

for i in d:
    forbid_dict[i] = True

def to_digits(n):
    digits = []
    while n > 0:
        digits.append(n % 10)
        n = n // 10
    return digits

digits = to_digits(n)

result_list = []

def find_avaiable(i, forbid_dict):
    k = (i + 1) % 10
    while k in forbid_dict:
        k = (k + 1) % 10
    return k

inc_flag = False
for i in digits:
    if inc_flag or i in forbid_dict:
        k = find_avaiable(i, forbid_dict)
        result_list.append(k)
        if k < i:
            inc_flag = True
        else:
            inc_flag = False
    else:
        result_list.append(i)


print(''.join(map(str, reversed(result_list))))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
L = SR(n)
dp = ['{' * l for l in range(k+1)]


for i in range(n):
    for j in range(k, len(L[i]) - 1, -1):
        dp[j] = min(dp[j-len(L[i])] + L[i], dp[j])



print(dp[k])

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(input().split())
for i in range(n+1, 10**6):
  if all([j not in a for j in str(i)]):
 #   print([j for j in str(i)])
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n+1, 10**6):
  for j in str(i):
    if j in a:
      break
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
n, k = [int(x) for x in input().split(' ')]
d = set(x for x in input().split(' '))

for i in range(10000):
    if set(str(i)).isdisjoint(d) and i >= n:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import itertools
n, k = map(int, input().split())
d = list(map(int, input().split()))
u = []
for i in range(0, 10):
    if i not in d:
        u.append(i)
for j in range(1, 6):
    for i in itertools.product(u, repeat=j):
        t = int("".join(map(str, i)))
        if n <= t <= 10000:
            print(t)
            exit()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
N, K = map(list, input().split())
D = list(map(int, input().split()))
D = [i for i in range(10) if not i in D]
res = []
big = 0
if int("".join([str(D[-1])] * len(N))) < int("".join(N)):
  if int(K[0]) < 9:
    if D[0] == 0:
      res = [D[1]] + [0] * len(N)
    else:
      res = [D[1]] * (len(N) + 1)
  else:
    res = [D[0]] * (len(N) + 1)
else:
  for i in range(len(N)):
    if big == 0:
      res.append(D[bl(D, int(N[i]))])
    else: res.append(D[0])
    if res[i] > int(N[i]): big = 1
print("".join(list(map(str, res))))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = tuple(map(str, input().split()))
for i in range(n, 10001):
    b = True
    for s in tuple(str(i)):
        if s in d:
            b = False
            break
    if b:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#ARC58C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
k=hoge[1]

d=[]
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,k):
	d.append(hoge[i])

payment=0
for i in range(0,10000-n+1):
	payment=n+i
	for j in range(0,k):
		if(str(d[j]) in str(payment)):
			break
		if(j==k-1):
			print(payment)
			sys.exit()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#ARC58C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
k=hoge[1]

d=[]
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,k):
	d.append(hoge[i])

payment=0
for i in range(0,10000-n):
	payment=n+i
	for j in range(0,k):
		if(str(d[j]) in str(payment)):
			break
		if(j==k-1):
			print(payment)
			sys.exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

value = list((input().split(" "))[0])
dislike_list = tuple(int(i) for i in input().split(" "))
digits = len(value)
move_up_key = 0
for i in range(digits - 1, -1, -1):
    judged_num = int(value[i])
    while True:
        if judged_num == 10:
            judged_num = 0
            if i != 0:
                value[i - 1] = str(int(value[i - 1]) + 1)
            else:
                move_up_key = 1
        else:
            if judged_num not in dislike_list:
                value[i] = str(judged_num)
                break
            else:
                judged_num += 1
if move_up_key:
    judged_num = 1
    while True:
        if judged_num not in dislike_list:
            value.insert(0, str(judged_num))
            break
        else:
            judged_num += 1
print(int("".join(value)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

value = list((input().split(" "))[0])
dislike_list = tuple(int(i) for i in input().split(" "))
digits = len(value)
for i in range(digits - 1, -1, -1):
    judged_num = int(value[i])
    while True:
        if judged_num == 10:
            judged_num = 0
            if i != 0:
                value[i - 1] = str(int(value[i - 1]) + 1)
            else:
                value.insert(0, str(1))
        else:
            if judged_num not in dislike_list:
                value[i] = str(judged_num)
                break
            else:
                judged_num += 1
print(int("".join(value)))

Submission status: Wrong Answer

Solution code:
import collections, heapq, math, sys

n, k = map(int, sys.stdin.readline().rstrip().split(' '))
dislikes = map(int, sys.stdin.readline().rstrip().split(' '))
dislikess= set(dislikes)
for i in range(9):
  if i not in dislikess:
    smallest = i
    break
cp = n
s = []
while cp:
  s.append(cp%10)
  cp //= 10
s.append(0)
idx = -1
found = True
print(s)
print(dislikess)
for i in range(len(s)):
  z = s[i]
  if i == len(s) - 1:
    if not found:
        if smallest == 0:
            for m in range(1, 10):
                if m not in dislikess:
                    s[i] = m
                    break
        else:
            s[i] = smallest
        idx = i-1
    break
  if not found or z in dislikess:
    found = False
    for j in range(z+1, 10):
      if j not in dislikes:
        s[i] = j
        found = True
        break
    print('a')
    if not found:
    	idx = i
    else:
    	idx = i - 1
  else:
    found = True
print(idx)
if s[-1] == 0:
  s.pop()
for i in range(idx+1):
  s[i] = smallest

ret = 0
while len(s):
  ret *= 10
  ret += s.pop()
print(ret)

Submission status: Wrong Answer

Solution code:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums < available:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()
N, K = map( int, lines[0].split(' ') )
D = [int(d) for d in lines[1].split(' ')]

total = [int(x) for x in str(N)]
for i in range(0, len(total)):
    old_digit = total[i]
    while total[i] in D:
        total[i] = (total[i] + 1) % 10
    if total[i] > old_digit and (not 0 in D):
        print(''.join(map(str, total[0:i+1])) + '0'*(len(total)-i-1) )
        quit()

print(''.join(map(str, total)))

Submission status: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()
N, K = map( int, lines[0].split(' ') )
D = [int(d) for d in lines[1].split(' ')]

total = [int(x) for x in str(N)]
for i in range(0, len(total)):
    old_digit = total[i]
    while total[i] in D:
        total[i] += 1
    if total[i] > old_digit:
        print(''.join(map(str, total[0:i+1])) + '0'*(len(total)-i-1) )
        quit()

print(''.join(map(str, total)))