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:
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)

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)

    # 数字を各桁に分解する。
    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]
        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] + 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)

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)

    # 数字を各桁に分解する。
    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]
        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] + 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)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def dfs(n):
    if all(not(int(i) in D) for i in str(n)):
        return n
    return dfs(n+1)
print(dfs(N))

Submission status: Runtime Error

Solution code:
# coding: UTF-8


N, _ = input().split()
dislike_nums = set(map(int, input().split()))

nums = set(range(10))
nums -= dislike_nums

for i in range(len(N)):
    Ni = int(N[i])
    larger_num = [n for n in nums if n >= Ni]
    print(min(larger_num), end="")

print()

Submission status: Runtime Error

Solution code:
import sys
N, _ = map(int, input().split())
D = list(map(int, input().split()))
E = [str(i) for i in [0,1,2,3,4,5,6,7,8,9] if i not in D]
for n in N:
    if not n in E:
        for e in E:
            if e>n:
                n=e
                sys.stdout.write(n)
                break;
    else:
        sys.stdout.write(n)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
D  = {int(n) for n in input().split()}
for j in range(10000):
    if N <= j:
        L = {int(result) for result in str(j)}
        if D.isdisjoint(L):
            D_love = j
            break
print(D_love)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
D  = {int(n) for n in input().split()}
for j in range(10001):
    if N <= j:
        L = {int(result) for result in str(j)}
        if D.isdisjoint(L):
            D_love = j
            break
print(D_love)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
D  = {int(n) for n in input().split()}
a = {i for i in range(10)}
N_hate = a.difference(D)
for j in range(10001):
    if N <= j:
        L = {int(result) for result in str(j)}
        if N_hate == L:
            N_love = j
            break
print(N_love)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
de_num = list(map(int, input().split()))
ok_num = []
cand_num = []
ans_num = []

for i in range(10):
  if i not in de_num:
    ok_num.append(i)

for i in ok_num:
  for j in ok_num:
    for k in ok_num:
      for l in ok_num:
        num = 1000*i + 100*j + 10*k + l
        cand_num.append(num)

for cd in cand_num:
  if cd >= N:
    ans_num.append(cd)

print(min(ans_num))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
l=[0,1,2,3,4,5,6,7,8,9]
for i in range(k):
  l.remove(d[i])
L=[]
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        L.append(l[j1]*1000+l[j2]*100+l[j3]*10+l[j4])
for k in range(len(L)):
  if L[k]>=n:
    x=L[k]
    break
print(x)

Submission status: Runtime Error

Solution code:
import itertools
def main():
    n,k = map(int, input().split())
    ds =  map(int, input().split())
    canuse = [i for i in range(10)]
    for d in ds: canuse.remove(d)
    canuse = [str(c) for c in canuse]
    digit = len(str(n))
    x = [int("".join(a)) for a in itertools.product(canuse, repeat=digit) if int("".join(a))>=n]
    print(min(x))
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# encoding: utf-8
N, K = map(int, input().split())
D = list(map(int, input().split()))

Db = []
for Di in range(10):
    if Di not in D: Db.append(Di)
# print("#", Db)

for level in range(6):
    if N // (10 ** level) < 1: break
# print("#", level)
    
memo = [None] * (level * 10000)
    
