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:
from itertools import product

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
se = set(range(10))
for x in A:
    se ^= set([x])

ans = 10 ** 10
for x in product(se, repeat=5):
    M = 10000 * x[0] + 1000 * x[1] + 100 * x[2] + 10 * x[3] + x[4]
    if M >= N:
        ans = min(ans, M)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
se = set(range(10))
for x in A:
    se ^= set([x])

ans = 10 ** 10
for x in product(se, repeat=4):
    M = 1000 * x[0] + 100 * x[1] + 10 * x[2] + x[3]
    if M >= N:
        ans = min(ans, M)
print(ans)

Submission status: Wrong Answer

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

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


print(m)

Submission status: Wrong Answer

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 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: Wrong Answer

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
    m += a[y-i+1]*(10**(i))
    i+=1


print(m)

Submission status: Wrong Answer

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:
            k=0
        else:
            k=1
        for i in range(len(N)+1):
            ans.append(like[k])
        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: Wrong Answer

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:
        for i in range(len(N)+1):
            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: Wrong Answer

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:
        for i in range(len(N)+1):
            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(answer)

Submission status: Wrong Answer

Solution code:
import itertools

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

D = set(input().split())

n = [x for x in str(N)]
num = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D
judge = "no"
ans = N

for i in n:
    if i in D:
        judge = "yes"
        break

if judge == "yes":
    if ans < int(list(num)[-1] * len(n)):
        ans_list = sorted(list(itertools.product(num, repeat=len(n))))
        for i in ans_list:
            if int("".join(i)) > ans:
                ans = int("".join(i))
                break
    else:
        ans_list = sorted(list(itertools.product(num, repeat=len(n) + 1)))
        for j in ans_list:
            if int("".join(j)) > ans:
                ans = int("".join(j))
                break

print(ans)

Submission status: Wrong Answer

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

for n in range(N, 10001):
    n = str(n)
    for s in n:
        if s in D:
            break
    else:
        print(n)
        exit()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
D = list(map(int,input().split()))
use = [i for i in range(10)]
use = sorted(list(set(use)-set(D)))
ans = ''
for a in str(n):
    a = int(a)
    flg = False
    for j in use:
        if flg:
            continue
        if j>=a:
            flg = True
            ans += str(j)     
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
D = list(map(str,input().split()))
use = [str(i) for i in range(10)]
use = set(use) - set(D)
for x in range(n, 10010):
    flg = True
    for c in str(x):
        if c not in use:
            flg = False
    if flg:
        print(x)
        break

Submission status: Wrong Answer

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 = list()
m = 0
while i <= y:
    a.append(((n//(10**(y-i)))%10))
    j = 0
    while j < k:
        if a[i] == d[j]:
            a[i] += 1
        j+=1
    m += a[i]*(10**(y-i))
    i+=1


print(m)

Submission status: Wrong Answer

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

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

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


print(m)

Submission status: Wrong Answer

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

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

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


print(m)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
res = f_inf


def resolve():
    n, k = map(int, input().split())
    D = set(list(map(int, input().split())))
    Available = []

    for i in range(10):
        if i not in D:
            Available.append(str(i))

    def calc(L):
        global res
        l = int("".join(L))
        if l >= n:
            res = min(res, l)

        return res

    def dfs(Price):
        if len(Price) == len(str(n)):
            return calc(Price)

        for value in Available:
            Price.append(value)
            dfs(Price)
            Price.pop()

    dfs([])
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

n, k = map(int, input().split(" "))
d = list(map(int, input().split(" ")))

def f(curr):
    if curr >= n:
        print(curr)
        sys.exit(0)


    for i in filter(lambda x: x not in d, range(10)):
        if not (curr == 0 and i == 0):
            f(curr * 10 + i)

f(0)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = set(map(int, input().split()))
f = True
while f:
    if set(str(N)) == set(str(N)) - D:
        print(N)
        f = False
    else:
        N += 1

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = set(map(int, input().split()))
while True:
    if set(str(N)) == set(str(N)) - D:
        print(N)
        break
    else:
        N += 1

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10-k):
        if n%10+j+k in l:
            ans += n%10+j+k
            if k == 0:
                ans=int(ans)
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
z=set([0])
l2=l-z
if k==1:
    ans+=min(l2)
    ans = int(ans)
for i in range(le):
    ans *=10
    if ans%10 ==0:
        ans+=min(l)
print(int(ans))

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10-k):
        if n%10+j+k in l:
            ans += n%10+j+k
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
z=set([0])
l=l-z
if k==1:
    ans+=min(l)
print(int(ans*(10**le)))

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10-k):
        if n%10+j+k in l:
            ans += n%10+j+k
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
z=set([0])
l=l-z
ans+=min(l)
print(int(ans*(10**le)))

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10-k):
        if n%10+j+k in l:
            ans += n%10+j+k
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
if k==1 and min(l)!=0:
    ans+=min(l)
