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: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
A = [i for i in range(10)]
A = set(A) - set(D)
A = list(A)
A.sort()
S = str(N)
s = ''
for i in range(len(S)):
    for j in range(len(A)):
        if int(S[i]) <= A[j]:
            s += str(A[j])
            break
if len(s) == len(S):
    print(s)
else:
    if A[0] == 0:
        s = str(A[1])
        for i in range(len(S)):
            s += str(A[0])
    else:
        s = str(A[0])
        for i in range(len(S)):
            s += str(A[1])
    print(s)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
A = [i for i in range(10)]
A = set(A) - set(D)
A = list(A)
A.sort()
S = str(N)
s = ''
for i in range(len(S)):
    for j in range(len(A)):
        if int(S[i]) <= A[j]:
            s += str(A[j])
            break
if len(s) == len(S):
    print(s)
else:
    if A[0] == 0:
        s = A[1]
        for i in range(len(S)):
            s += A[0]
    else:
        s = A[0]
        for i in range(len(S)):
            s += A[1]
    print(s)

Submission status: Runtime Error

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

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[0] for i in range(len(N_list))+1]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[0] for i in range(len(N_list))]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            i += 1
            ans[j] = use[i]
        mapans = map(str,ans)
        x = int(''.join(mapans))

    print(x)

Submission status: Runtime Error

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

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[0] for i in range(len(N_list))+1]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[0] for i in range(len(N_list))]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            ans[j] = use[i]
            i += 1
    mapans = map(str,ans)
    x = int(''.join(mapans))

    print(x)

Submission status: Runtime Error

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

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[0] for i in range(len(N_list))+1]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[0] for i in range(len(N_list))]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    print(x)
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            ans[j] = use[i]
            i += 1
    mapans = map(str,ans)
    x = int(''.join(mapans))

    print(x)

Submission status: Runtime Error

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

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[0] for i in range(len(N_list))+1]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[0] for i in range(len(N_list))]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    print(x)
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            ans[j] = use[i]
            # i += 1
            # print(use)
            # print(ans[j])
    mapans = map(str,ans)
    x = int(''.join(mapans))

    print(x)

Submission status: Runtime Error

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

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans.append(use[1])
        ans = [use[0] for i in range(len(N_list))]
    mapans = map(str,ans)
    x = int(''.join(mapans))
    print(x)
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans.append(use[1])
        ans = [use[0] for i in range(len(N_list)-1)]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            ans[j] = use[i]
            i += 1
        mapans = map(str,ans)
        x = int(''.join(mapans))
    print(x)

Submission status: Runtime Error

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

num_exclude = list(map(int, input().split()))

dec_num = [i for i in range(0, 10)]

able_use_num_lis = list(map(str, set(dec_num) - set(num_exclude)))

num_len = len(str(N))

output_list = []

def dfs(cur, num, able_use_num_lis):
    if num != '':
        if int(num) >= N:
            output_list.append(int(num))
    if len(str(N)) == cur:
        return
    
    for add_num in able_use_num_lis:
        ret = dfs(cur + 1, num + add_num, able_use_num_lis)
    return output_list

print(min(dfs(0, '', able_use_num_lis)))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
D=list(map(int, input().split()))
num=[0,1,2,3,4,5,6,7,8,9]
M=[]
N=list(str(n))
for i in D:
    num.remove(int(i))
for k in num:
    if k>=int(N[0]) and k!=0:
        M.append(str(k))
        N.pop(0)
        for j in N:
            m=[]
            for l in num:
                if l>=int(j):
                    m.append(l)
            M.append(str(min(m)))
print("".join(M))

Submission status: Runtime Error

Solution code:

n, m = [ int(v) for v in input().split() ]
num_list = [ v for v in input().split() ]
t = n
while:
	if all([ ( v not in num_list ) for v in list(str(i))]):
		print(i)
		break
	t += 1

Submission status: Runtime Error

Solution code:
def equal(n, available):
  return n in available 

def less(n, available):
  return n < sorted(available)[0]

def greater(n, available):
  return n > sorted(available, reverse=True)[0]
  

#less(n, available) == True であること
def upper_next(n, available):  
  for v in sorted(available):
    if n < v:
      return v
  return 1/0

  
