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())
D=list(map(int,input().split()))
nums=[i for i in range(10) if i not in D]
ans=""
for i in str(n):
  if int(i) in nums:
    ans+=i
  else:
    tmp=100
    for j in nums:
      if int(i)<=j:
        tmp=min(tmp,j)
    ans+=str(tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
# O(Dlogn)解法?
N,K=map(int, raw_input().split(" "))   
D=map(int, raw_input().split(" "))   
keta=len(str(N))
strN=str(N)
ans1=""
for x in range(keta-1):
    p=int(strN[keta-x-1])
    d=0
    for dd in range(10):
        if dd not in D:
            d=dd
            break
    ans1=str(d)+ans1
candidate=int(strN[0])
def ok(n):
    s=str(n)
    for ss in s:
        if int(ss) in D: return False
    return True
while True:
    if ok(candidate): # and int(str(candidate)+ans1)>=N: # shit
        break
    candidate+=1

ans1=str(candidate)+ans1
if ok(N):
    print(N)
else:
    print(int(ans1))

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    n, k = map(int, input().split())
    d = [int(s) for s in input().split()]
    p = [i for i in range(10) if i not in d]

    print(solve(n, p))

def solve(n, p):
    def rec(n, r):
        if n == 0:
            s = ''.join(str(i) for i in reversed(r))
            return int(s)
        
        idx = bisect.bisect_left(p, n % 10)
        if idx < len(p):
            r.append(p[idx])
            return rec(n // 10, r)
        else:
            r = [p[0] for _ in r]
            r.append(p[0])
            return rec(n // 10 + 1, r)

    return rec(n, [])

main()

Submission status: Wrong Answer

Solution code:
price, num = input().split(" ")
dislike = input().split(" ")
for i in range(int(price), 10001):
    if set(dislike) & set(str(i)):
        continue
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
price, num = input().split(" ")
dislike = input().split(" ")
for i in range(int(price), 10001):
    if set(dislike) & set(str(i)):
        continue
    else:
        print(i)

Submission status: Wrong Answer

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

for i in range(n, 88888):
  if bool(set([int(x) for x in str(n)]) & d_set ) is False:
    print(n)
    break
  n += 1

Submission status: Wrong Answer

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

for i in range(n, 10000):
  if bool(set([int(x) for x in str(n)]) & d_set ) is False:
    print(n)
    break
  n += 1

Submission status: Wrong Answer

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

for i in range(n, 10000):
  n += 1
  if bool(set([int(x) for x in str(n)]) & d_set ) is False:
    print(n)
    break

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=set([str(s) for s in range(10)])
B=A-set(list(map(str,input().split())))
for s in range(n,10000):
    if set(list(str(s)))<=B:
        print(s)
        exit()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=set([str(s) for s in range(10)])
B=A-set(list(map(str,input().split())))
print(B)
for s in range(n,10000):
    print(set(list(str(s))))
    if set(list(str(s)))<=B:
        print(s)
        exit()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=set([s for s in range(10)])
B=A-set(list(map(int,input().split())))
B=set(list(map(str,list(B))))
for s in range(n,10000):
    if set(list(str(s)))<=B:
        print(s)
        exit()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=set([s for s in range(10)])
B=A-set(list(map(int,input().split())))
B=set(list(map(str,list(B))))
for s in range(n,10000):
    print(set(list(str(s))))
    if set(list(str(s)))<=B:
        print(s)
        exit()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=set([s for s in range(10)])
B=A-set(list(map(int,input().split())))
B=set(list(map(str,list(B))))
print(B)
for s in range(n,10000):
    print(set(list(str(s))))
    if set(list(str(s)))<=B:
        print(s)
        exit()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[]
B=list(map(int,input().split()))
for t in range(10):
     if t not in B:
         A.append(t)
A=set(list(map(str,A)))
for s in range(n,10001):
    if set(list(str(s)))<=A:
        print(s)
        exit()

Submission status: Wrong Answer

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

Solution code:
D, K = map(int, input().split())
S = set(map(str, input().split()))
res = ''
while True:
    s = str(D)
    l = len(s) - 1
    count = 0
    for i in range(l):
        if s[i] in S:
            break
        else:
            count += 1
    if count == l:
        res = D
        break
    else:
        D += 1
print(res)

Submission status: Wrong Answer

Solution code:
D, K = map(int, input().split())
S = list(map(int, input().split()))
l = [0] * 10 
for i in range(len(S)):
    l[S[i]] = 1
lowest = str([x for x in range(len(l)) if l[x] == 0 and x != 0][0])
res = ''
for x in str(D):
    if x == '1':
        res += lowest
    else:
        res += x
print(res)

Submission status: Wrong Answer

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:
        for m in ok_num:
          if len(str(N)) == 4:
            num = 10000*i + 1000*j + 100*k + 10*l + m
            cand_num.append(num)
          elif len(str(N)) == 3:
            num = 1000*j + 100*k + 10*l + m
            cand_num.append(num)
          elif len(str(N)) == 2:
            num = 100*k + 10*l + m
            cand_num.append(num)
          elif len(str(N)) == 1:
            num = 10*l + m
            cand_num.append(num)
            num_s = m
            cand_num.append(num_s)
            

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

print(min(ans_num))

Submission status: Wrong Answer

Solution code:
n,k = (int(i) for i in input().split())
d = list(int(i) for i in input().split())
 
def ketajudge(x):
  while x != 0:
    if x%10 in d:
      return False
      break
    else:
      if x//10 == 0:
       return True
       break
    x = x//10

Submission status: Wrong Answer

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

std = list(range(10))
use = list(set(std) - set(D))

for i in range(N, 10001):
    base = list(map(int, list(set(list(str(i))))))
    if list(set(base) - set(use)) == []:
        print(i)
        exit()

Submission status: Wrong Answer

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

std = list(range(10))
use = list(set(std) - set(D))

for i in range(N, 10001):
    base = list(map(int, list(set(list(str(i))))))
    if list(set(base) - set(use)):
        print(i)
        exit()

Submission status: Wrong Answer

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

std = list(range(10))
use = list(set(std) - set(D))

for i in range(N, 10001):
    base = list(map(int, list(set(list(str(i))))))
    if list(set(base)) == list(set(use)):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
std = list(range(10))
use = list(set(std) - set(D))
for i in range(N, 10001):
    base = list(map(int, list(set(list(str(i))))))
    if list(set(base) - set(use)) == []:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
base = list(range(10))
use = list(set(base) - set(D))
for a in use:
    for b in use:
        for c in use:
            for d in use:
                ans = a*1000 + b*100 + c*10 + d
                if ans >= N:
                    print(ans)
                    exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
base = list(range(10))
use = list(set(base) - set(D))
for i in range(len(str(N))):
    for a in use:
        for b in use:
            for c in use:
                for d in use:
                    ans = a*1000 + b*100 + c*10 + d
                    if ans >= N:
                        print(ans)
                        exit()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,10000):
  for j in list(str(i).replace(""," ").split()):
    if j in d:
      break
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,10000):
  for j in list(str(i).replace(""," ").split()):
    if int(j) in d:
      break  
  print(i)
  break

Submission status: Wrong Answer

Solution code:
#C - こだわり者いろはちゃん
def minGE(d):
    for x in range(d,10):
        if not (x in D):
#            print(x)
            return x
    return 10

def minAll(d):
    for x in range(10):
        if not (x in D): 
            return x

def main(n):
    d = [n%10**i//10**(i-1) for i in range(5,0,-1)]
    same = True
    newN = 0
    for k in range(5):
        if d[k]!=0: break

    for i in range(k,5):
        if same:
            if d[i] in D:
                same = False
                newN = newN*10 + minGE(d[i])
            else:
                newN = newN*10 + d[i]
        else:
            newN = newN*10 + minAll(d[i])
    return newN

N, K = [int(x) for x in input().split()]
D = [int(x) for x in input().split()]
#print(N,K,D)
print(main(N))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
d=list(map(int,(input().split())))
ans = 0
for i in range(N,10000):
    temp = str(i)
    n_len = len(temp)
    for j in range(n_len):
        if int(temp[j]) in d:
            break
        elif j == n_len-1:
            ans = 1
            break
    if ans == 1:
        print(temp)
        break

Submission status: Wrong Answer

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

R = N
k = 1
while k <= N:
    if R // k % 10 in D:
        R += k
    else:
        k *= 10

print(R)

Submission status: Wrong Answer

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)):
        for j5 in range(len(l)):
          L.append(l[j1]*10000+l[j2]*1000+l[j3]*100+l[j4]*10+l[j5])