def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos > level or tmp >= N:
        if tmp >= N:
            # print("###", tmp)
            return tmp
        else: return 10000
    elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]
    rets = []
    for Dbi in Db:
        add = Dbi * (10 ** pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret    
    return ret

print(pay(0, 0))

Submission status: Runtime Error

Solution code:
price, len_hate_set = map(int, input().split())
hate_set = set([int(i) for i in input().split()])

ans = 0

while True:
    if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set, [int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
        return ans
    ans += 1

Submission status: Runtime Error

Solution code:
price, len_hate_set = map(int, input().split())
hate_set = set([int(i) for i in input().split()])

ans = 0

while True:
    if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set, 
               [int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
        print ans

    ans += 1

Submission status: Runtime Error

Solution code:
n, k = input().split()
dic = [int(_) for _ in input().split()]
not_in = [i for i in range(10) if i not in dic]
ans = [min(list(filter(lambda x: int(i) <= x, not_in))) for i in n]
print(''.join(map(str, ans)))

Submission status: Runtime Error

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

for i in range(100000):
  m = n + i
  N = []
  while(m > 0):
    N.append(m%10)
    m //= 10
  N.reverse()
  if N.intersection(d) == []:
    print(N)
    exit()
  else:
    continue

Submission status: Runtime Error

Solution code:
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

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

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    for num in d:
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+1, d)
    return x

  
amount = check_num(N, D)
print(amount)

Submission status: Runtime Error

Solution code:
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

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

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    for num in d:
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+1, d)
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D)
    print(amount)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

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

test_mode = False


