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 sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
d = na()
s = str(n)

ans = []
for i in range(len(s)):
    ok = False
    for j in range(0, 10):
        if j >= int(s[i]) and j not in d:
            flag = False
            if i + 1 < len(s):
                for k in range(int(s[i + 1]), 10):
                    if k not in d:
                        flag = True
            else:
                flag = True
            
            if flag:
                ans.append(j)
                ok = True
                break
    if not ok:
        ans = []
        for j in range(10):
            if j not in d:
                for k in range(len(s) + 1):
                    ans.append(j)
                break

print(*ans, sep="")

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
d = na()
s = str(n)

ans = []
for i in range(len(s)):
    for j in range(0, 10):
        if j >= int(s[i]) and j not in d:
            flag = False
            if i + 1 < len(s):
                for k in range(int(s[i + 1]), 10):
                    if k not in d:
                        flag = True
            else:
                flag = True
            
            if flag:
                ans.append(j)
                break

print(*ans, sep="")

Submission status: Wrong Answer

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

for i in range(n,10001):
     for x in d:
         if str(x) in str(i):
             break
     else:
         print(i)
         break

Submission status: Wrong Answer

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

for i in range(n,10001):
     for x in d:
         if str(x) in str(i):
             break
     else:
         print(i)
         break

Submission status: Wrong Answer

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

ans, i, OK = str(N), 0, False
while not OK:
    OK = True
    digit = len(ans)
    for i in range(digit):
        if ans[i] in D:
            ans = str(int(ans) + 10 ** (digit - i - 1))
            OK = False
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n,k = map(int,input().split())
dn = list(map(int,input().split()))
d = set([0,1,2,3,4,5,6,7,8,9])
for i in dn:
    d.remove(i)
d = list(d)
 
def dfs( s , n ):
    i = 0
    if len(s) == n:
        ans.append(s)
        return
    else:
        a = int(s[len(s)-1])
        for j in d:
            dfs( s + str(j) , n )

ans = []
for j in d:
    a = str(j)
    dfs( a , 5 )
    
for i in ans:
    if int(i) >= n:
        print(int(i))
        break

Submission status: Wrong Answer

Solution code:
import sys
n,k = map(int,input().split())
dn = list(map(int,input().split()))
d = set([0,1,2,3,4,5,6,7,8,9])
for i in dn:
    d.remove(i)
d = list(d)
 
def dfs( s , n ):
    i = 0
    if len(s) == n:
        ans.append(s)
        return
    else:
        a = int(s[len(s)-1])
        for j in d:
            dfs( s + str(j) , n )

ans = []
for j in d:
    a = str(j)
    dfs( a , 4 )
    
for i in ans:
    if int(i) >= n:
        print(int(i))
        break

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
hates = list(map(str, input().split()))
for i in range(N, 10000):
    nums = list(str(i))
    com = set(nums) & set(hates)
    if len(com) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
hates = list(map(str, input().split()))

for i in range(N, 9999):
    nums = list(str(i))
    com = set(nums) & set(hates)
    if len(com) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
hates = list(map(str, input().split()))
for i in range(N, 9999):
    nums = list(str(i))
    com = set(nums) & set(hates)
    if len(com) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
hates = list(map(str, input().split()))
for i in range(N, 9999):
    nums = list(str(i))
    com = set(nums) & set(hates)
    print(com)
    if len(com) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
# ABC042C

n, k = map(int, input().split())
d = list(map(int, input().split()))
digits = set(range(10)) - set(d)
ans = []
for s in reversed(str(n)):
    for d in digits:
        if int(s) <= d:
            ans.insert(0, str(d))
            break
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
lis=list(map(int,input().split()))
hate=list(map(int,input().split()))
a=str(lis[0])
love=[]
ans=0
sw=0
swn=0
for i in range(10):
  if i not in hate:
    love+=[i]
for i in a:
  if sw!=1:
    n=int(i)
    for j in love:
      if j==n:
        ans=ans*10+j
      elif j>n:
        ans=ans*10+j
        sw=1
  else:
    ans=ans*10+love[0]
  if ans>=lis[0]:
    swn=1
print(int(ans))

Submission status: Wrong Answer

Solution code:
def main():
  N, K = (int(_) for _ in input().split())
  D = [int(_) for _ in input().split()]
  n = set(range(0, 10))
  n = list(n - set(D))
  m = list(set(n + [0]))
  ret = 10 ** 10
  for a in m:
    for b in n:
      for c in n:
        for d in n:
          for e in n:
            cc = int(str(a) + str(b) + str(c) + str(d) + str(e))
            if cc >= N:
              ret = min(ret, cc)
  print(ret)
  return

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=set(list(map(str,input().split())))
print(d)
for i in range(n,10*n):
    flag=0
    sn=str(i)
    for j in sn:
        if j in d:
            flag=1
    if flag==0:
        print(i)
        exit()

