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 = input().split()

dislike = set(list(map(int, input().split())))


next_map = {}
for i in range(10):
    for j in range(i,10):
        if j not in dislike:
            if i == 0:
                min_digit = j
            next_map.update({ i : j })
            break
        next_map.update({ i : min_digit })
max_digit = max(next_map.values())

num = len(list(N))

count = num
cand = []
for n in list(N):
    n = int(n)
    if n in dislike:
        n_ = next_map[n]
        cand.append(n_)
        count -= 1
        cand.extend(count*[min_digit])
        break
    else:
        cand.append(n)
cand = int("".join(list(map(str, cand))))
if int(N) <= cand:
    print(cand)
else:
    if min_digit == 0:
        next_min = next_map[1]
        cand = [next_min] + num * [0]
    else:
        cand = (num + 1) * [min_digit]
    cand = int("".join(list(map(str, cand))))
    print(cand)

Submission status: Runtime Error

Solution code:
a = input().split()
tg = a[0]
ok_nums = set("1","2","3","4","5","6","7","8","9","0")
ng_nums = set(input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
while True:
  if ok_nums >= set(d for d in str(i)):
    print(i)
    break
  else:
    i+=1

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
numbers = [0,1,2,3,4,5,6,7,8,9]
use = []
for i in numbers:
  if not i in P:
    use.append(i)

ul = []
for u5 in [0, use[1]]:
  for u4 in use:
    for u3 in use:
      for u2 in use:
        for u1 in use:
          ul.append(u5*10000 + u4*1000 + u3*100 + u2*10 + u1)
ul.sort()
for r in ul:
  if N <= r:
    print(r)
    break

Submission status: Runtime Error

Solution code:
#ABC042C
N,K=map(int,input().split())
N=str(N)
N_len=len(N)
a=[]
out=N
for i in range(K):
    a.append(input())
for i2 in range(N_len):    
    for i3 in range(K):
        if N[i2]==a[i3]:
            out += 1
print(out)

Submission status: Runtime Error

Solution code:
#include <iostream>
using namespace std;

int main(void)
{
    int n, k;
    cin >> n >> k;

    bool dislikes[10] = {false};
    for (int i = 0, x; i < k; i++)
    {
        cin >> x;
        dislikes[x] = true;
    }

    auto valid = [&](int x) {
        while (x)
        {
            int d = x % 10;
            if (dislikes[d])
                return false;
            x /= 10;
        }
        return true;
    };

    for (int p = n; p < 80001; p++)
        if (valid(p))
        {
            cout << p << endl;
            break;
        }
}

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
l = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
a = d ^ l

for i in range(n, 10000):
    g = set(str(i))
    i_int ={int(m) for m in g} 
    if i_int<=a:
        ans = i
        break

print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
l = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
a = d ^ l

for i in range(n, 10000):
    g = set(str(i))
    i_int ={int(m) for m in g} 
    if i_int==a:
        ans = i
        break

print(ans)

Submission status: Runtime Error

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

if 0 in D:
    print(N)
else:
    print(int(*D2-D)*N)

Submission status: Runtime Error

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=map(int, input().split())
d=list(map(str, input().split()))
for item in d:
    a.remove(item)
#print(a)

from collections import deque

q=deque()
q.extend(a)
if n<10:
    if a[0]!=0:
        print(a[1])
        sys.exit()
    else:
        print(a[0])
        sys.exit()

while True:
    qq=q.popleft()
    #print(q)
    for item in a:
        qqq=qq+item
        #print(qqq[::-1])
        if int(qqq[::-1])>=n:
            print(qqq[::-1])
            sys.exit()
        q.append(qqq[::-1])

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
d = list(map(str, input().split()))
ans = N
while True:
    sra = str(ans)
    if sra[0] not in d and sra[1] not in d and sra[2] not in d and sra[3] not in d:
        if len(sra) == 5:
            if sra[4] not in d:
                print(sra)
                break
        print(sra)
        break
    ans = int(sra) + 1

Submission status: Runtime Error

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

keta = int(len(str(n)))
ok = sorted(list(set(d) ^ {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}))

ans = ''
for i in reversed(range(keta)):
    val = int(str(n)[i])
    candidate = [j for j in ok if j >= val]
    if candidate:
        ans += str(min(candidate))
    else:
        ans = str(min(ok))

ans = ''.join(reversed(list(ans)))
if int(ans) < n:
    idx = ok.index(ans[0])
    if idx == len(ok) - 1:
        ans = str(min(ok)) * (keta + 1)
    else:
        ans = str(ok[idx + 1]) + str(min(ok)) * (keta - 1)

print(ans)

Submission status: Runtime Error

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

ok = sorted(list(set(d) ^ {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}))

ans = ''
for i in range(len(str(n))):
    flag = False
    num = int(str(n)[i])
    candidate = [j for j in ok if j >= num]
    if candidate:
        ans += str(min(candidate))
    else:
        ans += min(ok)
        flag = True

if flag:
    ans[0] = str(min([i for i in ok if i > ans[0]]))

print(ans)

Submission status: Runtime Error

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

ok = sorted(list(set(d) ^ {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}))

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

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding : utf-8 -*-

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

curr_num = N
while True :
  n_str = str(curr_num)
  for d in D:
    if d in n_str:
      curr_num += 1
      break
    else:
      print(curr_num)
      break

Submission status: Runtime Error

Solution code:
# -*- coding : utf-8 -*-

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

while True :
  n_str = str(N)
  for d in D:
    if d in n_str:
      N += 1
      break
    else:
      print(N)
      break

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
other = [i for i in range(10)] - d
m = 0
def dfs(m, now):
  m = int(m)
  if(m >= n):
    print(int(now))
  else:
    if(m == 0):
      m = ""
    m = str(m)
    for(o in other):
      dfs(m, m + o)

Submission status: Runtime Error

Solution code:
class A:

    def solve(self):
        [a, b, c] = sorted([int(x) for x in input().split(" ")])
        if a == 5 and b == 5 and c == 7:
            print("YES")
        else:
            print("NO")

class B:

    def solve(self):
        [n, l] = [int(x) for x in input().split(" ")]

        strings = []
        for r in range(n):
            strings.append(input())

        sorted_strings = sorted(strings)

        print("".join(sorted_strings))

class C:

    def solve(self):
        [n, k] = [int(x) for x in input().split(" ")]
        dislikes = [int(x) for x in input().split(" ")]

        likes = []
        for r in range(10):
            if r not in dislikes:
                likes.append(r)

        import bisect as b

        final_amount = []
        for c in str(n):
            i = b.bisect_left(likes, int(c))
            final_amount.append(str(likes[i]))

        print("".join(final_amount))

C().solve()

Submission status: Runtime Error

Solution code:
n,k=map(int, input().split())
ds=list(map(str, input().split()))
while i in str(n) for i in ds:
  n+=1
print(str(n))

Submission status: Runtime Error

Solution code:
n,k=map(int, input().split())
ds=[]
for i in range(len(k)):
  ds.append(input())
ans=n
while ds in ans:
  ans+=1
print(str(ans))

Submission status: Runtime Error

Solution code:
n , k = map(int,input().split())
d = set(list(map(int,input().split())))
kouho =list({0,1,2,3,4,5,6,7,8,9} - d)
kouho.sort()

def f(now):
    if now >= n:
        print(now)
        exit()
    for i in kouho:
        f(now*10 + i)

f(0)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
b = {0,1,2,3,4,5,6,7,8,9}-set(a) #使用可能な数字の集合
n = [int(i) for i in list(str(n))] #価格(int)をリストに分解

while set([int(i) for i in list(str(n))])-b !={} : # 使用可能な数字のみでなければ
    n += 1

print(n)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
n2 = [int(i) for i in list(str(n))] #価格を分解
for i in n2:
    while n2[i] in a :#使用不可ならば
        n2[i] += 1
        if n2[i]>=10:
            n2[i] =1

print("".join([str(i) for i in n2]))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
b = list({0,1,2,3,4,5,6,7,8,9}-set(a)) #使用可能な数字のリスト
n2 = [int(i) for i in list(str(n))] #価格を分解

for i in n2:
    while n2[i] in a :#使用不可ならば
        n2[i] += 1

print("".join([str(i) for i in n2]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#input
#n=3519,k=5,d=0,2,5,7,9
d0=[0,1,2,3,4,5,6,7,8,9]
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(k):d0.remove(d[i])
n=str(n)
n=n[::-1]
ans0=0
for i in range(len(n)):
    for j in range(len(d0)):
        if int(n[i])==9 and i<(len(n)-1) and d0[len(d0)-1]!=9:
            ans=10**i * d0[0]
            break
        elif int(n[i])==9 and i==(len(n)-1) and d0[len(d0)-1]!=9:
            ans=10**(i+1) * d0[0] + 10**i * d0[0]
            break
        elif int(n[i])==d0[j]:
            ans=10**(i) * d0[j]
            break
        elif int(n[i])<d0[j]:
            ans=10**(i) * d0[j]
            break
        
    ans0=ans0+ans
    
print(ans0)

Submission status: Runtime Error

Solution code:
from collections import deque
n, k = map(int, input().split())
D = list(map(int, input().split()))

# 1. 初期化
ok_lst = [x for x in range(0, 10) if x not in D]
ok_lst.sort(reverse = True)
stack = deque([x for x in ok_lst if x != 0])

while len(stack) > 0:
    # 2. 現在の情報の取得
    # 今回は現在の数字
    now_num = stack.pop()
    # 3. 処理
    # もしnow_numの桁数がnの桁数と同じかつ条件の値以上の場合，ansに記録しwhileを終了．
    # もしnow_numの桁数がnの桁数と同じかつ条件の値未満の場合，次は数値を足すとまずいのでcontinueで防ぐ
    if len(str(now_num)) == len(str(n)) and now_num >= n:
        ans = now_num
        break
    if len(str(now_num)) == len(str(n)) and now_num < n:
        continue
    # 4. 更新
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        next_num = int(next_num)
        stack.append(next_num)

print(ans)

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

"""
lim = 2*10**5   #必要そうな階乗の限界を入力

#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod

#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod

"""

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

while 1:
	if set(list(str(N))) & set(D) == set():
		print(N)
		break
	N += 1

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

for i in range(N,INF):
	for number in dislike:
    	if str(i).count(number) != 0
        	judge = false
          	break
    if judge == true:
      answer = i
      break
   	else:
      judge = true

print(i)

Submission status: Runtime Error

Solution code:
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])
 
d = input().split()
D = [int[s] for s in d]
 
Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for i in D:
    Da.remove(i)
Da_str = [str(j) for j in Da]
 
a_1 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N))]
a_2 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N)+1)]
a = a_1 + a_2
nu = [int(k) for k in a]
 