n_str, _ = [v for v in input().split()]
n_s = [0]
n_s.extend([int(n_str[i:i+1]) for i in range(len(n_str))])

d_s = [int(v) for v in input().split()]

available = set(list(range(10))) - set(d_s)

#print("n", n_s, "d", d_s, "u", available)

min_available = sorted(available)[0]

ans = [0]
ans.extend([min_available] * (len(n_s) - 1))

eq = True
for i in range(1, len(n_s)):
  if eq:
    if equal(n_s[i], available):
      ans[i] = n_s[i]
      continue
    else:
      eq = False
      if less(n_s[i], available):
        ans[i] = upper_next(n_s[i], available)
        #残りは最小値詰め
        break
      else:
        for j in range(i - 1, -1, -1):
          if greater(ans[j], available):
            ans[j] = min_available
          else:
            ans[j] = upper_next(ans[j], available)
            break
        break

begin = 0
if ans[0] == 0:
  begin = 1
ans_val = "".join(map(lambda x:str(x), ans[begin:]))

print(ans_val)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
b=True
while b:
  b1=False
  l1=list(str(n))
  for i in l1:
    if i in l:
      b1=True
  if b1=False:
    b=True
    print(n)
    break
  else:
    n+=1

Submission status: Runtime Error

Solution code:
N, K = input().split()
D = [i for i in input().split()]
NUM = '0123456789'
num = [i for i in NUM if i not in D]
ans = ''
for j in range(len(N)):
    if int(N[j]) > int(max(num)):
        ans = ''
        ans += num[1]
        ans = int(ans.ljust(len(N)+1, min(num)))
        break
    for i in range(len(num)):
        if int(N[j]) <= int(num[i]):
            ans += num[i]
            break
    if int(ans.ljust(len(N), min(num))) > int(N):
        ans = int(ans.ljust(len(N), min(num)))
        break
print(ans)

Submission status: Runtime Error

Solution code:
N, K = input().split()
D = [i for i in input().split()]
NUM = '0123456789'
num = [i for i in NUM if i not in D]
ans = ''
for j in range(len(N)):
    if int(ans.ljust(len(N), min(num))) > int(N):
        ans = int(ans.ljust(len(N), min(num)))
        break
    elif int(N[j]) <= int(max(num)):
        ans += num[1]
        ans = int(ans.ljust(len(N)+1, min(num)))
        break
    for i in range(len(num)):
        if int(N[j]) <= int(num[i]):
            ans += num[i]
            break
    print(ans)
print(ans)

Submission status: Runtime Error

Solution code:
N, K = input().split()
D = [i for i in input().split()]
NUM = '0123456789'
num = [i for i in NUM if i not in D]
ans = ''
for j in range(len(N)):
    if int(ans.ljust(len(N), min(num))) > int(N):
        ans = int(ans.ljust(len(N), min(num)))
        break
    elif int(N[j]) <= int(max(num)):
        ans += num[1]
        ans = int(ans.ljust(len(N)+1, min(num)))
        break
    for i in range(len(num)):
        if int(N[j]) <= int(num[i]):
            ans += num[i]
            print(ans)
            break
    print(ans)
print(ans)

Submission status: Runtime Error

Solution code:
N, K = input().split()
D = [i for i in input().split()]
NUM = '0123456789'
num = [i for i in NUM if i not in D]
ans = ''
print(num)
for j in range(len(N)):
    if int(ans.ljust(len(N), min(num))) > int(N):
        ans = int(ans.ljust(len(N), min(num)))
        break
    elif int(N[j]) <= int(max(num)):
        ans += num[1]
        ans = int(ans.ljust(len(N)+1, min(num)))
        break
    for i in range(len(num)):
        if int(N[j]) <= int(num[i]):
            ans += num[i]
            print(ans)
            break
    print(ans)
print(ans)

Submission status: Runtime Error

Solution code:
N, K = input().split()
D = [i for i in input().split()]
NUM = '0123456789'
num = [i for i in NUM if i not in D]
ans = ''
a = []
for j in range(len(N)):
    for i in range(len(num)):
        if int(N[j]) <= int(num[i]):
            ans += num[i]
            break
a.append(int(ans))
ans = ''
for j in range(len(N)):
    if j == 0:
        for i in range(len(num)):
            if int(N[j]) <= int(num[i]):
                ans += num[i]
                break
    else:
        ans += min(num)
