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:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    ln = list(map(int, list(str(N))))
    c = 0
    for i in range(len(ln)-1,-1,-1):

        while(ln[i] in D):
            ln[i] += 1
        c = ln[i] // 10
        ln[i] %= 10

    if(c > 0):
        ln.appendleft(c)

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

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# 入力
N, K = map(int, input().split())
Ds = input().split()

D_list = [int(n) for n in Ds] # 嫌いな数字D
n_list = [int(n) for n in str(N)] # 1つずつのNの値
number = list(range(10)) # 0-9までの数字
likes = list(set(D_list) ^ set(number)) # 好きな数字

for i in range(len(n_list)):
    if n_list[i] in D_list: # 嫌いな時
        try: # 嫌いな値より大きな値が存在する時(0とか)
            big = min(list(filter(lambda x:x>=n_list[i], likes)))
            n_list[i] = big
        except ValueError: # 嫌いな値より大きな値が存在しない時(9とか)
            n_list[i] = min(likes)
            if n_list[i+1] != 9:
                n_list[i+1] = n_list[i+1] + 1
    print(n_list[i], end='')

Submission status: Runtime Error

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i += a:
    i += 1
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a + 1:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a + 1:
    i += 1
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        i = 0
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 1
while 1:
    while np.any(d == x[i]):
        x[i] += 1
        x[i + (i != a):] = 0
    if x[i] == 10:
        x[i - 1] += 1
        x[i:] = 0
        i = 0
    i += 1
    if np.any(d == x[0]) and x[0] != 0:
        i = 0
    if i == a:
        break
        
ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

print(int(ans))

Submission status: Runtime Error

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

ok = [True]*10;

d = [int(s) for s in input().split()]

for i in d:
    ok[i] = False

ans = 0
for i in range(N, 10*N+1):
    j = i
    while j > 0 and ok[j%10]:
        j /= 10
    if j == 0:
        ans = i
        break

print(ans)

Submission status: Runtime Error

Solution code:
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=input().split(" ")
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if len(n)==1:
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                return n[0]+search_min(n[1:],like)
            else:
                j=like.index(n[0])
                return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
print(search_min(N,like))

Submission status: Runtime Error

Solution code:
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=input().split(" ")
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if len(n)==1:
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                return n[0]+search_min(n[1:],like)
            else:
                j=like.index(n[0])
                return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
int(search_min(N,like))

Submission status: Runtime Error

Solution code:
inp=input().split(" ")
N=int(inp[0])
K=int(inp[1])
dislike=input().split(" ")
like=[]
for i in range(0,10):
    if str(i) not in dislike:
        like.append(str(i))
def search_min(n,like):
    n=str(n)
    if len(n)==1:
        for i in like:
            if i>=n:
                return i
    else:
        if n[0] in like:
            if n[1]<=like[-1]:
                return n[0]+search_min(n[1:],like)
            else:
                j=like.index(n[0])
                return like[j+1]+like[0]*(len(n)-1)
        else:
            for i in like:
                if i>n[0]:
                    return i+like[0]*(len(n)-1)
search_min(N,like)

Submission status: Runtime Error

Solution code:
l = list(range(10001))
l = list(map(str, l))
c = 0
N, K = map(int, input().split())
ld = list(map(str, input().split()))
del l[:N]
while True:
    if any(x in l[c] for x in ld):
        c += 1
    else:
        break
print(int(l[c]))

Submission status: Runtime Error

Solution code:
l = list(range(10001))
l = list(map(str, l))
print(l)
c = 0
N, K = map(int, input().split())
ld = list(map(str, input().split()))
del l[:N]
while True:
    if any(x in l[c] for x in ld):
        c += 1
    else:
        break
print(int(l[c]))

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools,pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()
D = LI()
nums = [i for i in range(0, 10) if i not in D]

"""
使える数字の中で一番低いものから試していく
見つかったら各桁試していく

"""
if len(nums) == 1:
    print(str(nums[0])*len(str(N)))
    exit()
N = str(N)
ans = []
is_done = False
for n in N:
    if is_done:
        break
    for num in nums:
        if int(n) <= num:
            # このnumを使用する
            ans.append(num)
            break
    else:
        # 超える数字がなかった
        ans = [n + 1, nums[0], nums[0], nums[0], nums[0]]
        is_done = True

for a in ans:
    print(a, end = '')

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools,pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()
D = LI()
nums = [i for i in range(0, 10) if i not in D]