elif k==1 and min(l)==0:
    ans+=1
print(int(ans*(10**le)))

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10-k):
        if n%10+j+k in l:
            ans += n%10+j+k
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
ans+=k
print(int(ans*(10**le)))

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10):
        if n%10+j+k in l:
            ans += n%10+j+k
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
ans+=k
print(int(ans*(10**le)))

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10):
        if n%10+j+k in l:
            ans += n%10+j+k
            c=1
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
ans+=k
print(int(ans*(10**le)))

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10):
        if n%10+j+k in l:
            ans += n%10+j+k
            c=1
            break
    if c ==0:
        ans +=min(l)
        k=1
    n//=10
    ans/=10
ans+=k
print(int(ans*(10**le)))

Submission status: Wrong Answer

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))+1

    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: Wrong Answer

Solution code:
import sys

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

number = N-1
while True:
    number += 1
    ng = False
    for i in range(K):
        if Ds[i] in str(number):
            ng = True
            break

    if ng == False:
        print(number)
        sys.exit(0)

Submission status: Wrong Answer

Solution code:
n, _ = map(int, input().split())
d = set(sorted(map(int, input().split())))

for q in range(10000):
    if not set(sorted({int(str(q)[i]) for i in range(len(str(q)))})) & d:
        if q >= n:
            print(q)
            exit(0)

Submission status: Wrong Answer

Solution code:
import sys

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

number = N-1
while True:
    number += 1
    for j in range(K):
        if Ds[j] in str(number):
            break
        if j == K-1:
            print(number)
            sys.exit(0)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N, 1000000):
    for j in range(K):
        if Ds[j] in str(i):
            break
        if j == K-1:
            print(i)
            sys.exit(0)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N,100001):
    for j in range(K):
        if Ds[j] in str(i):
            break
        if j == K-1:
            print(i)
            sys.exit(0)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
d_set = {x for x in input().split()}

for i in range(n,10001):
    i_set = set(list(str(i)))
    if(len(d_set & i_set) == 0):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    new = ""
    ok = False
    for s in str(N):
        if ok:
            s = "0"
        while int(s) in D:
            s = str(int(s) + 1)
            ok = True
        new += s
    print(new)
    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
d = list(input().split())
flag = True
while flag:
    n_str = str(n)
    for i in d:
        if i in n_str:
            break
        else:
            flag = False
            break
    n += 1

print(n-1)

Submission status: Wrong Answer

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

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)

out = sorted(list(out))
res_list = []
flag = 0
for i in range(len(N)-1, -1, -1):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
  elif flag == 1:
    flag = 0
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
if flag == 1:
  res_list.append(out[0])
  
res = ''
for i in range(len(res_list)-1, -1, -1):
  res += res_list[i]
print(res)

Submission status: Wrong Answer

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

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)

out = sorted(list(out))
res_list = []
flag = 0
for i in range(len(N)-1, -1, -1):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
  elif flag == 1:
    flag = 0
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
if flag == 1:
  res_list.append('1')
  
res = ''
for i in range(len(res_list)-1, -1, -1):
  res += res_list[i]
print(res)

Submission status: Wrong Answer

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

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)

out = sorted(list(out))
res_list = []
flag = 0
for i in range(len(N)-1, -1, -1):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
  elif flag == 1:
    flag = 0
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)

res = ''
for i in range(len(res_list)-1, -1, -1):
  res += res_list[i]
print(res)

Submission status: Wrong Answer