for k in range(len(L)):
  if L[k]>=n:
    x=L[k]
    break
print(x)

Submission status: Wrong Answer

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])
L.append(10000)
for k in range(len(L)):
  if L[k]>=n:
    x=L[k]
    break
print(x)

Submission status: Wrong Answer

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

U=[i for i in range(10) if i not in D]

Keta=1
while True:
    if N>U[-1]*(sum(10**(i) for i in range(Keta))):
        Keta+=1
    else:
        break

N_copy=N

Result=[]
for k in range(Keta):

    for u in U:
        if u*(10**(Keta-k-1))+U[-1]*(sum(10**(i) for i in range(Keta-k-1)))>=N_copy:
            Result.append(u)
            N_copy-=u*(10**(Keta-k-1))
            break
    print u
    print N_copy
    print Keta
    if N_copy<=0:
        while len(Result)<Keta:
            Result.append(U[0])
        break

Ans=sum(Result[i]*(10**(Keta-i-1)) for i in range(len(Result)))
print Ans

Submission status: Wrong Answer

Solution code:
import sys
line = []
for i in sys.stdin.readlines():
    line.append(i.rstrip())
data = line.pop(0).split(" ")
num_list = line.pop().split(" ")

def pick_up(num_list):
    use_list = ['0','1','2','3','4','5','6','7','8','9']
    for i in num_list:
        use_list.remove(i)
    return use_list