for i in nu:
    if i >= int(N):
        print(i)
        break

Submission status: Runtime Error

Solution code:
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])
 
d = input().split()
D = [int[s] for s in d]
 
Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for i in D:
    Da.remove(i)
Da_str = [str(j) for j in Da]
 
a_1 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N))]
a_2 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N)+1)]
a = a_1 + a_2
nu = [int(k) for k in a]
 
 
for i in nu:
    if i >= int(N):
        print(i)
        break

Submission status: Runtime Error

Solution code:
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])
 
d = input().split()
D = [int[s] for s in d]
 
Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for i in range(len(D)):
    Da.remove(D[i])
Da_str = [str(j) for j in Da]
 
a_1 = [''.join(j) for j in itertools.product(b_st, repeat=len(N))]
a_2 = [''.join(j) for j in itertools.product(b_st, repeat=len(N)+1)]
a = a_1 + a_2
nu = [int(k) for k in a]
 
 
for i in nu:
    if i >= int(N):
        print(i)
        break

Submission status: Runtime Error

Solution code:
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])
 
d = input().split()
D = [int[s] for s in d]
 
Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for i in range(len(D)):
    Da.remove(D[i])
Da_str = [str(j) for j in Da]

a_1 = [''.join(j) for j in itertools.product(b_st, repeat=len(N))]
a_2 = [''.join(j) for j in itertools.product(b_st, repeat=len(N)+1)]
a = a_1 + a_2
nu = [int(k) for k in a]

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