Submission status: Wrong Answer

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

for i in range(n,100*n):
    flag=0
    sn=str(i)
    for j in sn:
        if j in d:
            flag=1
    if flag==0:
        print(i)
        exit()

Submission status: Wrong Answer

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

for i in range(n,100*n):
    flag=0
    sn=str(n)
    for j in sn:
        if j in d:
            flag=1
    if flag==0:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=set(list(map(int,input().split())))
dd=set([0,1,2,3,4,5,6,7,8,9])
ddd=dd-d

keta=len(str(n))
kuriage=0
result=""
for i in range(1,keta+1):
    x=int(str(n)[keta-i])

    if kuriage==1:
        x+=1
        kuriage=0
    if x==10:
        kuriage=1
    
    temp=10
    for j in ddd:
        if j>=x:
            temp=min(temp,j)
    
    if temp==10:
        kuriage=1

    if kuriage==0:
        result=str(temp)+result
    else:
        result=str(min(list(ddd)))+result

if kuriage==1:
    result=str(min(list(ddd)))+result

print(result)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
for i in range(10001):
  nn = n+i
  cnt = 0
  for j in d:
    if str(j) in str(nn):
      break
    else:
      cnt += 1
  if cnt == len(d):
    print(nn)
    break

Submission status: Wrong Answer

Solution code:
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,k=INPUT()
A=INPUT()
accepted=[]
for i in range(10):
    if i not in A:
        accepted.append(i)
L=len(accepted)
x=str(n)
X=[int(x[i]) for i in range(len(x))]
for i in range(len(x)):
    if X[i] in A:
        for j in range(L):
            if X[i]<accepted[j]:
                X[i]=accepted[j]
                break
for ele in X:
    print(int(ele),end="")

Submission status: Wrong Answer

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


for i in range(10001):
    if i >= int(N):
        ans=str(i)
        num=0
        for j in range(len(ans)):
            if int(ans[j]) not in listA:
                num += 1

            if num == len(ans):
                print(i)
                exit()

Submission status: Wrong Answer

Solution code:
import sys

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

for n in range(N, 10000, 1):
    L = list(str(n))
    flg = 0
    for l in L:
        if (l in D) or n<N:
            flg = 1
            break
    if flg==0:
        print(n)
        sys.exit()

Submission status: Wrong Answer

Solution code:
n,k,*d=map(int,open(0).read().split())
c=0
for i in range(10000):
  if n<=i:
    for j in str(i):
      if not int(j) in d:
        c+=1
      if c==len(str(i)):
        print(i)
        exit()
    c=0

Submission status: Wrong Answer

Solution code:
n,k,*d=map(int,open(0).read().split())
c=0
for i in range(10000):
  if n<=i:
    for j in str(i):
      if not int(j) in d:
        c+=1
      if c==len(str(i)):
        print(i)
        break
    else:
      c=0
      continue
    break

Submission status: Wrong Answer

Solution code:
from collections import deque

n, k = map(int, input().split())
org = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
kod = set(map(int, input().split()))
ele = list(org ^ kod)
que = deque(ele)

if n < 10:
    for i in ele:
        if i >= n:
            print(i)
            exit()

while que:
    x = que.popleft()
    for i in ele:
        y = 10 * x + i
        if y >= n:
            print(y)
            exit()
        else:
            que.append(y)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, k = map(int, input().split())
org = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
kod = set(map(int, input().split()))
ele = list(org ^ kod)
que = deque(ele)

while que:
    x = que.popleft()
    for i in ele:
        y = 10 * x + i
        if y >= n:
            print(y)
            exit()
        else:
            que.append(y)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, k = map(int, input().split())
org = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
kod = set(map(int, input().split()))
ele = list(org ^ kod)
que = deque(ele)

while que:
    x = que.popleft()
    for i in ele:
        y = 10 * x + i
        if y > n:
            print(y)
            exit()
        else:
            que.append(y)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
def calc():
    global N, D
    while(True):
        for i in D:
            if str(i) in str(N):
                N += 1
                break
            return
calc()
print(N)

Submission status: Wrong Answer

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

kl = [int(x) for x in input().split()]


ans = []