def advance(n_list, num):
    n_list[len(n_list)-1] += 1
    while((num) in n_list):
        chk = n_list.index(num)
        if chk == 0:
            return [0 for i in range(len(n_list))]
        else:
            n_list[chk] = 0
            n_list[chk-1] += 1
    return n_list

def solve(num, num_list):
    use_list = pick_up(num_list)
    ans_list = [0 for i in range(len(num))]
    count = 0

    while(count < len(use_list)**len(ans_list)):
        ans_num = ""
        for i in ans_list:
            ans_num += use_list[i]
        if (int(ans_num) - int(num) >= 0):
            break
        ans_list = advance(ans_list, len(use_list))
        count += 1

    if count == len(use_list)**len(ans_list):
        if use_list[0] != "0":
            for i in range(len(num)+1):
                ans_num += use_list[0]
        else:
            ans_list += use_list[1]
            for i in range(len(num)):
                ans_num += use_list[0]
    
    return ans_num
    
def main():
    print(solve(data[0], num_list))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import sys
def main():
    n,k = map(int, input().split())
    ds =  list(map(int, input().split()))
    canuse = []
    for i in range(10):
        if not i in ds:
            canuse.append(str(i))
    digit = len(str(n))
    flt = list(filter(lambda x: x>=str(n)[0], canuse))
    if len(flt)==0:
        if '0' in canuse:
            print(canuse[1] + canuse[0]*digit)
        else:
            print(canuse[0]*(digit+1))
        sys.exit()
    ans = 10**5
    for a in itertools.product(canuse, repeat=digit):
        x = int("".join(a))
        if x>=n and x < ans:
            ans = x
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import sys
def main():
    n,k = map(int, input().split())
    ds =  map(int, input().split())
    canuse = []
    for i in range(10):
        if not i in ds:
            canuse.append(str(i))
    digit = len(str(n))
    flt = list(filter(lambda x: x>=str(n)[0], canuse))
    if len(flt)==0:
        if '0' in canuse:
            print(canuse[1] + canuse[0]*digit)
        else:
            print(canuse[0]*(digit+1))
    ans = 10**5
    for a in itertools.product(canuse, repeat=digit):
        x = int("".join(a))
        if x>=n and x < ans:
            ans = x
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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))
    ans = 10**6
    for a in itertools.product(canuse, repeat=digit):
        x = int("".join(a))
        if x>=n and x < ans:
            ans = x
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
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)
    digit = len(str(n))
    string = str(n)
    flt = list(filter(lambda x: x!=0 and x>=int(string[0]), canuse))
    if len(flt)==0:
        if 0 in canuse:
            print(str(canuse[1])+str(canuse[0])*digit)
            sys.exit()
        else:
            print(str(canuse[0])*(digit+1))
            sys.exit()
    i = 0
    ans = [s for s in string]
    flag = False
    while i< digit:
        flt = list(filter(lambda x: x>=int(string[i]), canuse))
        if len(flt)==0:
            flag = True
            break
        if int(string[i]) in flt:
            pass
        else:
            ans[i] = str(min(flt))
            for j in range(i+1, digit):
                ans[j] = str(canuse[0])
            print("".join(ans))
            sys.exit()
        i += 1
    i -= 1
    while i >= 0 and flag:
        flt = list(filter(lambda x: x>int(ans[i]), canuse))
        if len(flt)==0:
            pass
        else:
            ans[i] = str(min(flt))
            for j in range(i+1, digit):
                ans[j] = str(canuse[0])
            print("".join(ans))
            sys.exit()
        i -= 1

    print("".join(ans))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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] * (5 * 10000)
    