Submission status: Runtime Error

Solution code:
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])

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

Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range(len(D)):
    Da.remove(D[i])

nu = []
for j in itertools.combinations_with_replacement(Da, len(N)+1):
    b = ''.join([str(j[i]) for i in range(len(N)+1)])
    nu.append(int(b))

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

Submission status: Runtime Error

Solution code:
import copy
def make1d(n, m):
    return [copy.deepcopy(m) for i in range(0,n)]
s = list(map(int, input().split()))
t = list(map(int, input().split()))
#支払う金額s[0]を桁ごとに分解する
#支払う金額の桁数：n
n = 0
while (s[0] // (10 ** n)) >= 10:
    n = n + 1
l = make1d(n + 1, 1)
m = s[0]
for i in range(0, n + 1):
    l[n - i] = m % 10
    m = m // 10
#使えない数字->tを使える数字->numに変換
num = make1d(10, 1)
for i in range(0, len(t)):
    num[t[i]] = 0
#支払う金額からスタートしてダメな数字を含む場合は1増やしていく
#払うべき金額->l，使える数字->num（使える->1，使えない->0），支払う金額（答え）->a
a = l
limit = 10 ** len(a) - 1
a_int = int(''.join(map(str, a)))
#桁数が一致しているときは
tmp = 1
for i in range(0, n + 1):
    tmp = tmp * num[a[i]]
if tmp == 1:
    ans = a_int
while tmp == 0:
    if(a_int <= limit - 1):
        a_int = a_int + 1
        a_tmp = a_int
        for i in range(0, n + 1):
            a[n - i] = a_tmp % 10
            a_tmp = a_tmp // 10
        tmp = 1
        for i in range(0, n + 1):
            tmp = tmp * num[a[i]]
        ans = a_int
    else:#桁が一つ増える場合
        count = 0
        count_n = 1#0以外の最小の数
        while count == 0:
            count = count + num[count_n]
        if num[0] == 1:
            a = make1d[n + 2, 0]
            a[0] = count_n
        else:
            a = make1d[n + 2, count_n]
        ans = int(''.join(map(str, a)))
print(ans)

Submission status: Runtime Error

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

S = str(N)
ans = []


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


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

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

print("".join(ans))

Submission status: Runtime Error

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

s = 0
while s == d[s]:
    s += 1

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

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

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

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


print(m)

Submission status: Runtime Error

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

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

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

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

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


print(m)

Submission status: Runtime Error

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

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

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

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

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


print(m)

Submission status: Runtime Error

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

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

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

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

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


print(m)

Submission status: Runtime Error

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

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

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

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

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

Submission status: Runtime Error

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

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

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

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

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


print(m)

Submission status: Runtime Error

Solution code:
n,k=list(map(int,input().split()))
D=list(map(int,input().split()))
like=[]
for i in range(10):
    if not i in D:
        like.append(i)
N=str(n)
ans=[]
for i in range(len(N)):
    for j in range(len(like)):
        if like[j]>=int(N[i]):
            ans.append(like[j])
            break
    else:
        if not like[0]==0:
            ans.append(like[1])
        else:
            ans.append(like[0])
        for i in range(len(N)):
            ans.append(like[0])
        break
    if ans[i]>int(N[i]):
        for i in range(i+1,len(N)):
            ans.append(like[0])
        break

answer=''.join(map(str,ans))
print(int(answer))

Submission status: Runtime Error

Solution code:
import itertools
def solve(n, k, xs):

    tmp = [str(i) for i in range(10) if i not in xs]
    str_len = len(str(n))

    hoge = [i for i in map(lambda x: int("".join(x)),
                            itertools.product(tmp, repeat=str_len)) if i >= n]

    return hoge[0]

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    xs = [int(i) for i in input().split()]
    print(solve(n, k, xs))

Submission status: Runtime Error

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

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

for ii in range(n*10):
    i = ii+1
    ar = ValueToArray10(i, int(1+(math.log(i)+0.00001)/math.log(10)))
    ok=1
    for j in ar:
        for k in a:
            if(j==k):
                ok=0
    if(ok==1 and i>=n):
        print(i)
        exit()

Submission status: Runtime Error

Solution code:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])