def check_num(x, d, n):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+n を想定）
    d : 嫌いな数字のリスト（D を想定）
    n : 元の金額（N を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら元の金額 n を足して再試行する。
    """
    if test_mode:
        print('x =', x)
    for num in d:
        if test_mode:
            print('num =', num)
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+n, d, n)
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D, N)
    print(amount)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
aUnList.sort()
sN = str(iN)
iF = int(sN[0])

def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
    iL = len(sTarget)
    iF = int(sTarget[iPoint])
    aUpper = [x for x in aUnList if x >= iF]
    aUpper.sort()
    if bRev: #遡ってきたとき
        #もうひとつ上があるかどうか
        if len(aUpper) == 1 and aUpper[0] == iF: #==のとき。もうひとつ上はない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])] * iL
            else:
                return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
        else: #上の桁がある
            if len(aUpper) == 1:
                iNext = aUpper[0]
            else:
                iNext = aUpper[1]
            return aRet[0:iPoint]+[str(iNext)]+[str(aUnList[0])]*(iL-1-iPoint)
    else: #順向
        if aUpper == []: #大きい数字がない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])]*(iL+1)
            else:
                return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
        else:
            if aUpper[0] != iF:
                return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
            else:
                aRet.append(str(iF))
                if iPoint  < iL -1 :
                    return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
                else:
                    return aRet

print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))

Submission status: Runtime Error

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
sN = str(iN)
iF = int(sN[0])

def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
    iL = len(sTarget)
    iF = int(sTarget[iPoint])
    aUpper = [x for x in aUnList if x >= iF]
    if bRev: #遡ってきたとき
        #もうひとつ上があるかどうか
        if len(aUpper) == 1 and aUpper[0] == iF: #==のとき。もうひとつ上はない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])] * iL
            else:
                return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
        else: #上の桁がある
            if len(aUpper) == 1:
                iNext = aUpper[0]
            else:
                iNext = aUpper[1]
            return aRet[0:iPoint]+[str(iNext)]+[str(aUnList[0])]*(iL-1-iPoint)
    else: #順向
        if aUpper == []: #大きい数字がない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])]*(iL+1)
            else:
                return fCheckDigit(sTarget,iPoint-1,aUnList,aRet,False)
        else:
            if aUpper[0] != iF:
                return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
            else:
                aRet.append(str(iF))
                if iPoint  < iL -1 :
                    return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
                else:
                    return aRet

print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))

Submission status: Runtime Error

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
sN = str(iN)
iF = int(sN[0])

def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
    iL = len(sTarget)
    iF = int(sTarget[iPoint])
    aUpper = [x for x in aUnList if x >= iF]
    if bRev: #遡ってきたとき
        #もうひとつ上があるかどうか
        if len(aUpper) == 1 and aUpper[0] == iF : #==のとき。もうひとつ上はない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])] * iL
            else:
                return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
        else: #上の桁がある
            return aRet[0:iPoint]+[str(aUpper[1])]+[str(aUnList[0])]*(iL-1-iPoint)
    else: #順向
        if aUpper == []: #大きい数字がない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])]*(iL+1)
            else:
                return fCheckDigit(sTarget,iPoint-1,aUnList,aRet,False)
        else:
            if aUpper[0] != iF:
                return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
            else:
                aRet.append(str(iF))
                if iPoint  < iL -1 :
                    return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
                else:
                    return aRet



print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))

Submission status: Runtime Error

Solution code:
N , K = map(int,input().split())
lst = []
for i in range(K):
    lst.append(input())
start = N
while True:
    for num in str(start):
        if num in lst:
            break
    else:
        break
    start += 1
print(str(start))

Submission status: Runtime Error

Solution code:
xs, k = input().split()

k = int(k)

xs = [int(x) for x in list(xs)]

ds = set([int(d) for d in input().split()])
#print(ds)
ans = []
for x in xs:
  if x not in ds:
    ans.append(x)
  else:
    us = [ u for u in range(0,10) if u not in ds ]    
    #print(us)
    x = sorted([ p for p in us if p > x ]).pop(0)
    ans.append(x)
print(''.join(map(str,ans)))

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    c += 1
print(c)

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(c)
    for i in c:
        if i in s: f = 0
    if f : break
    c += 1
print(c)

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(c)
    for i in s:
        if i in c: f = 0
    if f : break
    c += 1
print(c)

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(c)
    for i in c:
        if i in c: f = 0
    if f : break
    c += 1
print(c)

Submission status: Runtime Error

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

for i in range(len(str(n))+1):
	if str(n)[~i] not in d:
		continue
	while str(n)[~i] in d:
		n += 10**i
print(n)

Submission status: Runtime Error

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

for i in range(len(str(n))+1):
	if str(n)[~i] not in d:
		break
	while str(n)[~i] in d:
		n += 10**i
print(n)

Submission status: Runtime Error

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

for i in range(len(str(n))+1):
	while str(n)[~i] in d:
		n += 10**i
print(n)

Submission status: Runtime Error

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

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

us = [ i for i in range(10) if i not in ds]
#print(us)

oo = [int(s) for s in str(N)]

o_u = {}
for o in oo:
  o_u[o] = min(list(filter(lambda x:x>=o, us)))

n = str(N)
for o, u in o_u.items():
  n = n.replace(str(o),str(u))

print(n)

Submission status: Runtime Error

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

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

z = 0
while z in Ds:
  z += 1

for i in range(len(word)):
  for j in range(len(Ds)):
    if word[-i-1] in Ds:
      word[-i-1] += 1
      if i > 0:
        word[-i:] = [z for i in range(i)]
      if word[-i-1]>=10:
        word[-i-2] += 1
        word[-i-1:] += [z for i in range(i+1)]
s = list(map(str,word))

print(''.join(s))

Submission status: Runtime Error

Solution code:
n, k = map(int,input().split())
n = str(n)
unlike = list(map(int,input().split()))
like = []
ans = ''
for i in range(1, 10):
    if i not in unlike:
        like.append(i)

for num in range(len(n)):
    for i in like:
        if n[0] == 9 and (9 not in like):
            ans += like[0]
            break
        if int(n[num]) <= i:
            ans += str(i)
            break
    if len(ans) != (num + 1):
        for j in like:
            if int(ans[num - 1]) < j:
                ans[num - 1] == j
                break
    if num == 0:
        like.insert(0,0)
print(ans)

Submission status: Runtime Error

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

'''
n = 10
k = 8
d = [0, 2, 3]
D = [i for i in range(10)]
'''
like_vals = [int(str(i)) for i in D if i not in d]

i = 0

n = [int(str(n)[i]) for i in range(len(str(n)))]
r = [-1] * len(n)
while i < len(n):
    if n[i] in like_vals:
        r[i] = n[i]
        i += 1
    elif n[i] < max(like_vals):
        like_bigger = [like_val for like_val in like_vals if like_val > n[i]]
        r[i] = min(like_bigger)
        for j in range(i + 1, len(n)):
            r[j] = min(like_vals)
        break
    else:
        r = [-1] * (len(n) + 1)
        if min(like_vals) != 0:
            r[0] = min(like_vals)
        else:
            r[0] = min([like_val for like_val in like_vals if like_val != 0])

        for j in range(1, len(n) + 1):
            r[j] = min(like_vals)
        break

print(r)

Submission status: Runtime Error

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

# OK 숫자의 집합을 구하고,
# 각 자리수부터 들어가 NG 숫자를 OK숫자로 바꿔주면 되는 거 아냐?
n = list(n)
ng = set(d)
for i in range(len(n)):
#     print(ng)
    ok = set([str(i) for i in range(10)]) - ng
#     print(ok)
    if i == 0:
        ok.remove('0')
    if n[i] in ng:
        n[i] = str(min(ok))
print(''.join(n))

Submission status: Runtime Error

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

for i in range(10*n+2):
  if i >= n:
    s = str(i)
    for j in range(len(s)):
      if int(s[j]) in d:
        break
    else:
      print(i)
      return 0

Submission status: Runtime Error

Solution code:
def c_iroha_obsession(N, K, D):
    for ans in range(N, 10 * N + 1):
        for digit in str(ans):  # 1桁ずつ調べる
            if int(digit) in D:  # 嫌いな数字があった
                break
        else:  # 嫌いな数字がなかった。このときのansが解
            break
    return ans
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_IrohaObsession(N, K, D))

Submission status: Runtime Error

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

    for i in range(10):
        if i not in D:
            min_ = i
            break

    ans = []
    apnd = ans.append
    num, i = N, 0
    while num > 0:
        while num % 10 in D:
            num += 1
            top = i
        num, m = divmod(num, 10)
        apnd(m)
        i += 1

    ans[0:top] = [min_] * top
    print(*ans[::-1], sep='')

main()

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
for i in range(l):
    while l[i] in D:
        shiharai+=1
        l = [int(x) for x in list(str(shiharai))]
print(shiharai)

Submission status: Runtime Error

Solution code:

input_array = list(map(int,input().split()))
N = input_array[0]
input_array = list(map(int,input().split()))

num = [1,1,1,1,1,1,1,1,1,1]
ok = []
out = []

for l in range(len(input_array)):
    num[input_array[l]] = 0

for i in range(len(num)):
    if num[i] == 1:
        ok.append(i)

N = list(str(N))

for n in N:
    for m in ok:
        if m >= int(n):
            out.append(m)
            break

for i in range(len(out)-1):
    print(out[i],end="")

print(out[-1])

Submission status: Runtime Error

Solution code:
li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]

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


minvalue=N
temp=0

for i in range(10*N):
    i=i+N
    numtemp=i
    num_4=int(i/10000)
    i=i-10000*num_4
    num_3=int(i/1000)
    i=i-1000*num_3
    num_2=int(i/100)
    i=i-100*num_2
    num_1=int(i/10)
    i=i-10*num_1
    num_0=i
    
    for j in range(K):
        if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j])and(num_4!=D[j]):
            temp+=1
            
    if temp==K:
        num=numtemp
        break
    
    temp=0

print(num)

Submission status: Runtime Error

Solution code:
li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]

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


minvalue=N
temp=0

for i in range(10*(N+1)):
    i=i+N
    numtemp=i
    num_4=int(i/10000)
    i=i-10000*num_4
    num_3=int(i/1000)
    i=i-1000*num_3
    num_2=int(i/100)
    i=i-100*num_2
    num_1=int(i/10)
    i=i-10*num_1
    num_0=i
    
    for j in range(K):
        if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j]):
            if j==K-1:
                temp=1
        else:
            break
    if temp==1:
        num=numtemp
        break

print(num)

Submission status: Runtime Error

Solution code:

li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]

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


minvalue=N
temp=0

for i in range(N+1):
    i=i+N
    numtemp=i
    num_4=int(i/10000)
    i=i-10000*num_4
    num_3=int(i/1000)
    i=i-1000*num_3
    num_2=int(i/100)
    i=i-100*num_2
    num_1=int(i/10)
    i=i-10*num_1
    num_0=i
    
    for j in range(K):
        if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j]):
            if j==K-1:
                temp=1
        else:
            break
    if temp==1:
        num=numtemp
        break

print(num)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=list(input().split())
for i in range(n,100001):
    set_i=set(list(str(i)))
    for j in set_i:
        if s in d:
            break
    else:
        print(i)
        break

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""042-c"""

