Problem:


Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
ds = list(map(int, input().split()))
oks = [i for i in range(0, 10) if i not in ds]

nums = list(map(int, list(str(n))))
nums.reverse()
ans = []

more_one_flag = False
for c in nums:
    # c以上の数字を探索
    if more_one_flag:
        c += 1
    for i in range(c, 10):
        if i not in ds:
            ans.append(i)
            more_one_flag = False
            break
        if i == 9 and i in ds:
            # 一番小さいのにするしかない
            ans.append(min(oks))
            more_one_flag = True

ans.reverse()

if int(''.join(map(str, ans))) >= n:
    # ok
    print(int(''.join(map(str, ans))))
else:
    if 0 in oks:
        oks.remove(0)

    ans.reverse()
    ans.append(min(oks))
    ans.reverse()
    print(int(''.join(map(str, ans))))

Submission status: Wrong Answer

Solution code:
import sys

N, K = [int(s) for s in input().split(' ')]
D = [int(s) for s in input().split(' ')]

digits = set(range(0, 10))
excepts = set(D)

D = list(sorted(digits - excepts))

res_digits = []


N2 = N
while N > 0:
    d = N % 10

    x = D[0]
    for d2 in D:
        if d2 >= d:
            x = d2
            break

    res_digits.append(x)

    N = int(N / 10)

M = 0
for d in reversed(res_digits):
    M = M * 10 + d

if len(res_digits) == 0:
    print(D[0])
    sys.exit()

if M < N2:
    if D[0] == 0:
        res_digits.append(D[1])
    else:
        res_digits.append(D[0])
    M = 0
    for d in reversed(res_digits):
        M = M * 10 + d

print(M)

Submission status: Wrong Answer

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

digits = set(range(0, 10))
excepts = set(D)

D = list(sorted(digits - excepts))

res_digits = []


N2 = N
while N > 0:
    d = N % 10

    x = D[0]
    for d2 in D:
        if d2 >= d:
            x = d2
            break

    res_digits.append(x)

    N = int(N / 10)

M = 0
for d in reversed(res_digits):
    M = M * 10 + d

if M < N2:
    if D[0] == 0:
        res_digits.append(D[1])
    else:
        res_digits.append(D[0])
    M = 0
    for d in reversed(res_digits):
        M = M * 10 + d


if N2 == 0:
    print(D[0])
else:
    print(M)

Submission status: Wrong Answer

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

digits = set(range(0, 10))
excepts = set(D)

D = list(sorted(digits - excepts))

res_digits = []

N2 = N
while N > 0:
    d = N % 10

    x = D[0]
    for d2 in D:
        if d2 >= d:
            x = d2
            break

    res_digits.append(x)

    N = int(N / 10)

M = 0
for d in reversed(res_digits):
    M = M * 10 + d

if M < N2:
    if D[0] == 0:
        res_digits.append(D[1])
    else:
        res_digits.append(D[0])
    M = 0
    for d in reversed(res_digits):
        M = M * 10 + d

print(M)

Submission status: Wrong Answer

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

digits = set(range(0, 10))
excepts = set(D)

D = list(sorted(digits - excepts))

res_digits = []

N2 = N
while N > 0:
    d = N % 10

    x = D[0]
    for d2 in D:
        if d2 >= d:
            x = d2
            break

    res_digits.append(x)

    N = int(N / 10)

M = 0
for d in reversed(res_digits):
    M = M * 10 + d

if M < N2:
    res_digits.append(D[0])
    M = 0
    for d in reversed(res_digits):
        M = M * 10 + d

print(M)

Submission status: Wrong Answer

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

digits = set(range(0, 10))
excepts = set(D)

D = list(sorted(digits - excepts))

res_digits = []

while N > 0:
    d = N % 10

    x = 0
    for d2 in D:
        if d2 >= d:
            x = d2
            break

    res_digits.append(x)

    N = int(N / 10)

if res_digits[-1] == 0:
    if D[0] == 0:
        res_digits.append(D[1])
    else:
        res_digits.append(D[0])