Solution code:
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, K = read_ints()
    digits = list(range(10))
    ds = read_ints()
    for d in ds:
        digits.remove(d)
    prefixes = []
    already = False
    for i, c in enumerate(str(N)):
        chosen = -1
        for j in range(len(digits)):
            if digits[j] >= int(c):
                chosen = j
                break
        already = already or digits[j] > int(c)
        if chosen == -1:
            if not already:
                parity = 1
                for j in range(len(prefixes)-1, -1, -1):
                    prefixes[j], parity = (prefixes[j]+parity)%len(digits), (prefixes[j]+parity)//len(digits)
                    if parity == 0:
                        break
                if parity == 1:
                    min_digit = 0 if digits[0] != 0 else 1
                    prefixes.insert(0, min_digit)
            prefixes += [0]*(len(str(N))-i)
            return ''.join(str(digits[p]) for p in prefixes)
        prefixes.append(chosen)
    return ''.join(str(digits[p]) for p in prefixes)


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

Submission status: Wrong Answer

Solution code:
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, K = read_ints()
    digits = list(range(10))
    ds = read_ints()
    for d in ds:
        digits.remove(d)
    prefixes = []
    for i, c in enumerate(str(N)):
        chosen = -1
        for j in range(len(digits)):
            if digits[j] >= int(c):
                chosen = j
                break
        if chosen == -1:
            parity = 1
            for j in range(len(prefixes)-1, -1, -1):
                prefixes[j], parity = (prefixes[j]+parity)%len(digits), (prefixes[j]+parity)//len(digits)
                if parity == 0:
                    break
            if parity == 1:
                min_digit = 0 if digits[0] != 0 else 1
                prefixes.insert(0, min_digit)
            prefixes += [0]*(len(str(N))-i)
            return ''.join(str(digits[p]) for p in prefixes)
        prefixes.append(chosen)
    return ''.join(str(digits[p]) for p in prefixes)


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

Submission status: Wrong Answer

Solution code:
def check(x,d):
    s=str(x)
    flag=True 
    for i in range(len(s)):
        if int(s[i]) not in d:
            flag=False 
    return flag
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
d=[]
for i in range(10):
    if i not in a:
        d.append(i)
l=len(str(n))
final=10**l 
flag=False
#print(d)
for i in range(n,final):
    #print("HI")
    if check(i,d):
        flag=True
        print(i)
        break 
if not flag:
    print(str(d[0])*(l+1))

Submission status: Wrong Answer

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

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)

len_N = len(N)
res = ''
flag = 0
tmp = sorted(list(out))
#print(tmp)
for i in range(len_N):
  if len(set(N[i])&out) != 0 and flag == 0:
    res+=N[i]
  elif len(set(N[i])&out) == 0 and flag == 0:
    for j in range(len(tmp)):
      if int(N[i]) < int(tmp[j]):
        res += tmp[j]
        flag = 1
        break
  elif flag == 1:
    res += tmp[0]
if res == '':
  if int(tmp[0]) != 0:
    for i in range(len_N+1):
      res += tmp[0]
  else:
    res += tmp[1]
    for i in range(len_N):
      res += tmp[0]
print(res)

Submission status: Wrong Answer

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

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)

len_N = len(N)
res = ''
flag = 0
tmp = sorted(list(out))
#print(tmp)
for i in range(len_N):
  if len(set(N[i])&out) != 0 and flag == 0:
    res+=N[i]
  elif len(set(N[i])&out) == 0 and flag == 0:
    for j in range(len(tmp)):
      if int(N[i]) < int(tmp[j]):
        res += tmp[j]
        flag = 1
        break
  elif flag == 1:
    res += tmp[0]
print(res)

Submission status: Wrong Answer

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

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)

len_N = len(N)
res = ''
flag = 0
tmp = list(out)
print(tmp)
for i in range(len_N):
  if len(set(N[i])&out) != 0 and flag == 0:
    res+=N[i]
  elif len(set(N[i])&out) == 0 and flag == 0:
    for j in range(len(tmp)):
      if int(N[i]) < int(tmp[j]):
        res += tmp[j]
        flag = 1
        break
  elif flag == 1:
    res += tmp[0]