def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos >= level:
        if tmp >= N:
            # print("###", tmp)
            return tmp
        else: return 10 ** 9 + 7
    # 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: Wrong Answer

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] * (5 * 10000)
    
def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos >= level or tmp >= N:
        if tmp >= N: return tmp
        else: return 10 ** 9 + 7
    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: Wrong Answer

Solution code:
import itertools
N,K = input().split()
D = list(map(int,input().split()))
int_list = set(range(10))
like = list(int_list - set(D))
like.sort()
min_cost = 10**6
for e in itertools.product(like,repeat = len(N)):
    result = 0
    for i in range(len(N)):
        result += e[i] * pow(10,i)
    if int(N) <= result < min_cost:
        min_cost = result
if min_cost == 10**6:
    head = like[0] if like[0] > 0 else like[1]
    min_cost = head * pow(10,len(N))
    for i in range(len(N) - 1):
        min_cost += like[0] * pow(10,i)
print(min_cost)

Submission status: Wrong Answer

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

N = [int(x) for x in list(str(n))]
D_inv = sorted(list(set(range(10)) - set(D)))

m = len(N) + 1 # 置換が必要な桁
for i in range(len(N)):
    if N[i] in D:
        m = i
        break

if m == len(N) + 1:
    print(n)
    exit()

n = len(N) + 1 # 置換可能な桁 
for i in range(m + 1):
    if N[i] < D_inv[len(D_inv) - 1]:
        n = i

ans = 0
if n == len(N) + 1: # 置換可能な桁がない場合
    ans += D_inv[0] * (10 ** len(N))
    for i in range(len(N)):
        ans += D_inv[0] * (10 ** (len(N) - 1 - i))
else:
    for i in range(len(N)):
        if i < n:
            ans += N[i] * (10 ** (len(N) - 1 - i))
        if i == n: 
            for j in D_inv:
                if j > N[i]:
                    ans += j * (10 ** (len(N) - 1 - i))
                    break
        if i > n:
            ans += D_inv[0] * (10 ** (len(N) - 1 - i))
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu

n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ok = [1 for i in range(10)]
for i in range(len(d)):
    ok[d[i]] = -1
# nをしたの位から順に置き換えていく
money = [0]
for i in range(len(str(n))):
    money.append(int(str(n)[i]))
# 最小でなくともn以上の整数を作る
for i in reversed(range(1, len(money))):
    for j in range(money[i], 10+money[i]):
        _j = j % 10
        if ok[_j] == 1:
            if _j >= money[i]:
                money[i] = _j
                break
            else:
                money[i] = _j
# print("okList:{}".format(ok))
# print(money)
while True:
    if money[0] != 0:
        break
    else:
        del(money[0])