M = 0
for d in reversed(res_digits):
    M = M * 10 + d

print(M)

Submission status: Wrong Answer

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

digits = set(range(0, 10))
excepts = set(D)

D = list(sorted(digits - excepts))

res_digits = []

while N > 0:
    d = N % 10

    x = 0
    for d2 in D:
        if d2 >= d:
            x = d2
            break

    res_digits.append(x)

    N = int(N / 10)

if res_digits[-1] == 0:
    if D[0] == 0:
        res_digits.append(0)
        res_digits.append(D[1])
    else:
        res_digits.append(D[0])

M = 0
for d in reversed(res_digits):
    M = M * 10 + d

print(M)

Submission status: Wrong Answer

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

digits = set(range(0, 10))
excepts = set(D)

D = list(sorted(digits - excepts))

res_digits = []

while N > 0:
    d = N % 10

    x = 0
    for d2 in D:
        if d2 >= d:
            x = d2
            break

    res_digits.append(x)

    N = int(N / 10)

if res_digits[-1] == 0:
    res_digits.append(D[0])
    if D[0] == 0:
        res_digits.append(0)
        res_digits.append(D[1])

M = 0
for d in reversed(res_digits):
    M = M * 10 + d

print(M)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = [int(i) for i in range(10) if i not in d]

ans = ""
next_d = 0
for i in range(len(str(n))-1, -1, -1):
    idx = bisect.bisect_left(a, int(str(n)[i])+next_d)
    if idx == len(a):
        next_d = 1
        ans = str(a[0]) + "".join([str(a[0]) for j in range(len(ans))])
    else:
        next_d = 0
        ans = str(a[idx]) + ans
if next_d == 1:
    idx = bisect.bisect_left(a, 1)
    if idx == len(a):
        ans = str(a[0]) + "".join([str(a[0]) for j in range(len(ans))])
    else:
        ans = str(a[idx]) + ans
print(ans)

Submission status: Wrong Answer

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

a = [int(i) for i in range(10) if i not in d]

ans = ""
next_d = 0
for i in range(len(str(n))-1, -1, -1):
    idx = bisect.bisect_left(a, int(str(n)[i])+next_d)
    if idx == len(a):
        next_d = 1
        ans = str(a[0]) + "".join([str(a[0]) for j in range(len(ans))])
    else:
        next_d = 0
        ans = str(a[idx]) + ans
if next_d == 1:
    idx = bisect.bisect_left(a, 1)
    if idx == len(a):
        ans = str(a[0]) + ans
    else:
        ans = str(a[idx]) + ans
print(ans)

Submission status: Wrong Answer

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

a = [int(i) for i in range(10) if i not in d]

ans = ""
next_d = 0
for i in range(len(str(n))-1, -1, -1):
    idx = bisect.bisect_left(a, int(str(n)[i])+next_d)
    if idx == len(a):
        next_d = 1
        ans = str(a[0]) + ans
    else:
        next_d = 0
        ans = str(a[idx]) + ans
if next_d == 1:
    idx = bisect.bisect_left(a, 1)
    if idx == len(a):
        ans = str(a[0]) + ans
    else:
        ans = str(a[idx]) + ans
print(ans)

Submission status: Wrong Answer

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

a = [int(i) for i in range(10) if i not in d]
m = "0" + str(n)
ans = ""
next_d = 0
for i in range(len(m)-1, -1, -1):
    idx = bisect.bisect_left(a, int(m[i])+next_d)
    if idx == len(a):
        next_d = 1
        ans = str(a[0]) + ans
    else:
        next_d = 0
        ans = str(a[idx]) + ans
print(ans)

Submission status: Wrong Answer

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

a = [int(i) for i in range(10) if i not in d]

ans = ""
next_d = 0
for i in range(len(str(n))-1, -1, -1):
    idx = bisect.bisect_left(a, int(str(n)[i])+next_d)
    if idx == len(a):
        next_d = 1
        ans = str(a[0]) + ans
    else:
        next_d = 0
        ans = str(a[idx]) + ans
print(ans)