a.append(int(ans))
print(min(a) if min(a) >= int(N) else max(a))

Submission status: Runtime Error

Solution code:
N,K = map(str, input().split())
D = set(map(int,input().split()))
E = {0,1,2,3,4,5,6,7,8,9}
F = E - D
f = max(F)
swith = 0
if 0 in F:
    g =str(list(F)[1])
else:
    g = str(min(F))
list = N.split()
length = len(N)
for n in range(length):
    if int(N[n]) in D:
        swith = 1
        for l in range(n+1,length):
             list[l] = str(min(F)) 
        if int(N[n]) >= f:
              list[n] = str(min(F))
              if n == 0:
                     list.insert(0,str(g))
        else:
              H = {}
              H = set(range(int(N[n]) + 1))
              list[n] =  str(min(F - H))
    if swith == 1:
        break
print(''.join(list))

Submission status: Runtime Error

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

N, K = map(int, input().split())
L = [int(v) for v in input().split()]
no = [v for v in range(10) if v not in L]

s = list(map(int, str(N)))

for i in range(len(s)):
    if i == 0:
        if s[i] in L:
            s[i] = min([v for v in no if v != 0 and v > s[i]])
    else:
        if s[i] in L:
            s[i] = min([v for v in no if v > s[i]])
            
print("".join(map(str, s)))

Submission status: Runtime Error

Solution code:
import itertools
D=[]
DN=[]
the_string = input()
N, K = the_string.split()
K= int(K)
for x in range(K):
    D.append(input())
for x in range(10):
  if(str(x) in D):
    continue
  else:
    DN.append(x)
DList=list(itertools.product(DN,repeat=len(N)))
res=0
for x in DList:
    num1=int(''.join(map(str, x)))
    if num1>=int(N):
        res=num1
        break
if(res<int(N)):
    DList=list(itertools.product(DN,repeat=len(N)+1))
    res=0
    for x in DList:
        num1=int(''.join(map(str, x)))
        if num1>=int(N):
            res=num1
            break
print(res)

Submission status: Runtime Error

Solution code:
import itertools
D=[]
DN=[]
N= input()
K= int(input())
for x in range(K):
    D.append(input())
for x in range(10):
  if(str(x) in D):
    continue
  else:
    DN.append(x)
DList=list(itertools.product(DN,repeat=len(N)))
res=0
for x in DList:
    num1=int(''.join(map(str, x)))
    if num1>=int(N):
        res=num1
        break
if(res<int(N)):
    DList=list(itertools.product(DN,repeat=len(N)+1))
    res=0
    for x in DList:
        num1=int(''.join(map(str, x)))
        if num1>=int(N):
            res=num1
            break
print(res)

Submission status: Runtime Error

Solution code:
#C問題
N, K = map(int, input().split())

D = []
D = list(map(int, input().split()))

num = []
for i in range(10):
    if i not in D:
        num.append(i)

N_num = []
while True:
    if N ==0:
        break
    N_num.append(N%10)
    N = N//10

N_num.sort(reverse = True)

ans = []
for i in N_num:
    for k in range(len(num)):
        if num[k] >= i:
            ans.append(num[k])
            break
        elif k == len(num):
            ans.append(k)
            ans[k-1] = num[k+1]
map(str, ans)
ans = int("".join(map(str, ans)))
print(ans)

Submission status: Runtime Error

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

D = []
D = list(map(int, input().split()))

num = []
for i in range(10):
    if i not in D:
        num.append(i)

N_num = []
while True:
    if N ==0:
        break
    N_num.append(N%10)
    N = N//10

N_num.sort(reverse = True)

ans = []
for i in N_num:
    for k in num:
        if k >= i:
            ans.append(k)
            break
map(str, ans)
ans = int("".join(map(str, ans)))
print(ans)

Submission status: Runtime Error

Solution code:
def pay_by_iroha(price, dislike_digits):
    for n in range(10000):
        if n >= price and len(set(int(i) for i in str(n))&dislike_digits)==0:
            return n


def main():
    n, _ = (int(i) for i in input().split())
    dgs = set(int(i) for i input().split())
    print(pay_by_iroha(n, dgs))