for i in range(len(n))
    dig1=0
    dig2=0
    for j in range(l[1]):
        p=dig1+d_bar[j]*10**(range(l[0])-i)
        if p>l[0]:
            break
        dig1=p
        dig2=dig2+d_bar[j]*l[1]**(range(l[0])-i)
dig2=dig2+1
r=dig
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.append(r)
s=int(sum[str(-t-1) for t in R])
print(s)

Submission status: Runtime Error

Solution code:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
a=[]
p=0
n_int=[int(k) for k in str(l[0])]
for i in range(len(n_int)):
    a.append(10)
    for j in range(len(d_bar)):
        if n_int[-i-1]==d_bar[j]:
            a.pop(i)
            a.append(d_bar[j+p])
            p=0
            break
        elif n_int[-i-1]<d_bar[j]:
            a.pop(i)
            a.append(d_bar[j])
            p=0
            break
    if a[i]==10:
        a.pop(i)
        a.append(d_bar[0])
        p=1
b=''
for q in range(len(n_int)):
    b=b+str(a[-q-1]) 
print(int(b))

Submission status: Runtime Error

Solution code:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
a=[]
n_str=str(l[0])
n_int=[int(k) for k in n_str]
for i in n_int:
    a.append('na')
    for j in d_bar:
        if i<=j:
            a[i-1]=j
            break
        else:
            pass
    if a[i-1]='na':
        a[i-1]=d_bar[0]