import sys

ZERO_UNICODE = 48


def solve(dislike_digits_table, first_like_digit, number):
    """Solve."""
    if dislike_digits_table[int(number[0])]:
        while dislike_digits_table[int(number[0])]:
            number = "{0}{1}".format(chr(ord(number[0]) + 1), number[1:])
        number = number.replace(number[1:], first_like_digit * (len(number) - 1))

    return number


def main():
    """Main function."""
    dislike_digits_table = [False for _ in range(10)]

    N, _ = sys.stdin.readline().split(' ')
    digits = map(int, sys.stdin.readline().split(' '))

    for digit in digits:
        dislike_digits_table[digit] = True

    first_like_digit = str(next(i for i, v
                            in enumerate(dislike_digits_table)
                            if not v))

    for i, d in enumerate(N):
        if dislike_digits_table[int(d)]:
            N = N.replace(N[i:], solve(dislike_digits_table, first_like_digit, N[i:]))
            break

    print(N)


if __name__ == '__main__':
    sys.exit(main())

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
L = [i for i in range(10) if i not in D]
A = []
for i in L:
  A.append(i)
for i in L:
  for j in L:
    A.append(10*i+j)
for  i in L:
  for j in L:
    for k in L:
      A.append(100*i+10*j+k)
for i in L:
  for j in L:
    for k in L:
      for l in L:
        A.append(1000*i+100*j+10*k+l)

