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:
n, k = map(int, input().split())
dislike = list(map(int, input().split()))
for i in range(n, 10001):
    a = str(i)
    # print(a)
    flag = True
    for j in range(len(a)):
        # print(a[j])
        for k in dislike:
            # print(k)
            if int(a[j]) == k:
                flag = False
                break
        if flag == False:
            break
    if flag == True:
        print(i)
        break

Submission status: Wrong Answer

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

digitlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for d in D:
    digitlist.remove(d)

Keta = len(str(N))
Ans = ''


def clear(X):
    if len(X) == Keta:
        if int(X) >= N:
            print(X)
            exit()
    else:
        for i in digitlist:
            X = X + str(i)
            clear(X)
            X = X[:-1]


def clear2(X):
    if len(X) == Keta+1:
        if int(X) >= N:
            print(X)
            exit()
    else:
        for i in digitlist:
            X = X + str(i)
            clear(X)
            X = X[:-1]



clear(Ans)
clear2(Ans)

Submission status: Wrong Answer

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

digitlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for d in D:
    digitlist.remove(d)

Keta = len(str(N))
Ans = ''


def clear(X):
    if len(X) == Keta:
        if int(X) >= N:
            print(X)
            exit()
    else:
        for i in digitlist:
            X = X + str(i)
            clear(X)
            X = X[:-1]