"""
使える数字の中で一番低いものから試していく
見つかったら各桁試していく

"""
N = str(N)
ans = []
is_done = False
for n in N:
    if is_done:
        break
    for num in nums:
        if int(n) <= num:
            # このnumを使用する
            ans.append(num)
            break
    else:
        # 超える数字がなかった
        ans = [n + 1, nums[0], nums[0], nums[0], nums[0]]
        is_done = True

for a in ans:
    print(a, end = '')

Submission status: Runtime Error

Solution code:
import itertools

N, K = map(int,input().split())
D = list(map(int,input().split()))
N = str(N)
d = []
d_min = 10
for i in range(10):
    if i in D:
        continue
    else:
        if i != 0:
            d_min = min(d_min, i)
        d.append(str(i))
if '0' in d:
    ans = str(d_min) + '0' * len(N)
else:
    ans = str(d_min) * len(N+1)
ans = int(ans)
for s in itertools.product(d, repeat=len(N)):
    s = ''.join(s)
    s = int(s)
    if s >= int(N):
        ans = min(ans, s)
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
Dlist = list(map(int, input().split()))
    
alist = list(set([0,1,2,3,4,5,6,7,8,9]) - set(Dlist))
if sum(x==0 for x in alist) == 0:
    b = min(alist)
else:
    b = min(list(set(alist)-set([0])))
strN = str(N)
c = ""
ans = ""
flag = True
for i in range(len(strN)):
    iN = int(strN[i])
    if sum(x>=iN for x in alist) == 0:
        ans = b + str(min(alist))*len(strN)
        flag = False
        break
    elif sum(x==iN for x in alist) == 0:
        ans = c + str(min([a for a in alist if a>iN])) + str(min(alist))*(len(strN)-1-i)
        flag = False
        break
    else:
        c = c + str(iN)

if flag:
    print(N)
else:
    print(int(ans))

Submission status: Runtime Error

Solution code:
def add(ans_list, word_list):
  new_ans_list = []
  for ans in ans_list:
    for word in word_list:
      new_ans_list.append(ans+str(word))
  return new_ans_list

def run():
    N, K = map(int, input().split())
    len_N = len(str(N))
    d_list = set(map(int, input().split()))
    all_list = set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    use_list = sorted(list(all_list - d_list))
    ans_list = ['']
    for n in range(len_N):
      ans_list = add(ans_list, use_list)
    for ans in ans_list:
      if N <= int(ans): print(ans); break
    else:
      if use_list[0] == 0: print(str(use_list[1])+0*len_N)
      else: print(str(use_list[0])*(len_N+1))
    

run()

Submission status: Runtime Error

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
while True:
    flag=0
    for money_element in list(str(money)):
        if money_element in no_list:
            flag=1
            money+=1
            break
    if flag==0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
while true:
    flag=0
    for money_element in list(str(money)):
        if money_element in no_list:
            flag=1
            money+=1
            break
    if flag==0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
for i in range(money,100000):
  	flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
kirai = [int(i) for i in input().split()] 
usable_num = [1,2,3,4,5,6,7,8,9]
for x in kirai:
    usable_num.remove(x)
    
ketasu = len(str(N))
#print(ketasu)
s = 0
for d in range(ketasu):
    s += min(usable_num) * 10 ** d 

if s >= N:
    print(s)
else:
    print(N+min(usable_num))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
kirai = [int(i) for i in input().split()] 
usable_num = [1,2,3,4,5,6,7,8,9]
for x in kirai:
    usable_num.remove(x)
    
ketasu = len(str(N))

s = 0
for d in range(ketasu):
    s += min(usable_num) * 10 ** d 

if s >= N:
    print(s)
else:
    pass

Submission status: Runtime Error

Solution code:
l = list(range(10))  # LIST10桁の数字を生成
n, k = map(int, input().split())  # n=値段,10000以下 k=嫌いな個数
lis = list(map(int, input().split()))  # 嫌いな数字入力
[l.remove(x) for x in lis]  # 10桁の数字から嫌いな数字を削除
h = n / 10 ** (len(str(n))-1)  # 値段の一番左の数字を取得するための計算
temp = []
for x in l:
    if h < x:
        temp.append(x)
ans = []
ans.append(temp[0])
for x in range(len(str(n))-1):
    ans.append(l[0])
print(int("".join(map(str, ans))))

Submission status: Runtime Error

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

nums = []
for x in range(10):
    if x in ds:
        nums.append(1)
    else:
        nums.append(0)