main()

Submission status: Runtime Error

Solution code:
white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

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

white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.combinations_with_replacement(white_num_list, len(str(N))))

num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))

num_list = sorted(num_list)

def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    if 0 in white_num_list:
        white_num_list.remove(0)
    placeholder = str(min(white_num_list))
    return int(placeholder * (len(str(N)) + 1))
  
print(price(N, num_list, white_num_list))

Submission status: Runtime Error

Solution code:
import os

N, K = map(int, input().split(' '))
d_list = input().split(' ')
for i in range(10):
    for j in range(10):
        for k in range(10):
            for l in range(10):
                number =  i * 1000 + j * 100 + k * 10 + l
                result = set(list(str(number)))
                if set(d_list) & result != set():
                    continue
                if number >= N:
                    print(number)
                    os._exit(1)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = set([str(i) for i in input().split()])
c = 0
for i in range(1, 11):
    c += n
    t = set(list(str(c)))
    if len(d & t) == 0:
        ans = c
        break
print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = set([str(i) for i in input().split()])
c = 0
for i in range(1, 10):
    c += n
    t = set(list(str(c)))
    if len(t & d) == 0:
        ans = c
        break
print(ans)

Submission status: Runtime Error

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

p = []
for i in range(0, 10):
    if i in a:
        pass
    else:
        p.append(i)
p.sort()
count = 0
for i in list(n):
    count *= 10
    j = bisect.bisect_left(p, int(i))
    if p[j] < int(i):
        count += p[j + 1]
    else:
        count += p[j]
print(count)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in range(10):
  if i not in a:
    m.append(i)
k=0
for a in m:
  for b in m:
    for c in m:
      for d in m:
        for e in m:
        num=a*10000+b*1000+c*100+d*10+e
        if k==0 and num>=n:
          print(num)
          k=1

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in range(10):
  if i not in a:
    m.append(i)
k=0
for a in m:
  for b in m:
    for c in m:
      for d in m:
        num=a*1000+b*100+c*10+d
        if k==0 and num>=n:
          ans=num
          k=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in [0,1,2,3,4,5.6,7,8,9]:
  if i not in a:
    m.append(i)
k=0
for a in m:
  for b in m:
    for c in m:
      for d in m:
        num=a*1000+b*100+c*10+d
        if k==0 and num>=n:
          ans=num
          k=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in [0,1,2,3,4,5.6,7,8,9]:
  if i not in a:
    m.append(i)
k=0
for a in m:
  for b in m:
    for c in m:
      for d in m:
        if k:
          break
        num=a*1000+b*100+c*10+d
        if num>=n:
          ans=num
          k=1
print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(str,input().split())
D = list(map(int,input().split()))
nums = [x for x in range(10)]
nots = [i for i in nums if i not in D]
ans = ""
for j in range(len(N)):
  for k in nots:
    if int(N[j])<=k:
      ans+=str(k)
      break
print(int(ans))

Submission status: Runtime Error

Solution code:
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    N, K = map(str, input().split())
    D = list(map(str, input().split()))

    nums = set([str(i) for i in range(10)])
    safe = sorted(list(nums - set(D)))

    digit = len(str(N))
    safe_num = list(product(safe, repeat=digit))
    ans = 10**5
    for n in safe_num:
        m = int(''.join(n))
        l = int(safe[0] + ''.join(n))
        s = int(safe[1] + ''.join(n))
        if m >= int(N):
            ans = min(ans, m)

        if l >= int(N):
            ans = min(ans, l)

        if s >= int(N):
            ans = min(ans, s)

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    safe = list(set(range(10)) - set(D))
    safe = sorted(safe)

    n = [c for c in str(N)]
    for i in range(len(n)):
        if int(n[i]) in safe:
            continue
        
        for s in safe:
            if s > int(n[i]):
                n[i] = str(s)
                replaced = i
                break
        break

    for i in range(replaced+1, len(n)):
        n[i] = str(safe[0])

    return ''.join(n)


if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
num =set([0,1,2,3,4,5,6,7,8,9])
n,k = input().split()
d = list(map(int,input().split()))
a = list(num - set(d))
a.sort()
ans =[]
for i in range(len(n)):
    for j in a:
        if int(n[i]) <= j:
            ans.append(a[i])
            break
    if a[-1] < int(n[i]):
        ans.append(a[0])
