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, L = map(int, input().split())
S = {int(x) for x in input().split()}
flag = False
while flag == False:
    if N%10 in S:
        N += 1
        continue
    if int((N%100-N%10)/10) in S and N >= 10:
        N += 10
        continue
    if int((N%1000-N%100)/100) in S and N >= 100:
        N += 100
        continue
    if int((N%10000-N%1000)/1000) in S and N >= 1000:
        N += 1000
        continue
    if int((N%100000-N%10000)/10000) in S and N >= 10000:
        N += 10000
        continue
    flag = True
print(N)

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
S = {int(x) for x in input().split()}
flag = False
while flag == False:
    if N%10 in S:
        N += 1
        continue
    if int((N%100-N%10)/10) in S:
        N += 10
        continue
    if int((N%1000-N%100)/100) in S:
        N += 100
        continue
    if int((N%10000-N%1000)/1000) in S:
        N += 1000
        continue
    if int((N%100000-N%10000)/10000) in S:
        N += 10000
        continue
    flag = True
print(N)

Submission status: Wrong Answer

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

n=str(N)
flag=0

for i in range(10000):
    S=N+i
    flag=0
    for j in range(len(str(S))):
        if int(str(S)[j]) not in d:
            flag+=1
            if flag==len(str(S)):
                print(S)
                break
    else:
        continue
    break

Submission status: Wrong Answer

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

n=str(N)
flag=0

# for i in range(10):
#     if i not in d:
#         print(i)

for i in range(10000):
    S=N+i
    flag=0
    for j in range(len(str(S))):
        if int(str(S)[j]) not in d:
            flag+=1
            if flag==len(str(S)):
                print(S)
                break
    else:
        continue
    break

Submission status: Wrong Answer

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

N,K=1000,8
d=[1,3,4,5,6,7,8,9]
n=str(N)
flag=0

# for i in range(10):
#     if i not in d:
#         print(i)

for i in range(10000):
    S=N+i
    flag=0
    for j in range(len(str(S))):
        if int(str(S)[j]) not in d:
            flag+=1
            if flag==len(str(S)):
                print(S)
                break
    else:
        continue
    break

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    num = [True]*10
    for d in D:
        num[d] = False
    
    n = str(N)
    ans = ""
    for i in range(len(n)):
        for k in range(10):
            if num[k] and k >= int(n[i]):
                ans += str(k)
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
nk = input().split()
n = int(nk[0])
k = int(nk[1])
d = input().split()
for i in range(n,10000):
    for j in range(k):
        for l in range(len(str(n))):
            if str(n)[l] == str(d)[j]:
                break
        else:
            continue
        break
    else:
        print(i)
        break
    n += 1

Submission status: Wrong Answer

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

N = str(N)
res = 0
for c in N:
    n_digit = int(c)
    for i in range(10-K):
        if i == 0 and n_digit <= digits[0]:
            res = res*10 + digits[0]
            break
        elif n_digit <= digits[i] and n_digit > digits[i-1]:
            res = res*10 + digits[i]
            break

print(res)

Submission status: Wrong Answer

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

N = str(N)
res = 0
for c in N:
    n_digit = int(c)
    if n_digit <= digits[0]:
        res = res*10 + digits[0]
        continue

    if len(digits):
        for i in range(1, 10-K):
            if n_digit <= digits[i] and n_digit > digits[i-1]:
                res = res*10 + digits[i]
                break

print(res)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
d = LIST()
num = []
for i in range(10):
    if i not in d:
        num.append(i)
ans = inf
for i in range(5):
    for x in product(num,repeat=i):
        tmp = 0
        for j in range(i):
            tmp += x[j]*10**j
        if tmp >= n:
            ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = input().split()
for i in range(n,10000):
    for j in range(k):
        for l in range(len(str(i))):
            if str(i)[l] == str(d)[j]:
                break
        else:
            continue
        break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = input().split()
for i in range(n,10000):
    for j in range(k):
        for l in range(len(str(n))):
            if str(n)[l] == str(d)[j]:
                break
        else:
            continue
        break
    else:
        print(i)
        break
    n += 1

Submission status: Wrong Answer

Solution code:
n,k=input().split()
d=list(map(int,input().split()))
num=list(range(10))
for i in range(len(d)):
    num.remove(d[i])