Submission status: Wrong Answer

Solution code:

N, K = [int(i) for i in input().split()]
d = [i for i in input().split()]

digit = 0

while(True):
    n = int(N/(10**digit)) % 10        #nは桁digitの値
    if(str(n) in d):
   #     print(n, "in d")        
        N += 10**(digit)               #nは嫌いな数字なので加算
        continue
     
    digit += 1                         #nがきらいな数字でなければ次の桁を参照
    if(10**digit > N):                 #参照する桁がNを超えたら終了
        break
       
print(N)

Submission status: Wrong Answer

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

digit = 0

while(True):
    n = int(N/(10**digit)) % 10        #nは桁digitの値
    if(str(n) in d):
   #     print(n, "in d")        
        N += 10**(digit)            #nは嫌いな数字なので加算
        continue
     
    digit += 1                      #nがきらいな数字でなければ次の桁を参照
    if(10**digit > N):
        break
       
print(N)

Submission status: Wrong Answer

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

payment = int(N)

while(True):
    for i in range(len(str(payment)) -1, -1, -1):
        if(str(payment)[i] in d):
            payment += 10 ** (len(str(payment)) -1 - i)
            continue

    print(payment)
    break

Submission status: Wrong Answer

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

payment = int(N)

while(True):
    for i in range(len(str(payment)) -1, -1, -1):
        print(i)
        if(str(payment)[i] in d):
            print(i, "don't like it")
            payment += 10 ** (len(str(payment)) -1 - i)
            continue

    print(payment)
    break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
F = set(range(10)) - set(map(int, input().split()))

w = N
a = 1
while True:
  if w % 10 in F:
    if w < 10:
      break
    w //= 10
    a *= 10
  else:
    w += 1
    N += a
print(N)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
F = set(range(10)) - set(map(int, input().split()))

w = N
a = 1
while w > 0:
  if w % 10 in F:
    w //= 10
    a *= 10
  else:
    w += 1
    N += a
print(N)

Submission status: Wrong Answer

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

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

use = sorted(list(A - D))

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

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

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

    print(x)

Submission status: Wrong Answer

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

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

use = sorted(list(A - D))

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

    mapans = map(str,ans)
    x = int(''.join(mapans))
    while x < N:
        for j in range(len(use)):
            if x >= N:
                break;
            else:
                x += use[j]

    print(x)

Submission status: Wrong Answer

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

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

use = sorted(list(A - D))

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

    while x <= N:
        for j in range(len(use)):
            mapans = map(str,ans)
            x = int(''.join(mapans))
            if x >= N:
                break;
            else:
                x += use[j]

    print(x)

Submission status: Wrong Answer

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

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

use = sorted(list(A - D))

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

    while x <= N:
        for j in range(len(use)):
            mapans = map(str,ans)
            x = int(''.join(mapans))
            if x >= N:
                break;
            else:
                x += use[j]
                print('ans',ans)

    print(x)

Submission status: Wrong Answer

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

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

use = sorted(list(A - D))

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

    for i in range(len(ans)):
        for j in range(len(use)):
            mapans = map(str,ans)
            x = int(''.join(mapans))
            if x >= N:
                break;
            else:
                ans[len(ans)-i-1] = use[len(use)-j-1]
                print('ans',ans)

    print(x)

Submission status: Wrong Answer

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

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

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]

if N > max(use):
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[1] for i in range(len(N_list)+1)]
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[1] for i in range(len(N_list))]

for i in range(len(ans)):
    for j in range(len(use)):
        ans[len(ans)-i-1] = use[j]
        mapans = map(str,ans)
        x = int(''.join(mapans))
        if x >= N:
            break;

print(x)

Submission status: Wrong Answer

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

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

use = sorted(list(A - D))

ans = [min(use) for i in range(len(N_list))]

if N_list[0] > max(use):
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[1] for i in range(len(N_list)+1)]
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[1] for i in range(len(N_list))]

for i in range(len(ans)):
    for j in range(len(use)):
        ans[len(ans)-i-1] = use[j]
        mapans = map(str,ans)
        x = int(''.join(mapans))
        if x >= N:
            break;