for i in range(10):
    if i not in kl:
        a = n*i
        b = [str(x) for x in str(a)]
        count = 0
        for j in range(len(b)):
            if b[j] not in kl:
                count += 1
        if count == len(b):
            ans.append(a)
                
ans.sort()
minnum = ans[0]
if minnum == 0:
    minnum == ans[1]

print(minnum)

Submission status: Wrong Answer

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

kl = [int(x) for x in input().split()]

ans = []

for i in range(10):
    if i not in kl:
        a = n*i
        b = [str(x) for x in str(a)]
        for j in range(len(b)):
            if b[j] not in kl:
                ans.append(a)
ans.sort()
if min(ans) != 0:
    print(min(ans))
else:
    print(ans[1])

Submission status: Wrong Answer

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

flag = False

for i in range(N,10000):
    N = i
    while i > 0:
        flag = True
        if i%10 in D:
            flag = False
            break
        else:
            i //=10

    if flag == True:
        print(N)
        break

Submission status: Wrong Answer

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

for i in range(N, 10000):
    if len(list(set(D) & set(str(i)))) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
a, b = map(int, input('').split(' '))
c = input('').split(' ')
for i in range(a, 10000):
	for j in range(len(str(i))):
		if str(i)[j] in c:
			break
	else:
		print(i)
		break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
strN = str(N)
setN = set(list(map(int, strN)))
setD = set(D)


if len(setN.intersection(setD)) == 0:
    print(N)
    exit()

usable = [v for v in range(0, 10) if v not in D]

# print(N)
# print(usable)
# print(D)

# 末尾から順番に決める
ans = ""
for id, j in enumerate(strN[::-1]):
    if int(j) in usable:
        ans += j
    else:
        flag = False
        for k in usable:
            if k >= int(j):
                ans += "{}".format(k)
                flag = True
                break
        if not flag:
            ans += "{}".format(min(usable))