l = map(str,ans)
b = "".join(l)
if int(b) < int(n):
    if a[0] != 0:
        print(a[0]*(10**(len(n)))+int(b))
    else:
        print(a[1]*(10**(len(n))) + int(b))
else:
    print(int(b))

Submission status: Runtime Error

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

for i in range(N, 10*N+1):
    num = list(map(int,str(i)))
    match = list(set(i) & set(dislike))
    if len(match)==0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
n, k = (int(_) for _ in input().split())
a = [int(_) for _ in input().split()]
like = [i for i in range(10)]
pay = []
    
for i in str(n):
    while int(i)%10 in a:
            i = int(i) + 1
    pay.append(str(i%10))

total = ''
for i in pay:
    total += i

if n > int(total):
    total += str(like[0])
print(int(total))

Submission status: Runtime Error

Solution code:
n, k = (int(_) for _ in input().split())
a = [int(_) for _ in input().split()]
like = [i for i in range(10)]
pay = []

for i in a:
    like.remove(i)

print(like)
    
for i in str(n):
    while int(i)%10 in a:
            i = int(i) + 1
    pay.append(str(i%10))

total = ''
for i in pay:
    total += i

if n > int(total):
    total += str(like[0])
print(int(total))

Submission status: Runtime Error

Solution code:
N,K=input().split()
D=list(map(int,input().split()))
for i in N:
    if int(i) in D:
        N[i]+=1
    else:
        pass
print(''.join(N))

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
NL=len(str(N))
ans=[]
allnum=list(range(10))
use=list(set(allnum)^set(D))
for i in range(NL):
    a=int(str(N)[i])
    for j in use:
        if a<=j:
            ans.append(j)
            break
        else:
            continue
if ans[0]==0:
    ans[0]=use[1]
else:
    pass
print(int(''.join(map(str,ans))))

Submission status: Runtime Error

Solution code:
# 0〜9
l=list(range(10))

# 入力
N,K=map(str,input().split())
l2=list(map(int,input().split()))

ans=''
f=False

# 使用可能な数字を求める
for x in l2:
  l.remove(x)

# Nと桁数が一致する場合
if int(N[0])<l[-1]:
  for i in range(len(N)):
    for x in l:
      if f:
        ans+=str(x)
        break
      elif int(N[i])<x:
        f=True
        ans+=str(x)
        break
      elif int(N[i])==x:
        ans+=str(x)
        break
# Nと桁数が一致する可能性がある場合
elif int(N[0])==l[-1]:
  l3=list(N[1:])
  l3=list(map(int,set(l3)))
  l3.sort()

  # Nと桁数が一致しない
  if l3[-1]>l[-1]:
    # 最上位は0以外の最小の数にする
    if l[0]==0:
      ans+=str(l[1])
      ans+='0'*len(N)
    else:
      ans+=str(l[0])*(len(N)+1)

  # Nと桁数が一致する
  else:
    for i in range(len(N)):
      for x in l:
        if f:
          ans+=str(x)
          break
        elif int(N[i])<x:
          f=True
          ans+=str(x)
          break
        elif int(N[i])==x:
          ans+=str(x)
          break

# Nと桁数が一致しない場合
else:
  # 最上位は0以外の最小の数にする
  if l[0]==0:
    ans+=str(l[1])
    ans+='0'*len(N)
  else:
    ans+=str(l[0])*(len(N)+1)

# 出力
print(ans)

Submission status: Runtime Error

Solution code:
# 0〜9
l=list(range(10))

# 入力
N,K=map(str,input().split())
l2=list(map(int,input().split()))

ans=''
f=False

# 使用可能な数字を求める
for x in l2:
  l.remove(x)

# Nと桁数が一致する場合
if int(N[0])<l[-1]:
  for i in range(len(N)):
    for x in l:
      if f:
        ans+=str(x)
        break
      elif int(N[i])<x:
        f=True
        ans+=str(x)
        break
      elif int(N[i])==x:
        ans+=str(x)
        break