print(x)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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())

N,K = LI()
D = [str(i) for i in input().split()]


def main():
    ans = N
    while True:
        for i in range(K):
            # print(list(str(ans)))
            if D[i] in list(str(ans)):
                # print(ans)
                ans += 10**max((len(str(ans))-list(str(ans)).index(D[i])-1),0)
                break
            if i == K - 1:
                return ans

print(main())

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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())

N,K = LI()
D = [str(i) for i in input().split()]


def main():
    ans = N
    while True:
        for i in range(K):
            # print(list(str(ans)))
            if D[i] in list(str(ans)):
                print(ans)
                ans += 10**max((len(str(ans))-list(str(ans)).index(D[i])-1),0)
                break
            if i == K - 1:
                return ans

print(main())

Submission status: Wrong Answer

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

for i in range(N, 10000):
    flag = True
    for j in str(i):
        if j in D:
            flag = False
            break
    if flag:
        print(i)
        exit()

Submission status: Wrong Answer

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


def check_contain(cost):
    contain = False
    for dn in dislike_num:
        if str(cost).count(str(dn)) != 0:
            return True
    return contain


for i in range(N, 10000):
    if not check_contain(i):
        print(i)
        exit()

Submission status: Wrong Answer

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


def check_contain(cost):
    for dn in dislike_num:
        if str(cost).count(str(dn)) == 0:
            return False
        else:
            return True


for i in range(N, 10000):
    if not check_contain(i):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(input().split())
while N<100000:
    fr=False
    for j in D:
        if j in str(N):
            N+=1
            fr=True
            break
        if fr:
            continue
        else:
            print(N)
            exit()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LS()

  for i in range(n,100001):
    for j in str(i):
      if j not in l:
        return i
      else:
        break

print(main())

Submission status: Wrong Answer

Solution code:
[n,k]=[int(_) for _ in input().split()]
d=[int(_) for _ in input().split()]
while True:
  t=str(n).split()
  for _t in t:
    if _t in d:
      n+=1
      continue
  break
print(n)

Submission status: Wrong Answer

Solution code:
import sys

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

number_set = {0,1,2,3,4,5,6,7,8,9}
iroha_set = set(D)
usage_set = number_set - iroha_set
usage_list = list(usage_set)

str_N = str(N)
ans_list = []

str_list = []
for i in range(len(str_N)):
    str_list.append(str(max(usage_set)))

escape_flag = 0
ans_num = 0
for i in reversed(range(len(str_N))):
    for j in reversed(list(usage_set)):
        str_list[i] = str(j)
        temp_str2 = ''
        for k in range(len(str_N)):
            temp_str2 += str_list[k]
        temp_num2 = int(temp_str2)
        if temp_num2 < N:
            escape_flag = 1
            break
        ans_num = temp_num2
    if escape_flag == 1:
        break

if ans_num < N:
    ans_str = []
    if usage_list[0] == 0:
        ans_str.append(usage_list[1])
    else:
        ans_str.append(0)
    for i in range(len(str_N)):
        ans_str.append(str(min(usage_set)))
    ffff = ''
    for i in ans_str:
        ffff += str(i)
    ans_num = int(ffff)

print(ans_num)

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

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

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

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

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

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

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

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

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

min_available = sorted(available)[0]
max_available = sorted(available, reverse=True)[0]

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

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

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

print(ans_val)

Submission status: Wrong Answer