# print(money)
# 次に可能な限り最小化していく
for i in range(len(money)):
    for j in range(10):
        if ok[j] == 1:
            tmpMoney = copy.deepcopy(money)
            tmpMoney[i] = j
            # print("n:{} tmpMoney:{}".format(n, int(listToString(tmpMoney))))
            if int(listToString(tmpMoney)) >= n:
                # print("money:{}".format(money))
                money[i] = j
                break
print(int(listToString(money)))

Submission status: Wrong Answer

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

usable = set([str(i) for i in range(10)]) - set(D)

for i in range(N, 10000):
    if set(list(str(i))).issubset(usable):
        print(i)
        break

Submission status: Wrong Answer

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

    usable_list = list(set(range(0, 10)) - hate_set)

    ans = ""

    if all(list(map(lambda x: int(x) in usable_list, [price[i] for i in range(len(price))]))):
        return price

    while len(ans) >= len(price):
        if ans == price:
            return ans

        if ans == "" and min(usable_list) == 0:
            ans += str(usable_list[1:][0])
        else:
            ans += str(usable_list[0])

    if ans < price:
        if int(price[0]) <= usable_list[-1]:
            ans = str(usable_list[-1])

            for _ in range(len(price) - 1):
                ans += str(usable_list[0])

        else:
            ans = str(usable_list[0] if usable_list[0] is not 0 else usable_list[1])

            for _ in range(len(price)):
                ans += str(usable_list[0])

    return ans


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

Submission status: Wrong Answer

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

    usable_list = list(set(range(0, 10)) - hate_set)

    ans = ""

    if all(map(lambda x: int(x) in usable_list, [int(price[i]) for i in range(len(price))])):
        return price

    while len(ans) >= len(price):
        if ans == price:
            return ans

        if ans == "" and min(usable_list) == 0:
            ans += str(usable_list[1:][0])
        else:
            ans += str(usable_list[0])

    if ans < price:
        if int(price[0]) <= usable_list[-1]:
            ans = str(usable_list[-1])

            for _ in range(len(price) - 1):
                ans += str(usable_list[0])

        else:
            ans = str(usable_list[0] if usable_list[0] is not 0 else usable_list[1])

            for _ in range(len(price)):
                ans += str(usable_list[0])

    return ans

Submission status: Wrong Answer

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

    usable_list = list(set(range(0, 10)) - hate_set)

    ans = ""

    if all([lambda x: int(x) in usable_list, [int(price[i]) for i in range(len(price))]]):
        return price

    while len(ans) >= len(price):
        if ans == price:
            return ans

        if ans == "" and min(usable_list) == 0:
            ans += str(usable_list[1:][0])
        else:
            ans += str(usable_list[0])

    if ans < price:
        if int(price[0]) <= usable_list[-1]:
            ans = str(usable_list[-1])

            for _ in range(len(price) - 1):
                ans += str(usable_list[0])

        else:
            ans = str(usable_list[0] if usable_list[0] is not 0 else usable_list[1])

            for _ in range(len(price)):
                ans += str(usable_list[0])

    return ans


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

Submission status: Wrong Answer

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

    usable_list = list(set(range(0, 10)) - hate_set)

    ans = ""

    while len(ans) >= len(price):
        if ans == price:
            return ans

        if ans == "" and min(usable_list) == 0:
            ans += str(usable_list[1:][0])
        else:
            ans += str(usable_list[0])

    if ans < price:
        if int(price[0]) <= usable_list[-1]:
            ans = str(usable_list[-1])

            for _ in range(len(price) - 1):
                ans += str(usable_list[0])

        else:
            ans = str(usable_list[0] if usable_list[0] is not 0 else usable_list[1])

            for _ in range(len(price)):
                ans += str(usable_list[0])

    return ans


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

Submission status: Wrong Answer

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

    usable_list = list(set(range(0, 10)) - hate_set)

    if all(map(lambda x: int(x) in usable_list, set([price[i] for i in range(len(price))]))):
        return price

    elif price[0] in usable_list:
        ans = price[0]

    elif price[0] not in usable_list and min(usable_list) is not 0:
        ans = str(min(usable_list))

    else:
        ans = str(min(usable_list[1:]))

    for _ in range(len(price) - 1):
        ans += str(min(usable_list))

    if ans < price:
        ans += str(min(usable_list))

    return ans


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