clear(Ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(map(str, input().split()))
 
while True:
    print([i in d for i in list(str(n))])
    if sum([i in d for i in list(str(n))]) == 0:
        print(n)
        break
    n+= 1

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
f_inf = float("inf")
###
import itertools
def cal(temp):
    keta = len(temp)
    num = 0
    for t in range(keta):
        num += temp[t] * (10 ** (keta-t-1))
    return num
mini = float("inf")
N,K = map(int,input().split())
D = set(map(int,input().split()))
l = len(str(N))

li = set([int(_) for _ in range(0,10)])
D = li - D
for x in itertools.product(D,repeat=l):
    hoge = cal(x)
    if N <= hoge:
        mini = min([hoge,mini])
print(mini)

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
D = list(map(int, input().split()))
D.sort()
flag = False
print(D)
while True:
  K_str = str(K)
  for i in range(len(K_str)):
    for j in range(len(D)):
      if K_str[len(K_str)-1-i]==str(D[j]):
        flag=False
        break
      if j==len(D)-1:
        flag = True

    if not flag:
      break

  if flag:
    break
  K+=1

print(K)

Submission status: Wrong Answer

Solution code:
def aa(K, D, digit):
  K_str = str(K)
  K_len = len(K_str)
  carry = False
  j=0
  while j < len(D):
    if K_str[K_len-digit-1]==str(D[j]):
      K=K+10**digit
      K_str=str(K)
      if D[j]==9:
        carry = True
    j+=1
  return K, carry

K, N = map(int, input().split())
D = list(map(int, input().split()))
D.sort()
K_str = str(K)
K_len = len(K_str)
carry = False
i=0
while i < K_len:
  K, carry = aa(K, D, i)
  if carry:
    i-=1
  i+=1
  K_len=len(str(K))

print(K)

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
D = list(map(int, input().split()))
D.sort()
K_str = str(K)
K_len = len(K_str)
carry = False
i=0
while i < K_len:
  j=0
  while j < len(D):
    if K_str[K_len-i-1]==str(D[j]):
      K=K+10**i
      K_str=str(K)
      if D[j]==9:
        if j == K_len-1:
          carry = True
        i-=1
    j+=1
  i+=1
      
if carry:
  for j in range(len(D)):
    if K_str[0]==D[j]:
      K=K+10**(len(K_str)-1)
      K_str=str(K)

print(K)

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
D = list(map(int, input().split()))
D.sort()
K_str = str(K)
K_len = len(K_str)
carry = False
i=j=0
while i < K_len:
  while j < len(D):
    if K_str[K_len-i-1]==str(D[j]):
      K=K+10**i
      K_str=str(K)
      if D[j]==9:
        if j == K_len-1:
          carry = True
        i-=1
    j+=1
  i+=1
      
if carry:
  for j in range(len(D)):
    if K_str[0]==D[j]:
      K=K+10**(len(K_str)-1)
      K_str=str(K)

print(K)

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
D = list(map(int, input().split()))
D.sort()
K_str = str(K)
K_len = len(K_str)
carry = False
for i in range(K_len):
  for j in range(len(D)):
    if K_str[K_len-i-1]==str(D[j]):
      K=K+10**i
      K_str=str(K)
      if D[j]==9 and i==K_len-1:
        carry = True
      
if carry:
  for j in range(len(D)):
    if K_str[0]==D[j]:
      K=K+10**(len(K_str)-1)
      K_str=str(K)

print(K)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input=sys.stdin.readline

n,k=map(int,input().split())
d=list(map(int,input().split()))
res=[]
for i in range(10):
  if i not in d:
    res.append(i)
ans=0
ansmax=0
ansmin=0
n_s=str(n)
l=len(n_s)
M=max(res)
for i in range(l):
    ansmax+=M*10**(l-i-1)

if n>ansmax:
    if res[0]!=0:
        ans=res[0]*10**l
    else:
        ans=res[1]*10**l
    for i in range(l):
        ans+=res[0]*10**(l-i-1)
    print(ans)
    exit()
res=np.array(res)
flag=False
for i in range(l):
    j=n//(10**(l-i-1))
    if not flag:
        if j not in res:
            p=np.searchsorted(res,j, side="left")
            m=res[p]
            ans+=m*10**(l-i-1)
            flag=True
        else:
            ans+=j*10**(l-i-1)
    if flag:
        ans+=res[0]*(l-i-1)
    n=n%(10**(l-i-1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input=sys.stdin.readline

n,k=map(int,input().split())
d=list(map(int,input().split()))
res=[]
for i in range(10):
  if i not in d:
    res.append(i)
ans=0
ansmax=0
ansmin=0
n_s=str(n)
l=len(n_s)
M=max(res)
for i in range(l):
    ansmax+=M*10**(l-i-1)

if n>ansmax:
    if res[0]!=0:
        ans=res[0]*10**l
    else:
        ans=res[1]*10**l
    for i in range(l):
        ans+=res[0]*10**(l-i-1)
    print(ans)
    exit()
res=np.array(res)
flag=False
print(res)
for i in range(l):
    j=n//(10**(l-i-1))
    if not flag:
        if j not in res:
            print(j)
            p=np.searchsorted(res,j, side="left")
            m=res[p]
            ans+=m*10**(l-i-1)
            flag=True
        else:
            ans+=j*10**(l-i-1)
    if flag:
        ans+=res[0]*(l-i-1)
    n=n%(10**(l-i-1))
print(ans)

Submission status: Wrong Answer

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


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


def main():
    N, _ = readnums()
    d = set(readstrs())
    for i in range(N, 10000):
        for digit in tuple(str(i)):
            if digit in d:
                break
        else:
            print(i)
            break


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

D = list(map(int,input().split()))
OK = []
for i in range(10):
  if i not in D:
    OK.append(str(i))
print(OK)
sn = str(N)
l = len(sn)

ans = N*1
Flag = 0
while Flag == 0:
  sans = str(ans)
  if all(sans[i] in OK for i in range(len(sans))):
    Flag = 1
  else:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,K= map(int,input().split())
D = [int(j) for j in input().split()]
D2 = list(set([i for i in range(0,10)])-set(D))
D1 = list(set([i for i in range(1,10)])-set(D))
ans =''
for i in reversed(range(-len(str(N)),0)):
    if int(str(N)[i]) not in D:
        ans+=str(N)[i]
    elif i==-len(str(N)):
        ans+=str(min(D1))
    else:
        ans+=str(min(D2))
print(int(ans[::-1]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,10000):
  s=str(i)
  ok=True
  t_str=""
  for ss in s:
    if int(ss) in d:
      ok=False
      break
    t_str+=ss
  if ok:
    print(int(t_str))
    exit(0)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
UN = [i for i in range(10)]
for i in D:
    UN.remove(i)
print(UN)

n = str(N)
N_keta = len(n)

for i in n:
    if int(i) not in UN:
        break
else:
    print(N)
    exit()

ex_0 =  [i for i in UN if i > 0]

if N_keta == 1:
    if N < max(UN):
        _11 =[i for i in UN if i > N]
        print(min(_11))
    else:
        print(min(ex_0) * 10 + min(UN))

if N_keta == 2:
    if N < max(UN) * 11:
        for i in UN:
            for j in UN:
                _2 = i * 10 + j
                if  _2 > N:
                    print(_2)
                    exit()
    else:
        print(min(ex_0) * 100 + min(UN) * 11)

if N_keta == 3:
    if N < max(UN) * 111:
        for i in UN:
            for j in UN:
                 for k in UN:
                     _3 = i * 100 + j * 10 + k
                     if _3 > N:
                         print(_3)
                         exit()
    else:
        print(min(ex_0) * 1000 + min(UN) * 111)

if N_keta == 4:
    if N < max(UN) * 1111:
        _4 = [i for i in UN if i >= int(n[0])]
        for i in _4:
            for j in UN:
                for k in UN:
                    for l in UN:
                        _41 = i * 1000 + j * 100 + k * 10 + l
                        if _41 > N:
                            print(_41)
                            exit()
    else:
        print(min(ex_0) * 10000 + min(UN) * 1111)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = [str(i) for i in input().split()]
ans = N

for i in range(N, 10002):
    if set(list(str(i))) & set(D):
        gg = 1
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N, _ = map(int, input().split())
D = tuple(map(int, input().split()))
total = 0
digit = 1
n = N
while n:
    for i in range(10):
        if i < n % 10 or i in D or (n < 10 and not i):
            continue
        total += digit * i
        break
    n //= 10
    digit *= 10
if total < N:
    for i in range(1, 10):
        if i < n % 10 or i in D:
            continue
        total += digit * i
        break
print(total)

Submission status: Wrong Answer

Solution code:
N, _ = map(int, input().split())
D = tuple(map(int, input().split()))
total = 0
digit = 1
n = N
while n:
    for i in range(10):
        if i < n % 10 or i in D or (n < 10 and not i):
            continue
        total += digit * i
        break
    n //= 10
    digit *= 10
print(total)

Submission status: Wrong Answer

Solution code:
N, _ = map(int, input().split())
D = tuple(map(int, input().split()))
total = 0
digit = 1
n = N
while n:
    for i in range(10):
        if i < n % 10 or i in D:
            continue
        total += digit * i
        break
    n //= 10
    digit *= 10
if total < N:
    for i in range(1, 10):
        if i < n % 10 or i in D:
            continue
        total += digit * i
        break
print(total)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
# list(map(int, input().split()))
N, K = getNM()
intlist = [i for i in range(10)]
D = getList()
for i in D:
    if i in D:
        intlist.pop(intlist.index(i))

anslist = []
def dfs(i, num):
    anslist.append(num)
    if i < 4:
        for j in intlist:
            newnum = int(str(num) + str(j))
            dfs(i + 1, newnum)

for i in intlist[1:]:
    dfs(1, i)

anslist.sort()

for i in anslist:
    if i >= N:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
while True:
    ans = ""
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        for j in range(len(use)):
            if c<=use[j]:
                ans += str(use[j])
                break
    n += 1
    if len(ans) == 0:
        continue
    if int(ans)>=n-1:
        print(ans)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
while True:
    ans = ""
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        for j in range(len(use)):
            if c<=use[j]:
                ans += str(use[j])
                break
    n += 1
    if len(ans) == 0:
        continue
    if int(ans)>=n-1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
while True:
    ans = ""
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        for j in range(len(use)):
            if c<=use[j]:
                ans += str(use[j])
                break
    n += 1
    if len(ans) != 0:
        if int(ans)>=n-1:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
while True:
    ans = ""
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        for j in range(len(use)):
            if c<=use[j]:
                ans += str(use[j])
                break
    if len(ans) != 0:
        if int(ans)>=n:
            break
    n += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
while True:
    ans = ""
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        for j in range(len(use)):
            if c<=use[j]:
                ans += str(use[j])
                break
    if len(ans) != 0:
        if int(ans)>=n:
            break
    else:
        n += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
while True:
    ans = ""
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        for j in range(len(use)):
            if c<=use[j]:
                ans += str(use[j])
                break
    if len(ans) != 0:
        break
    else:
        n += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
n = str(n)
ans = ""
for i in range(len(n)):
    s = int(n[i])
    for j in range(len(able)):
        if able[j] == False:
            continue
        if s<=j:
            ans += str(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

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

a,b = cin()
a = list(str(a))
c = cina()

d = {0,1,2,3,4,5,6,7,8,9}
e = d.difference(c)

s = ""
check = False
for i in a:
  replace = False
  rep = -1
  for j in range(len(c)):
    if int(i)==c[j]:
      replace = True
      break
  if replace:
    for k in e:
      if k>int(i):
        rep = k
        break
  else:
    rep = i  
  if rep == -1 and not check:
  	check = True
  s += str(rep)
if check:
  f = e.difference({0})
  g = list(f)
  g.sort()
  s = ""
  s += str(g[0])
  ap = ""
  if 0 in e:
    ap = '0'*len(a)
  else:
    ap = str(g[0])*len(a)
  s += ap
  
print(s)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
dd = [int(i) for i in input().split()]

flg = False
for i in range(len(str(n))):
    first = int(str(n)[i])
    if flg:
        first = 0
    while first in dd:
        first += 1
        flg = True
    print(first, end="")
print()

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

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

a,b = cin()
a = list(str(a))
c = cina()

d = {0,1,2,3,4,5,6,7,8,9}
e = d.difference(c)

s = ""
check = False
for i in a:
  replace = False
  rep = -1
  for j in range(len(c)):
    if int(i)==c[j]:
      replace = True
      break
  if replace:
    for k in e:
      if k>int(i):
        rep = k
        break
  else:
    rep = i  
  if rep == -1 and not check:
  	check = True
  s += str(rep)
if check:
  f = e.difference({0})
  g = list(f)
  s = ""
  s += str(g[0])
  if 0 in e:
    ap = '0'*len(a)
  else:
    ap = str(g[0])*len(a)
  s += ap
  
print(s)

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

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

a,b = cin()
a = list(str(a))
c = cina()

d = {0,1,2,3,4,5,6,7,8,9}
e = d.difference(c)

s = ""
for i in a:
  replace = False
  rep = -1
  for j in range(len(c)):
    if int(i)==c[j]:
      replace = True
      break
  if replace:
    for k in e:
      if k>int(i):
        rep = k
        break
  else:
    rep = i  
  s += str(rep)
  
print(s)

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

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

a,b = cin()
a = list(str(a))
c = cina()

d = {1,2,3,4,5,6,7,8,9}
e = d.difference(c)

s = ""
for i in a:
  replace = False
  rep = -1
  for j in range(len(c)):
    if int(i)==c[j]:
      replace = True
      break
  if replace:
    for k in e:
      if k>int(i):
        rep = k
        break
  else:
    rep = i  
  s += str(rep)
  
print(s)

Submission status: Wrong Answer

Solution code:
n, k = (int(x) for x in input().split())
ds = [int(x) for x in input().split()]
xs = list(filter(lambda x: x not in ds, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
o = n
m = len(str(n))
ans = 0
c = False
for i in reversed(range(m)):
    d = (o // 10 ** i) % 10
    ys = list(filter(lambda x: x >= d, xs))
    if c:
        y = min(xs)
    else:
        if len(ys) == 0:
            y = min(xs) * 11
            c = True
        else:
            y = min(ys)
            if y > d:
                c = True
    ans += y * 10 ** 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()]
xs = list(filter(lambda x: x not in ds, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
o = n
m = len(str(n))
ans = 0
for i in range(m):
    d = (o // 10 ** i) % 10
    ys = list(filter(lambda x: x >= d, xs))
    if len(ys) == 0:
        y = min(xs)
        o = o - d * 10 ** i + 10 ** (i+1)
    else:
        y = min(ys)
    ans += y * 10 ** i
if ans < n:
    a, b = (xs[0], xs[0]) if xs[0] != 0 else (xs[1], xs[0])
    ans = a * 10 ** m
    for i in range(m):
        ans += b * 10 ** i
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
n=[int(x) for x in str(n)]

ok=[]
for i in range(10):
    if i not in d:
        ok.append(i)

import bisect
for i in range(len(n)-1,-1,-1):
    if n[i]>ok[len(ok)-1]:
        for j in range(i,len(n)):
            n[j]=str(ok[0])
        if i>0:
            n[i-1] += 1
        else:
            if ok[0]==0:
                n.insert(0,str(ok[1]))
            else:
                n.insert(0,str(ok[0]))
    else:
        num=bisect.bisect_left(ok,n[i])
        n[i]=str(ok[num])

n=int(''.join(n))
print(n)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def forgive(num):
    for i in range(10):
        if ((num + i) % 10) in unforgiven:
            continue
        else:
            return num + i


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

price = [int(x) for x in str(N)]
purchase = 0
dig = 0
forgiven = 0
for num in reversed(price):
    forgiven = forgive(num + forgiven // 10)
    purchase += (forgiven % 10) * (10 ** dig)
    dig += 1
else:
    if forgiven >= 10:
        purchase += forgive(1) * (10 ** dig)

print(purchase)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def forgive(num):
    for i in range(10):
        if ((num + i) % 10) in unforgiven:
            continue
        else:
            return num + i


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

price = [int(x) for x in str(N)]
purchase = 0
dig = 0
for num in reversed(price):
    purchase += forgive(num) * (10 ** dig)
    dig += 1

print(purchase)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
price = [int(x) for x in str(N)]
hates = list(map(int, input().split()))
hates.sort()
purchase = []
#print(price)
#print(hates)

def dig_culc(num):
    for i in range(10):
        if ((num + i) % 10) in hates:
            continue
        else:
            purchase.append((num + i) % 10)
            return 1 if (num + i) >= 10 else 0

next_dig = 0 #桁上がり
for num in reversed(price):
    next_dig = dig_culc(num + next_dig)
else:
    if next_dig == 1:
        dig_culc(next_dig)

purchase.reverse()
print(int(''.join([str(x) for x in purchase])))
#result = 0
#for i in range(len(purchase)):
#    result += purchase[i] * (10 ** i)
#print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
price = [int(x) for x in str(N)]
hates = list(map(int, input().split()))
hates.sort()
purchase = []
#print(price)
#print(hates)

def dig_culc(num):
    for i in range(10):
        if ((num + i) % 10) in hates:
            continue
        purchase.append((num + i) % 10)
        return 1 if (num + i) >= 10 else 0

next_dig = 0 #桁上がり
for num in reversed(price):
    next_dig = dig_culc(num + next_dig)
else:
    if next_dig == 1:
        dig_culc(next_dig)

result = 0
for i in range(len(purchase)):
    result += purchase[i] * (10 ** i)

print(result)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = [i for i in input().split()]

flg = True
ans = ''
for n in N:
    if flg:
        st = int(n)
    else:
        st = 0
    for i in range(st, 10):
        if str(i) not in D:
            if i != st:
                flg = False
            ans += str(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = [i for i in input().split()]

flg = True
ans = ''
for n in N:
    if flg:
        st = int(n)
    else:
        st = 0
    for i in range(st, 10):
        if str(i) not in D:
            ans += str(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
# 1の桁から順にチェックする
price = list(map(int, list(str(n))))
hates = list(map(int, input().split()))

dig_add = 0 #桁上がり
purchase = []

def dig_culc(num):
    for j in range(10):
        if ((num + j) % 10) in hates:
            continue
        purchase.append((num + j) % 10)
        return 1 if (num + j) >= 10 else 0

for num in reversed(price):
    dig_add = dig_culc(num + dig_add)

if dig_add == 1:
    dig_culc(dig_add)

result = 0
for i in range(len(purchase)):
    result += purchase[i] * (10 ** i)
print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
# 1の桁から順にチェックする
price = list(map(int, list(str(n))))
hates = list(map(int, input().split()))

dig_add = 0 #桁上がり
purchase = []

for num in reversed(price):
    num += dig_add
    dig_add = 0

    for j in range(10):
        if ((num + j) % 10) in hates:
            continue

        purchase.append((num + j) % 10)
        dig_add = 1 if (num + j) >= 10 else 0
        break
purchase.append(dig_add)

result = 0
for i in range(len(purchase)):
    result += purchase[i] * (10 ** i)
print(result)

Submission status: Wrong Answer

Solution code:
inputNK = input().split(" ")
N = int(inputNK[0])
K = int(inputNK[1])
 
dislike = input().split(" ")
judge = True
answer = 0
 
for i in range(N,10000):
	for number in dislike:
		if str(i).count(number) != 0:
			judge = False
			break
	if judge == True:
		answer = i
		break
	else:
		judge = True
 
print(answer)

Submission status: Wrong Answer

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

dislike = input().split(" ")
judge = True
answer = 0

for i in range(N,10000):
	for number in dislike:
		if str(i).count(number) != 0:
			judge = False
			break
	if judge == True:
		answer = i
		break
	else:
		judge = True

print(i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
N, K = map(int, input().split())
D = set((map(int, input().split())))
ok = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - D)
def dfs(s):
    if N <= int(s):
        return int(s)
    for i in range(len(ok)):
        return dfs(s+str(ok[i]))
start = ok[0] if ok[0] != 0 else ok[1]
print(dfs(str(start)))

Submission status: Wrong Answer

Solution code:
from collections import deque
n, k = map(int, input().split())
D = list(map(int, input().split()))
ok_lst = [x for x in range(0, 10) if x not in D]
stack = deque([x for x in ok_lst if x != 0])
while len(stack) > 0:
    now_num = stack.popleft()
    print(now_num)
    if now_num >= n:
        break
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        stack.append(int(next_num))

Submission status: Wrong Answer

Solution code:
from collections import deque
n, k = map(int, input().split())
D = list(map(int, input().split()))
ok_lst = [x for x in range(0, 10) if x not in D]
stack = deque([x for x in ok_lst if x != 0])
while len(stack) > 0:
    now_num = stack.popleft()
    print('now', now_num)
    if now_num >= n:
        break
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        stack.append(int(next_num))

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
D = list(map(int, input().split()))
OK = list({1, 2, 3, 4, 5, 6, 7, 8, 9} - set(D))

S = str(N)
ans = []


def find_next(x):
    while True:
        x += 1
        if x in OK:
            return str(x)


for i in range(len(S)):
    if int(S[i]) in OK:
        ans += S[i]
    elif max(OK) > int(S[i]):
        ans += find_next(int(S[i]))
        for _ in range(len(S) - len(ans)):
            ans += "0"
        break
    else:
        if i == 0:
            a = str(min(OK)) + "0"
            ans.append(a)
        else:
            ans[i - 1] = find_next(int(ans[i - 1]))

        for _ in range(len(S) - len(ans)):
            ans += "0"
        break

print("".join(ans))

Submission status: Wrong Answer

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

x = 0
y = 0
while x <4:
    if n // (10**x) >0:
        y = x
    x += 1

i = 0
a = [0]
m = 0
while i <= y:
    a.append(((n//(10**(y-i)))%10))
    i +=1

i = 0
t = 0
while i <= y + t:
    j = 0
    while j < k:
        if a[y-i+1] == d[j]:
            a[y-i+1] += 1
            if y-i+1 < y+1:
                a[y-i+2] = d[0]
        if a[y-i+1] == 10:
            a[y-i+1] = 0
            a[y-i] +=1
        j+=1
    i+=1
    if a[0] == 1 and t == 0:
        i = 1
        while i<=y+1:
            a[i] = 0
        i = 0
        t = 1
        continue

i = 0
while i <= y + t:
    m += a[y-i+1]*(10**(i))
    i+=1


print(m)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
OK = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - set(D))

S = str(N)
ans = ""
for i in range(len(S)):
    for j in OK:
        if j == int(S[i]):
            ans += str(j)
            break
        elif j > int(S[i]):
            ans += str(j)
            for _ in range(len(S)-len(ans)):
                ans += str(min(OK))
            print(ans)
            exit(0)

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
OK = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - set(D))

S = str(N)
ans = ""
for i in range(len(S)):
    for j in OK:
        if j >= int(S[i]):
            ans += str(j)
            break

print(ans)