Solution code:
def main():
    n,k=map(int,input().split(' '))
    d = list(map(int,input().split(' ')))
    like_list = [i for i in range(10) if i not in d]
    n_list=list(str(n))
    ans = 0
    for num,i in enumerate(n_list):
        tmp = 0
        for j in like_list:
            if int(i) <= j:
                tmp= j
                break
            else:
                tmp = j
        ans+=(j*(10**(len(n_list)-num-1)))
    if ans >=n:
        pass

    elif like_list[-1]*1111%(10**(len(n_list))) < n:
        ans = like_list[0]*11111%(10**(len(n_list)+1))
        if ans <n:
            ans = like_list[1]*10000
    else:
        for i in range(len(list(str(ans)))):
            if ans >=n:
                break
            for j in like_list:
                if ans//(10**(i+1))*(10**(i+1)) + j*(10**i)+like_list[0]*1111%(10**i) >= n:
                    ans = ans//(10**(i+1))*(10**(i+1)) + j*(10**i)+like_list[0]*1111%(10**i)
                    break
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    n,k=map(int,input().split(' '))
    d = list(map(int,input().split(' ')))
    like_list = [i for i in range(10) if i not in d]
    n_list=list(str(n))
    ans = 0
    for num,i in enumerate(n_list):
        tmp = 0
        for j in like_list:
            if int(i) <= j:
                tmp= j
                break
            else:
                tmp = j
        ans+=(j*(10**(len(n_list)-num-1)))
    if ans >=n:
        print(ans)

    elif like_list[-1]*1111%(10**(len(n_list))) < n:
        ans = like_list[0]*11111%(10**(len(n_list)+1))
        if ans <n:
            ans = like_list[1]*10000
    else:
        for i in range(len(list(str(ans)))):
            if ans >=n:
                break
            for j in like_list:
                if ans//(10**(i+1))*(10**(i+1)) + j*(10**i)+like_list[0]*1111%(10**i) >= n:
                    ans = ans//(10**(i+1))*(10**(i+1)) + j*(10**i)+like_list[0]*1111%(10**i)
                    break
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    n,k=map(int,input().split(' '))
    d = list(map(int,input().split(' ')))
    like_list = [i for i in range(10) if i not in d]
    n_list=list(str(n))
    ans = 0
    for num,i in enumerate(n_list):
        tmp = 0
        for j in like_list:
            if int(i) <= j:
                tmp= j
                break
            else:
                tmp = j
        ans+=(j*(10**(len(n_list)-num-1)))
    if ans >=n:
        print(ans)
    else:
        for i in range(len(list(str(ans)))):
            if ans >=n:
                break
            for j in like_list:
                if ans//(10**(i+1))*(10**(i+1)) + j*(10**i)+like_list[0]*1111%(10**i) >= n:
                    ans = ans//(10**(i+1))*(10**(i+1)) + j*(10**i)+like_list[0]*1111%(10**i)
                    break
        if ans < n:
            ans = like_list[0]*(10**len(n_list))+like_list[0]*1111%(10**(len(n_list)))
        print(ans)
        
main()

Submission status: Wrong Answer

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

for i in range(N, 10010):
    flag = True
    tmp = i
    for j in reversed(range(len(str(i)))):
        if (tmp // (10 ** j)) in d:
            flag = False
            break
        else:
            tmp = tmp % (10 ** j)

    if flag:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
def dfs(i, s, l):
    if i == len(s):
        return ''
    for j in l:
        if j >= int(s[i]):
            ans = dfs(i + 1, s, l)
            if ans is not None:
                ans += str(j)
                return ans
    return None

n, k = map(int, input().split())
ns = str(n)
d = list(map(int, input().split()))
l = [i for i in range(10) if i not in d]
ans = dfs(0, ns, l)
if ans is None:
    if l[0] == 0:
        ans = str(l[1]) + str(l[0]) * len(ns)
    else:
        ans = str(l[0]) * (len(ns) + 1)
else:
    ans = ans[::-1]
print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(i, s, l):
    if i == len(s):
        return ''
    for j in l:
        if j >= int(s[i]):
            ans = dfs(i + 1, s, l)
            if ans is None:
                continue
            else:
                ans += str(j)
                return ans
    return None

n, k = map(int, input().split())
ns = str(n)
d = list(map(int, input().split()))
l = [i for i in range(10) if i not in d]
ans = dfs(0, ns, l)
if ans is None:
    if l[0] == 0:
        ans = l[1] + l[0] * len(ns)
    else:
        ans = l[0] * (len(ns) + 1)
else:
    ans = ans[::-1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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