Submission status: Wrong Answer

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

    usable_list = sorted(list(set(range(0, 10)) - hate_set))

    if price[0] in usable_list:
        ans = price[0]

    elif price[0] not in usable_list and min(usable_list) is not 0:
        ans = str(min(usable_list))

    else:
        ans = str(min(usable_list[1:]))

    for _ in range(len(price) - 1):
        ans += str(min(usable_list))

    if ans <= price:
        ans += str(min(usable_list))

    return ans


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

Submission status: Wrong Answer

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

    usable_list = sorted(list(set(range(0, 10)) - hate_set))

    if price[0] in usable_list:
        ans = price[0]

    elif price[0] not in usable_list and min(usable_list) is not 0:
        ans = str(min(usable_list))

    else:
        ans = str(min(usable_list[1:]))

    for _ in range(len(price) - 1):
        ans += str(min(usable_list))

    if ans < price:
        ans += str(min(usable_list))
    
    return ans


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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().strip().split())
D=list(map(int,input().strip().split()))
X=[1,2,3,4,5,6,7,8,9,0]
Y=list(set(D)^set(X))
YY=list(set(D)^set(X))
if 0 in YY:
    YY.remove(0)
Z=''
if max(Y)<int(str(N)[0]):
    Z+=str(min(YY))
    for i in range(len(str(N))):
        Z+=str(min(Y))
    print(Z)
    exit()
for i in Y:
    if i>=int(str(N)[0]):
        Z+=str(i)
        break
while not len(Z)==len(str(N)):
    Z+=str(min(Y))
print(Z)

Submission status: Wrong Answer

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

X=[1,2,3,4,5,6,7,8,9,0]
Y=list(set(D)^set(X))
YY=list(set(D)^set(X))
if 0 in YY:
    YY.remove(0)
Z=''
if max(Y)<int(str(N)[0]):
    Z+=str(min(YY))
    for i in range(len(str(N))):
        Z+=str(min(Y))
    print(Z)
    exit()

for i in range(len(str(N))):
    for x in range(len(Y)):
        
        if int(str(N)[i])<=Y[x]:
            Z+=str(Y[x]) 
            break

while not len(Z)==len(str(N)):
    Z+=str(min(Y))

print(Z)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().strip().split())
D=list(map(int,input().strip().split()))
X=[1,2,3,4,5,6,7,8,9,0]
Y=list(set(D)^set(X))
Z=''
for i in range(len(str(N))):
    for x in range(len(Y)):
        if int(str(N)[i])<=Y[x]:
            Z+=str(Y[x])
            break
print(Z)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
L = list(map(int,input().split()))
P = []
for i in range(10) :
    if i not in L :
        P.append(str(i))

A = list(str(N))
for i in range(len(A)) :
    if A[i] not in P :
        for j in range(len(P)) :
            if A[i] < P[j] :
                A[i] = P[j]
                break
print("".join(A))

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().strip().split(' ')))
D = list(map(int,input().strip().split(' ')))
flag = False
while flag == False:
    arrayN = [int(x) for x in list(str(N))]
    for i in arrayN:
        if i in D:
            N+=1
            break
        else:
            flag=True
    if flag:
        break
print(N)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [int(i) for i in input().split()]
N = []
while(n > 0):
    N.append(n % 10)
    n //= 10
N.reverse()
m = N.__len__()
d_c = [i for i in range(10)]
for i in d:
    d_c.remove(i)
for i in range(1,m):
    while(N[-i] in d):
        if N[-i] == 9:
            N[-i] = d_c[0]
            N[-i-1] = (N[-i-1] + 1) % 10 
        else:
            N[-i] += 1
if N[0] == 0:
    N.insert(0,1)
while(N[0] in d):
    if N[0] == 9:
        N[0] = d_c[0]
        N.insert(0,1)
    else:
        N[0] += 1
new_n = 0
for i in range(N.__len__()):
    new_n += N[-i-1] * (10**i)
print(new_n)