print(res)

Submission status: Wrong Answer

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

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)

len_N = len(N)
res = ''
flag = 0
tmp = list(out)
for i in range(len_N):
  if len(set(N[i])&out) != 0 and flag == 0:
    res+=N[i]
  elif len(set(N[i])&out) == 0 and flag == 0:
    for j in range(len(tmp)):
      if int(N[i]) < int(tmp[j]):
        res += tmp[j]
        flag = 1
  elif flag == 1:
    res += tmp[0]
print(res)

Submission status: Wrong Answer

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

Da = set(range(10)) - set(D)

ans = [9, 9, 9, 9]
div = 1000

for d in range(4):
  b = int(N/div)
  ans[d] = b
  while ans[d] in D and not (d == 0 and ans[d] == 0):
    ans[d] += 1
  if not b == ans[d]:
    ans[d+1:] = [min(Da)]*(3-d)
    break
  N = N%div
  div /= 10

print(1000*ans[0]+100*ans[1]+10*ans[2]+ans[3])

Submission status: Wrong Answer

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

Da = set(range(10)) - set(D)

ans = [9, 9, 9, 9]
div = 1000

for d in range(4):
  if not ans[d] == 9:
    break
  b = int(N/div)
  ans[d] = b
  while ans[d] in D and not (d == 0 and ans[d] == 0):
    ans[d] += 1
  if not b == ans[d]:
  	ans[d+1:] = [min(Da)]*(3-d)
  N = N%div
  div /= 10

print(1000*ans[0]+100*ans[1]+10*ans[2]+ans[3])

Submission status: Wrong Answer

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

Da = set(range(10)) - set(D)

ans = [9, 9, 9, 9]
div = 1000

for d in range(4):
  if not ans[d] == 9:
    break
  b = int(N/div)
  ans[d] = b
  while ans[d] in D and not (d == 0 and ans[d] == 0):
    ans[d] += 1
  if not b == ans[d]:
  	ans[d+1:] = [min(Da)]*(3-d)
  print(ans)
  N = N%div
  div /= 10

print(1000*ans[0]+100*ans[1]+10*ans[2]+ans[3])

Submission status: Wrong Answer

Solution code:
def abc042_c():
  n, _ = map(int, input().split())
  D = list(map(int, input().split()))
  for i in range(n, 10000):
    like = True
    for s in str(i):
      if int(s) in D:
        like = False
        break
    if like:
      print(i)
      return

abc042_c()

Submission status: Wrong Answer

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(int(i))
    if l == 2:
        for ii in usable:
            for i in usable:
                num.append(int( ii + i))
    elif l == 3:
        for iii in usable:
            for ii in usable:
                for i in usable:
                    num.append(int( iii + ii + i))
    elif l == 4:
        for iv in usable:
            for iii in usable:
                for ii in usable:
                    for i in usable:
                        num.append(int( iv + iii + ii + 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: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
d = na()
s = str(n)

ans = []
res1 = 0
res2 = 0

while res1 < n:
    if res1 == 0:
        for i in range(1, 10):
            if i not in d:
                res1 *= 10
                res1 += i
                break
    else:
        for i in range(10):
            if i not in d:
                res1 *= 10
                res1 += i
                break

j = 0
while res2 < n:
    ok = False
    for i in range(int(s[j]), 10):
        if i not in d:
            res2 *= 10
            res2 += i
            ok = True
            break
    if not ok:
        res2 = inf
        break
    j += 1

print(min(res1, res2))

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
d = na()
s = str(n)

ans = []
for i in range(len(s)):
    ok = False
    for j in range(0, 10):
        if j >= int(s[i]) and j not in d:
            flag = False
            if i + 1 < len(s):
                for k in range(int(s[i + 1]), 10):
                    if k not in d:
                        flag = True
            else:
                flag = True
            
            if flag:
                ans.append(j)
                ok = True
                break
    if not ok:
        res = 0
        for j in range(1, 10):
            if j not in d:
                if 0 in d:
                    while res < n:
                        res *= 10
                        res += j
                else:
                    res += j
                    while res < n:
                        res *= 10
                ans = list(str(res))
                break

print(*ans, sep="")