ln=list(n)
n=int(n)
if int(ln[0])>max(num):
    if num[0]==0:
        ans=num[1]*(10**len(ln))
    else:
        ans=str(num[0]*(len(ln)+1))
    print(ans)
else:
    ans=[0]*len(ln)
    num1=0
    num2=max(num)
    num3=0
    for i in range(len(ln)):
        if num2<int(ln[i]):
            num3=i+1
            break
        for j in range(len(num)):
            if num[j]>=int(ln[i]):
                if num[j]>int(ln[i]):
                    num1=1
                    num3=i+1
                ans[i]=num[j]
                break
        if num1==1:
            break
    if num1!=1:
        for i in range(num3):
            num4=num3-1-i
            if max(num)!=int(ln[num4]):
                for j in range(len(num)):
                    if num[j]>ans[num4]:
                        ans[num4]=num[j]
                        break
                num3=num3+2+i
                break
    for i in range(num3,len(ln)):
        ans[i]=min(num)
    ans1=""
    for i in range(len(ans)):
        ans1+=str(ans[i])
    print(ans1)

Submission status: Wrong Answer

Solution code:
N, K = 1000, 8
DRR = [1, 3, 4, 5, 6, 7, 8, 9]

N, K = 9999, 1
DRR = [0]

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

def calculate(n,k,arr):

    dictA = set()
    for i in range(10):
        dictA.add(i)
    dictD = set()
    for i in range(len(arr)):
        dictD.add(arr[i])
    dictL = dictA.difference(dictD)



    likes = sorted(list(dictL))

    originalArray = list(map(int,str(n)))
    for i in range(len(originalArray)):
        if dictD.__contains__(originalArray[i]):
            if (i == 0) and (likes[0] == 0):
                originalArray[0] = likes[1]
            else:
                originalArray[0] = likes[0]


    print("".join(list(map(str,originalArray))))



calculate(N, K, DRR)

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
l=set(map(int,input().split()))
s=n
p=set()
for i in range(10):
  if i not in l:
    p.add(i)
if k==1 and 0 in l:
  print(n)
else:
  d=math.floor(math.log(n, 10)+1) 
  for i in p:
    n=n+i*(10**d)
    d=d+1
  print(n)

Submission status: Wrong Answer

Solution code:
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r
    
def solve():
    n,k=mp()
    l=li()
    x=[1]*10
    for i in l:
        x[i]=0

    s=str(n)
    p=''
    for i in s:
        if x[int(i)]:
            p+=i
        else:
            a=int(i)+1
            while True:
                
                if x[a%10]:
                    p+=str(a%10)
    
                    break
                else:
                    a=(a+1)%10
    print(p)
            
        
        

for _ in range(1):
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

for n in range(N, 10000):
    s = str(n)
    ok = True
    for c in s:
        if c in D:
            ok = False
    if ok:
        print(n)
        break

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

for n in range(N, 10000 + 1):
    s = str(n)
    ok = True
    for c in s:
        if c in D:
            ok = False
    if ok:
        print(n)
        break

Submission status: Wrong Answer

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

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

n = str(N)

rs = 0

for i in range(1, len(n) + 1):
    nn = n[-i]
    nt = n[-i]
    while True:
        if not nt in D:
            break
        else:
            nnn = int(nt)
            nnn += 1
            nt = str(nnn)

    if not nn == nt:
        sa = int(nt) - int(nn)

        N += sa * 10 ** (i - 1)
        n = str(N)

print(N)

Submission status: Wrong Answer

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

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

n = str(N)

rs = 0

for i in range(1, len(n) + 1):
    nn = n[-i]
    while True:
        if not nn in D:
            break
        else:
            nnn = int(nn)
            nnn += 1
            nn = str(nnn)

    rs += int(nn) * 10 ** (i-1)

print(rs)

Submission status: Wrong Answer

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

def main():


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

    print(D)

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

    num = set()
        
    for i in numList:
        if i not in D:
            num.add(i)
    
    # print(num)

    for i in range(N, N * 10 + 1):
        setI = set(int(x) for x in list(str(i)))
        if len(num | setI) <= len(num):
            ans = i
            break
                
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

like_n = sorted(list(set(D) ^ set(diff)))
if [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] == like_n:
  print(n)
elif 0 not in like_n:
  print(min(like_n)*n)
else:
  print(min(like_n[1:])*n)