for x in range(n, n*10):
    ys = list(map(int,list(str(x))))
    flag = False
    for y in ys:
        if nums[y]:
            flag = True
            break
    if flag:
        continue
    else:
        print(x)
        exit

Submission status: Runtime Error

Solution code:
no_list=[]
s=input().split()
money,num=int(s[0]),int(s[1])
for i in range(num):
    no_list.append(input())
for i in range(money,10000):
    origin=i
    flag=0
    while i!=0:
        if str(i%10) in no_list:
            flag=1
            break
        i//=10
    if flag==0:
        print(origin)
        break

Submission status: Runtime Error

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

keta = len(str(n))

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




ans = []

for i in range(1,10):
    if not i in d:
        ans.append(i)
        break

k = 9

for i in range(0,10):
    if (not i in d) and (i < k):
        k = i

for i in range(keta-1):
    ans.append(k)

for i in range(len(ans)):
    ans[i] = str(ans[i])

if n <= int(''.join(ans)):
    print(int(''.join(ans)))

else:
    ans.append(k)
    print(int(''.join(ans)))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
#print(num)
digit = []
while N>0:
    digit.append(N%10)
    N = N//10
digit.reverse()
#print(digit)
retval = []
#print(digit)
#print(num)
if digit[0] > num[-1]:
    if num[0] == 0:
        retval.append(num[1])
        for i in range(N):
            retval.append(num[0])
    else:
        for i in range(N+1):
            retval.append(num[0])
else:
    for i in range(len(digit)):
        m = 10000000
        for j in num:
            if j < m and j >= digit[i]:
                m = j
                break
        retval.append(str(m))
        #print(digit[i])
        #print(m)
        if digit[i] == m:
            #print("yes")
            for k in range(len(digit)-i-1):
                retval.append(str(num[0]))
            break
        else: continue

#print(retval)
print("".join(retval))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
#print(num)
digit = []
while N>0:
    digit.append(N%10)
    N = N//10
digit.reverse()
#print(digit)
retval = []
if digit[0] > num[-1]:
    if num[0] == 0:
        retval.append(num[1])
        for i in range(N):
            retval.append(num[0])
    else:
        for i in range(N+1):
            retval.append(num[0])
else:
    for i in range(len(digit)):
        m = 10000000
        for j in num:
            if j < m and j >= digit[i]:
                m = j
                break
        retval.append(str(m))
        if digit[i] != m:
            for k in range(len(digit)-i-1):
                digit.append(num[0])
        else: continue

#print(retval)
print("".join(retval))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
#print(num)
digit = []
while N>0:
    digit.append(N%10)
    N = N//10
digit.reverse()
#print(digit)
retval = []
if digit[0] > num[-1]:
    if num[0] == 0:
        retval.append(num[1])
        for i in range(N):
            retval.append(num[0])
    else:
        for i in range(N+1):
            retval.append(num[0])
else:
    for i in digit:
        m = 10000000
        for j in num:
            if j < m and j >= i:
                m = j
                break
        retval.append(str(m))
#print(retval)
print("".join(retval))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
#print(num)
digit = []
while N>0:
    digit.append(N%10)
    N = N//10
digit.reverse()
#print(digit)
retval = []
if digit[0] > num[-1]:
    if num[0] == 0:
        retval.append(num[1])
        for i in range(N):
            retval.append(num[0])
    else:
        for i in range(N+1):
            retval.append(num[0])
else:
    for i in digit:
        m = 10000000
        for j in num:
            if j < m and j >= i:
                m = j
        retval.append(str(m))
#print(retval)
print("".join(retval))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k;

    cin >> n >> k;
    vector<int>d_vec(k, 0);
    for (int i = 0; i < k; ++i) {
        cin >> d_vec[i];
    }

    int price = n;
    while (true){
        bool isValid = true;
        int digit_cnt = floor(log10(price));
        int now = price;
        for (int digit = 0; digit < digit_cnt+1; ++digit) {
            int tmp = now % 10;
            auto iter = find(d_vec.begin(), d_vec.end(), tmp);
            if (iter != d_vec.end()){
                isValid = false;
                break;
            }
            now /= 10;
        }

        if (isValid){
            cout << price << endl;
            break;
        }


        price++;
    }
    return 0;

Submission status: Runtime Error

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

for i in range(n, 10000):
    flg: bool = True
    for s in str(i):
        if int(s) in dlist:
            flg = False
            break
    if flg:
        print(i)
        break