for i in L:
  for j in L:
    for k in L:
      for l in L:
        for m in L:
A.append(10000*i+1000*j+100*k+10*l+m)

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

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
dislikes = list(map(int, input().split())
m = n
while True:
    m = list(str(m))
    l = []
    for p in m:
        if int(p) not in dislikes:
            l.append(p)
            continue
        else:
            m = int(''.join(m))+1
            break
    if len(l) >= len(str(n)):
        if int(''.join(l))>=n:
            break
print(''.join(m))

Submission status: Runtime Error

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

#N, K = (99999, 8)
#ds = [0,1,2,3,4,5,6,7,9]

def run_code(N, K, ds):

    dislike_digits_set = set(i for i in ds)
    avail_digits = [i for i in range(10) if i not in dislike_digits_set]
    avail_min = avail_digits[0]

    def get_next_digit(d):
        last = 10
        for ad in (avail_digits + [last]):
            if ad >= d:
                if ad == last:
                    return (1, avail_min)
                else:
                    return (0, ad)

    def to_num(n_digits):
        num = 0
        n = len(n_digits)
        for i in range(n):
            num += n_digits[i] * 10**(n-i-1)
        return num

    def to_digits(num):
        return [int(i) for i in str(num)]

    def search_nearest_larger(num):
        n_digits = to_digits(num)
        n = len(n_digits)

        for i in range(n):
            d_in = n_digits[i]
            inc, d_out = get_next_digit(d_in)
            if inc == 0 and d_in == d_out:
                continue
            if inc > 0:
                num += 10**(n-i)
                return search_nearest_larger(num)
            else:
                n_digits[i] = d_out
                return to_num(n_digits[:i+1] + [avail_min]*(n-i-1))

        return to_num(n_digits)

    return search_nearest_larger(N)



res = run_code(N, K, ds)
print(res)