# Nと桁数が一致する可能性がある場合
elif int(N[0])==l[-1]:
  l3=list(N[1:])
  l3=list(map(int,set(l3)))
  l3.sort()

  # Nと桁数が一致しない
  if l3[-1]>l[-1]:
    # 最上位は0以外の最小の数にする
    if l[0]==0:
      ans+=str(l[1])
      ans+='0'*int(N)
    else:
      ans+=str(l[0])*(N+1)

  # Nと桁数が一致する
  else:
    for i in range(len(N)):
      for x in l:
        if f:
          ans+=str(x)
          break
        elif int(N[i])<x:
          f=True
          ans+=str(x)
          break
        elif int(N[i])==x:
          ans+=str(x)
          break

# Nと桁数が一致しない場合
else:
  # 最上位は0以外の最小の数にする
  if l[0]==0:
    ans+=str(l[1])
    ans+='0'*int(N)
  else:
    ans+=str(l[0])*(N+1)

# 出力
print(ans)

Submission status: Runtime Error

Solution code:
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

for i in rang:e(Num[0],10000):
    if len(set([str(n) for n in D]) & set(str(i))) == 0:
        print(int(i))
        break

Submission status: Runtime Error

Solution code:
Num = [int(n) for n in input().rstrip().split()][0]

D = [int(n) for n in inut().rstrip().split()]

numberlist = [n if n not in D for n in range(9)]

anslist = []

for num in numberlist:
    if num >= Num:
        anslist.append(num)
    else:pass

print(min(anslist))

Submission status: Runtime Error

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

#使用可能数字の取り出し
Num1 = []
for i in range(10):
  if(i in D): continue
  else: Num1.append(i)
 
#組み合わせ
Comb = []
n = len(str(N))
for i in range(n):
  Comb.append(Num1)
Comb = list(itertools.product(*Comb))

for i in range(len(Comb)):
  tmp = Comb[i]
  tmp_num = ''
  for j in range(n): tmp_num += str(tmp[j])
  tmp_num = int(tmp_num)
  if(N <= tmp_num):
    ans = tmp_num
    break
    
print(ans)

Submission status: Runtime Error

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

#使用可能数字の取り出し
Num = [1]*10 #index = num, 使用可能: 1,使用不可: 0
Num1 = [] #使用可能数字格納
for i in range(K):
  Num[D[i]] = 0
for i in range(10):
  if(Num[i] == 1):Num1.append(i)
 
#組み合わせ
Comb = []
n = len(str(N))
for i in range(n):
  Comb.append(Num1)
Comb = list(itertools.product(*Comb))

for i in range(len(Comb)):
  tmp = Comb[i]
  tmp_num = ''
  for j in range(n): tmp_num += str(tmp[j])
  tmp_num = int(tmp_num)
  if(N <= tmp_num):
    ans = tmp_num
    break
    
print(ans)

Submission status: Runtime Error

Solution code:
def irohas_obsession(N: int, K: int, D: list) -> int:
    # D に含まれない最小の値
    min_not_d = min(d for d in range(10) if d not in D)
    min_not_d_and_not_zero = min(d for d in range(10) if d not in D and d != 0)

    # 数字を各桁に分解する。
    nums = []
    while N > 0:
        nums = [N % 10] + nums
        N //= 10

    # 上位の桁から見ていって最初に D に含まれる数字を探す。
    # convert_idx = len(nums)
    for i, n in enumerate(nums):
        if n not in D:
            # 変換の必要がない
            continue

        convert_idx = i
        break
    # print(convert_idx)
    for i in range(convert_idx, -1, -1):
        n = nums[i]
        if n > 9:
            n %= 10
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

        for d in range(n, 10):
            # 変換先が n 以上 9 以下
            if d in D:
                # NG
                continue

            nums[i] = d
            break
        else:
            # 変換先が n 未満
            for d in range(n, 10):
                if d in D:
                    # NG
                    continue

                nums[i] = d

            # 上位の桁に繰り上がりを伝搬
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

    # 残りの桁は D に含まれない最小の値に変換する。
    nums = [min_not_d if n in D else n for n in nums]

    ret = 0
    digit = 1
    # print(nums)
    for n in reversed(nums):
        ret += n * digit
        digit *= 10

    return ret


if __name__ == "__main__":
    N, K = map(int, input().split())
    D = [int(s) for s in input().split()]
    ans = irohas_obsession(N, K, D)
    print(ans)