Submission status: Runtime Error

Solution code:
def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    D_tmp = []
    for x in range(10):
        if x not in D:
            D_tmp.append(x)
    for x in range(len(D_tmp)):
        ans = D_tmp[-1] * (10**(x))
    if N > ans:
        ans = D_tmp[1] * (10 ** (len(str(N))-1))
    else:
        ans = 0
        for i_1 in D_tmp:
            if ans > N: break
            ans = i_1
            if len(str(N)) <= len(str(ans)): continue
            for i_10 in D_tmp:
                if ans > N: break
                ans = i_10 * 10 + i_1
                if len(str(N)) <= len(str(ans)): continue
                for i_100 in D_tmp:
                    if ans > N: break
                    ans = i_100 * 100 + i_10 * 10 + i_1
                    if len(str(N)) <= len(str(ans)): continue
                    for i_1000 in D_tmp:
                        if ans > N: break
                        ans = i_1000 * 1000 + i_100 * 100 + i_10 * 10 + i_1
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()

Submission status: Runtime Error

Solution code:
def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    D_tmp = []
    for x in range(10):
        if x not in D:
            D_tmp.append(x)
    for x in range(len(D_tmp)):
        ans = D_tmp[-1] * (10**(x+1))
    if N > ans:
        ans = D_tmp[1] * (10 ** len(str(N-1)))
    else:
        ans = 0
        for i_1 in D_tmp:
            if ans > N: break
            ans = i_1
            if len(str(N)) <= len(str(ans)): continue
            for i_10 in D_tmp:
                if ans > N: break
                ans = i_10 * 10 + i_1
                if len(str(N)) <= len(str(ans)): continue
                for i_100 in D_tmp:
                    if ans > N: break
                    ans = i_100 * 100 + i_10 * 10 + i_1
                    if len(str(N)) <= len(str(ans)): continue
                    for i_1000 in D_tmp:
                        if ans > N: break
                        ans = i_1000 * 1000 + i_100 * 100 + i_10 * 10 + i_1
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()

Submission status: Runtime Error

Solution code:
N_str, K=input().split()
N_digit=list(map(int,list(N_str)))
D=sorted(list(map(int,input().split())))
l_digit=[n>D[-1] for n in N_digit]


if any(l_digit):
  N_n=l_digit.index(True)
  if not any([n<D[-1] for n in N_digit[0:N_n]]):
    out=list(str(D[1] if D[0]==0 else D[0]))
    out+=[str(D[0]) for i in range(len(N_digit))]
  else:
    out=[str(D[[n<=D[j] for j in range(int(K))].index(True)]) for n in N_digit[0:N_n]] + [str(D[0]) for n in N_digit[N_n:]]
    for k in range(N_n-1,-1,-1):
      if N_digit[k]<D[-1]:
        out[k]=str(D[[N_digit[k]<D[j] for j in range(int(K))].index(True)])
        break
    
else:
  out=[str(D[[n<=D[j] for j in range(int(K))].index(True)]) for n in N_digit]

print(int("".join(out)))

Submission status: Runtime Error

Solution code:
n,K = map(int,input().split())
use = [0,1,2,3,4,5,6,7,8,9]
useless = list(map(int,input().split()))
for i in range(K):
  use.remove(useless[i])
k = 10 - K
time = [0]
def suc(time):
  now = 0
  while True:
    if now >= len(time):
      time.append(1)
      break
    elif time[now] != k-1:
      time[now] += 1
      break
    else:
      time[now] = 0
      now += 1
  return time
#print(suc([0]))
#print(suc([1,1,1,1]))
#print(suc([1,0,1,1]))
while True:
  pay = 0
  for j in range(len(time)):
    pay += use[time[j]] * 10 ** j
  if pay >= n:
    print(pay)
    break
  time = suc(time)

Submission status: Runtime Error

Solution code:
import bisect
#find set of numbers iroha like
tmp = raw_input("").split(' ')
n = int(tmp[0])
k = int(tmp[1])
tmp = raw_input("")
exclude_set = map(int, tmp.split(' '))
include_set = []
for i in range(0, 10):
  if i not in exclude_set:
    include_set.append(i)
#print include_set
n_digits = []
while n > 0:
  n_digits.append(n%10)
  n = int(n/10)
out = []
j = 0
#print include_set
while j < len(n_digits):
  tmp = bisect.bisect_left(include_set, n_digits[j])
  #print tmp
  out.append(str(include_set[tmp]))
  j += 1