if a[0]=0:
    a.insert(0,d_bar[0])

print(int(a))

Submission status: Runtime Error

Solution code:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
a=''
for i in str(l[0]):
    for j in d_bar:
        if int(i)<=j:
            k=str(j)
            break
        else:
            pass
    a=a+k
print(int(a))

Submission status: Runtime Error

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

usable = sorted( list( {str(i) for i in range(10)} - hate))

l = len(str(n))

def check(l):
    num = []
    if l == 1:
        for i in usable:
            num.append(i)
    if l == 2:
        for ii in usable:
            for i in usable:
                num.append(int( str(ii) + str(i)))
    elif l == 3:
        for iii in usable:
            for ii in usable:
                for i in usable:
                    num.append(int( str(iii) + str(ii) + str(i)))
    elif l == 4:
        for iv in usable:
            for iii in usable:
                for ii in usable:
                    for i in usable:
                        num.append(int( str(iv) + str(iii) + str(ii) + str(i)))
    else:
        for v in usable:
            for iv in usable:
                for iii in usable:
                    for ii in usable:
                        for i in usable:
                            num.append(int( str(v) + str(iv) + str(iii) + str(ii) + str(i)))
    return num

truf = False
num = check(l)
for i in num:
    if n <= i:
        print(i)
        truf = True
        break
if not truf:
    num = check(l+1)
    for i in num:
        if n <= i:
            print(i)
            break

Submission status: Runtime Error

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

usable = sorted( list( {str(i) for i in range(10)} - hate))

l = len(str(n))

def check(l):
    num = []
    if l == 1:
        for i in usable:
            num.append(i)
    if l == 2:
        for ii in usable:
            for i in usable:
                num.append(int( str(ii) + str(i)))
    elif l == 3:
        for iii in usable:
            for ii in usable:
                for i in usable:
                    num.append(int( str(iii) + str(ii) + str(i)))
    elif l == 4:
        for iv in usable:
            for iii in usable:
                for ii in usable:
                    for i in usable:
                        num.append(int( str(iv) + str(iii) + str(ii) + str(i)))
    else:
        for v in usable:
            for iv in usable:
                for iii in usable:
                    for ii in usable:
                        for i in usable:
                            num.append(int( str(v) + str(iv) + str(iii) + str(ii) + str(i)))
    return num

truf = False
num = check(l)
for i in num:
    if n <= i:
        print(i)
        truf = True
        break
if not truf:
    num = check(l+1)
    for i in num:
        if n <= i:
            print(i)

Submission status: Runtime Error

Solution code:
a,n=map(int,input())
b=[]
for i in range(n):
  b.append(int(input())
flag="F"
which flag=="F":
  k=a
  fflag="T"
  which k>=1 and fflag=="T":
    l=int(k%10)
    for i in range(n):
      if a[i]==l:
        fflag="F"
    break
  if fflag=="T":
    flag="T"
  else:
    a+=1
print(a)

Submission status: Runtime Error

Solution code:
N, L = map(int, input().split())
hates = [input() for _ in range(N)]

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

Submission status: Runtime Error

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(9)

Submission status: Runtime Error

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



for price in range(N,10**4+1):
    s=str(price)
    flag=True
    for i in range(len(s)):
        if int(s[i]) in D:
            flag=False
    if flag:
        ans=price
        break

print(ans)

Submission status: Runtime Error

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(n)) - str(n).index(i) - 1
            ans += 10**x
            flag = True
    if flag:continue
    print(ans)
    break

Submission status: Runtime Error

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(n)) - str(n).index(i) - 1
            ans += 10**x
            flag = True
    if flag:continue
    print(ans)
    exit(0)