print(ans[::-1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

from collections import deque

N, K = mi()
D = list(map(str, sys.stdin.readline().split()))

for num in range(N+1, N*10):
    flag = 1
    s = str(num)
    for i in range(K):
        if s.count(D[i]):
            flag = 0
            break
    if flag:
        print(num)
        exit()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
#from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    #que = deque(r[1:])
    que = r[1:]
else:
    #que = deque(r)
    que = r

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    #if que[-1] >= 10**6:
        #break
    i += 1

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
#from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    #que = deque(r[1:])
    que = r[1:]
else:
    #que = deque(r)
    que = r

i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    #if que[-1] >= 10**6:
        #break
    i += 1

Submission status: Wrong Answer

Solution code:
a = input('')
b = input('')
num = b.split(' ')
price = int(a.split(' ')[0])
f = False
for i in range(price, 10000):
	for j in range(len(str(i))):
		if str(i)[j] in num:
			break
	else:
		break
print(i)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = N
while True:
  tmp = n
  ng = False
  while tmp > 0:
    ng = ng or tmp%10 in D
    tmp //= 10
  if ng:
    break
  n += 1
print(n)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def next(v, cu):
	for i in cu:
		if i >= v:
			return i
	else:
		return -1

def main():
	n, k = IN()
	al = list(IN())
	cu=[]
	for i in range(10):
		if i not in al:
			cu.append(i)
	non_zero_min = cu[0] if cu[0] > 0 else cu[1]
	is_cu0_is_0 = cu[0]==0
	
	if n < 10:
		if n in cu:
			return n
		if n > cu[-1]:
			return non_zero_min*10+cu[0]
	
	kiriage=False
	ret=[]
	for i, v in enumerate(str(n)):
		if kiriage:
			ret.append(cu[0])
		elif int(v) in cu:
			ret.append(v)
		else:
			kiriage=True
			n = next(int(v),cu)
			if n == -1:
				ret.append(cu[0])
				for ic in range(i,-1,-1):
					t=ret[ic]
					nt = next(t,cu)
					if nt != -1:
						ret[ic]=nt
						break
					elif nt == -1 and ic == 0:
						ret[ic]=str(non_zero_min)+str(cu[0])
					else:
						ret[ic]=c[0]
			else:
				ret.append(n)
	return ''.join([str(r) for r in ret])
			
			
			
			
			
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()

q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
while q:
    a = q.popleft()
    # print(q)

    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        # if len(b) == 0 and d == 0:
        #     pass
        # else:
        b += str(d)
        q.append(b)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()

q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
while q:
    a = q.popleft()
    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        if len(b) == 0:
            if d == 0:
                continue
        b += str(d)
        q.append(b)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(input().split())
ans = n
while True:
    flag = False
    for i in d:
        if flag :break
        if i in str(ans):
            x = len(str(ans)) - str(ans).index(i) - 1
            ans += 10**x
            flag = True
    if flag:continue
    print(ans)
    break

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
A=[0,1,2,3,4,5,6,7,8,9]
for i in range(0,K):
    A.remove(D[i])
A=sorted(A)
B=A
B.append(0)
ans=0
M=str(N)
L=len(M)
if A[0]==0:
    ans+=111111*A[1]
else:
    ans+=111111*A[0]

if L==5:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    for t in range(0,10-K):
                        for y in range(0,10-K):
                            if ans>=1000*(100*B[q]+10*A[w]+A[e])+100*A[r]+10*A[t]+A[y]>=N:
                                ans=1000*(100*B[q]+10*A[w]+A[e])+100*A[r]+10*A[t]+A[y]
elif L==4:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    for t in range(0,10-K):
                        if ans>=100*(100*B[q]+10*A[w]+A[e])+10*A[r]+A[t]>=N:
                            ans=100*(100*B[q]+10*A[w]+A[e])+10*A[r]+A[t]
elif L==3:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    if ans>=10*(100*B[q]+10*A[w]+A[e])+A[r]>=N:
                        ans=10*(100*B[q]+10*A[w]+A[e])+A[r]
elif L==2:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                if ans>=100*B[q]+10*A[w]+A[e]>=N:
                    ans=100*B[q]+10*A[w]+A[e]
else:
    for q in range(0,11-K):
        for w in range(0,10-K):
            if ans>=10*B[q]+A[w]:
                ans=10*B[q]+A[w]

print(ans)

Submission status: Wrong Answer

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

i = N
while True:
  flg = True
  for j in str(i):
    if int(j) in D:
      flg = False
      break

  if flg == True:
    print(i)
    exit()

  i += 1

Submission status: Wrong Answer

Solution code:
# C - こだわり者いろはちゃん
# https://atcoder.jp/contests/abc042/tasks/arc058_a

# 入力 1
# 1000 8
# 1 3 4 5 6 7 8 9

N,K = input().split()
D = input().split()

# Nの各桁をみて、嫌いな数字が入っていないかチェック
# 嫌いな数字が入っていたら、その桁をインクリメントして、整数(N)を再生性する。
# これを嫌いな数字がなくなるまで繰り返す。

nums = [n for n in N] # 各桁

i = 1

# 嫌いな数字が入っていたら、その桁をインクリメントして、整数(N)を再生性する。
while i != 0:
    tmp = []
    j = 0
    for num in nums :
        if num in D:
            tmp.append(str(int(num) + 1))
            j = 1
        else :
            tmp.append(num)
    
    # 嫌いな数字があったか判定
    if j == 1:
        i = 1
        nums = "".join(tmp)
    else :
        print("".join(tmp))
        exit()

Submission status: Wrong Answer

Solution code:
# C - こだわり者いろはちゃん
# https://atcoder.jp/contests/abc042/tasks/arc058_a

# 入力 1
# 1000 8
# 1 3 4 5 6 7 8 9

print("test")

N,K = input().split()
D = input().split()

# Nの各桁をみて、嫌いな数字が入っていないかチェック
# 嫌いな数字が入っていたら、その桁をインクリメントして、整数(N)を再生性する。
# これを嫌いな数字がなくなるまで繰り返す。

nums = [n for n in N] # 各桁

i = 1

# 嫌いな数字が入っていたら、その桁をインクリメントして、整数(N)を再生性する。
while i != 0:
    tmp = []
    j = 0
    for num in nums :
        if num in D:
            tmp.append(str(int(num) + 1))
            j = 1
        else :
            tmp.append(num)
    
    # 嫌いな数字があったか判定
    if j == 1:
        i = 1
        nums = "".join(tmp)
    else :
        print("".join(tmp))
        exit()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
d = list(input().split())
for check in range(n, 10 ** 4 + 1):
    flag = True
    for i in str(check):
        if i in d:
            flag = False
            break
    if flag:
        print(check)
        exit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
A=[0,1,2,3,4,5,6,7,8,9]
for i in range(0,K):
    A.remove(D[i])
A=sorted(A)
ans=999999
#小さい順に数字を作る
for q in range(0,10-K):#100000担当
    for w in range(0,10-K):#10000担当
        for e in range(0,10-K):#1000担当
            for r in range(0,10-K):#100担当
                for t in range(0,10-K):#10担当
                    for y in range(0,10-K):#1担当
                        if ans>=100000*A[q]+10000*A[w]+1000*A[e]+100*A[r]+10*A[t]+A[y]>=N:
                            ans=100000*A[q]+10000*A[w]+1000*A[e]+100*A[r]+10*A[t]+A[y]
                        else:
                            pass
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
A=[0,1,2,3,4,5,6,7,8,9]
for i in range(0,K):
    A.remove(D[i])
A=sorted(A)
ans=99999
#小さい順に数字を作る
for q in range(0,10-K):#100000担当
    for w in range(0,10-K):#10000担当
        for e in range(0,10-K):#1000担当
            for r in range(0,10-K):#100担当
                for t in range(0,10-K):#10担当
                    for y in range(0,10-K):#1担当
                        if ans>=100000*A[q]+10000*A[w]+1000*A[e]+100*A[r]+10*A[t]+A[y]>=N:
                            ans=100000*A[q]+10000*A[w]+1000*A[e]+100*A[r]+10*A[t]+A[y]
                        else:
                            pass
print(ans)

Submission status: Wrong Answer

Solution code:
# C - こだわり者いろはちゃん
# https://atcoder.jp/contests/abc042/tasks/arc058_a

# 入力 1
# 1000 8
# 1 3 4 5 6 7 8 9

N,K = input().split()
D = input().split()

one_to_ten = ["0","1","2","3","4","5","6","7","8","9","10"]
can_use = list(set(one_to_ten) - set(D))
can_use = sorted([int(c) for c in can_use])

print(can_use)
tmp = []

for n in N:
    i = 0
    if n in can_use:
        tmp.append(n)
    else :
        tmp.append(can_use[0])
    i = i + 1

tmp[0] = can_use[1]
tmp = [str(t) for t in tmp]
print("".join(tmp))

Submission status: Wrong Answer

Solution code:
# C - こだわり者いろはちゃん
# https://atcoder.jp/contests/abc042/tasks/arc058_a

# 入力 1
# 1000 8
# 1 3 4 5 6 7 8 9

N,K = input().split()
D = input().split()

one_to_ten = ["0","1","2","3","4","5","6","7","8","9","10"]
can_use = list(set(one_to_ten) - set(D))

print(can_use)
tmp = []

for n in N:
    i = 0
    if n in can_use:
        tmp.append(n)
    else :
        tmp.append(can_use[0])
    i = i + 1
    
print("".join(tmp))

Submission status: Wrong Answer

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

dislikes = [int(i) for i in input().split(' ')]

final_res = []

num = 0
for ch in str(N):
    num = int(ch)
    while True:
        if num in dislikes:
            num += 1
        else:
            final_res.append(num)
            break


for i in final_res:
    print(i, end = '')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# 全探索だが、Nを超える場合があるので注意
n,k = map(int,input().split())
s = str(n)
d = list(map(int,input().split()))
#すでにsortされている
convert = [0]*10 # convert[i] はi 以上で使える数字ないなら10
for j in range(10):
    i = j
    while True:
        if i not in d: break
        elif i == 10: 
            break
        else: i += 1
    convert[j] = i
#print(convert,d)
min_use = min(convert)#最小の使えるやつ
kuriagari = 0
out = ""
for i in range(len(s)):#１の位から見ていく
    digit = kuriagari + int(s[-1-i])
    if digit >= 10 or convert[digit] == 10:
        out = str(min_use)+out
        kuriagari = 1
    else:
        out = str(convert[digit]) + out
        kuriagari = 0
for i in range(10):
    if convert[i] != 0:
        min_use = convert[i]
if kuriagari == 1:
    out = str(convert[1])+out
print(out)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# 全探索だが、Nを超える場合があるので注意
n,k = map(int,input().split())
s = str(n)
d = list(map(int,input().split()))
#すでにsortされている
convert = [0]*10 # convert[i] はi 以上で使える数字ないなら10
for j in range(10):
    i = j
    while True:
        if i not in d: break
        elif i == 10: 
            break
        else: i += 1
    convert[j] = i
#print(convert,d)
min_use = min(convert)#最小の使えるやつ
kuriagari = 0
out = ""
for i in range(len(s)):#１の位から見ていく
    digit = kuriagari + int(s[-1-i])
    if digit >= 10 or convert[digit] == 10:
        out = str(min_use)+out
        kuriagari = 1
    else:
        out = str(convert[digit]) + out
        kuriagari = 0
convert.sort()
if kuriagari == 1:
    if min_use != 0:
        out = str(min_use)+out
    else: out = str(convert[1])+out
print(out)