print int(''.join(out)[::-1])

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
D_ALL = [0,1,2,3,4,5,6,7,8,9]

# 使える値
like = sorted(list(set(D_ALL) - set(D)))
small = like[0]

is_inc = False
out = ""
for i, s in enumerate(str(N)):
    num = int(s)

    for i2, like_num in enumerate(like):

        if is_inc:
            out += str(small)
            break

        if like_num >= num:
            out += str(like_num)
            if like_num > num:
                is_inc = True
            break

        if i2 == len(like) - 1 and i == 0:
            out = 1
            out += str(small)
            is_inc = True

print(out)

Submission status: Runtime Error

Solution code:
is_inc = False
out = ""
for i, s in enumerate(str(N)):
    num = int(s)

    for i2, like_num in enumerate(like):

        if is_inc:
            out += str(small)
            break

        if like_num >= num:
            out += str(like_num)
            if like_num > num:
                is_inc = True
            break

        if i2 == len(like) - 1 and i == 0:
            out = str(small) + str(small)
            is_inc = True

Submission status: Runtime Error

Solution code:
n, k = input().split()
a = input().split()

n = int(n)

for i in range(10000-n):
    c = str(n+i)
    
    for j in a:
        if j in c:
            break
    
    else:
        ans = c
        break
        
print(ans)

Submission status: Runtime Error

Solution code:
n,k=[s for s in input().split()]
hate=[]
like=[]
for i in range(k): #hate取得
	hate.extend(input().split())
for i in range(1,10): #like取得
	if i in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break

if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break

if pointer==1:
	print(kane)
else:
	print("Error!!")

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()))
    L=[]
    for i in range(10):
        if i not in D:
            L.append(i)
    for p in L:
        if len(str(N))==1:
            if p>=N:
                print(p)
                return
        else:
            for q in L:
                if len(str(N))==2:
                    pay=p*10+q
                    if pay>=N:
                        print(pay)
                        return
                else:
                    for r in L:
                        if len(str(N))==3:
                            pay=p*100+q*10+r
                            if pay>=N:
                                print(pay)
                                return
                        else:
                            for s in L:
                                pay=p*1000+q*100+r*10+s
                                if pay>=N:
                                    print(pay)
                                    return
    if L[0]==0:
        print(L[1]*10**len(str(N)))
    else:
        print("".join([L[0] for _ in range(len(str(N)))]))
    return
            

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    input=sys.stdin.readline
    N,K=map(int,input().split())
    D=list(map(int,input().split()))
    L=[]
    for i in range(10):
        if i not in D:
            L.append(i)
    for p in L:
        if len(str(N))==1:
            if p>=N:
                print(p)
                return
        else:
            for q in L:
                if len(str(N))==2:
                    pay=p*10+q
                    if pay>=N:
                        print(pay)
                        return
                else:
                    for r in L:
                        if len(str(N))==3:
                            pay=p*100+q*10+r
                            if pay>=N:
                                print(pay)
                                return
                        else:
                            for s in L:
                                pay=p*1000+q*100+r*10+s
                                if pay>=N:
                                    print(pay)
                                    return
    if L[0]==0:
        print(L[1]*10**len(str(N)))
    else:
        print("".join([L[0] for _ in range(len(str(N)))]))
    return
            

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
def UnlikeNum(nums,price):
    for num in nums:
        if(str(num) in str(price)):
            return True
    
    return False

N, K = map(int,input().split())
D = [int(input()) for k in range(K)]
while(UnlikeNum(D,N)):
    N+=1
print(N)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*- 
price, K = map(int, input().split())
 
kirai_data =list(input().split())
#print(set(data))
 
lst = list(range(price,10001))
for min in lst:
   
    shugo = set(data) & set(list(str(min))) 
    if  len(shugo) != 0 :                         
        continue
    else:
      #print(price)
      print(min)
      break

Submission status: Runtime Error

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]

    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    l = len(NN)
    ANS = []
    now = 0
    MIN = [0, A[0], A[0]*11, A[0]*111, A[0]*1111]
    check = 0
    for i in range(l):
        for a in A:
            if a > NN[0]:
                ANS.append(now*10**(l-i)+a*10**(l-1-i) + MIN[l-1-i])
                now = now*10+a
                break
            elif a == NN[0]:
                now = now*10+NN[0]
                check += 1
    if check == l:
        ANS.append(now)
    print( min(ANS))
            
if __name__ == '__main__':
    main()