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

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

A = [i for i in L]

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

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

Submission status: Wrong Answer

Solution code:
#! python3
import sys

N, K = [int(x) for x in input().strip().split(' ')]
dislikes = set([int(x) for x in input().strip().split(' ')])

for i in range(10):
    if i not in dislikes:
        m_like = i
        break

N = str(N)
if int(N[0]) == 9 and 9 in dislikes:
    N = '10'+N[1:]
    if 1 not in dislikes and 0 not in dislikes:
        print('10'+str(m_like)*(len(N)-2))
        sys.exit(0)
r = ''
for i in range(len(N)):
    #print(N[i])
    c = int(N[i])
    if c in dislikes:
        while c < 10 and c in dislikes:
            c += 1
        r += str(c)
        break
    r += str(c)
r += str(m_like) * (len(N)-1-i)
print(r)

Submission status: Wrong Answer

Solution code:
#! python3

N, K = [int(x) for x in input().strip().split(' ')]
dislikes = set([int(x) for x in input().strip().split(' ')])

for i in range(10):
    if i not in dislikes:
        m_like = i
        break

N = str(N)
if int(N[0]) == 9 and 9 in dislikes:
    N = '10'+N[1:]
r = ''
for i in range(len(N)):
    #print(N[i])
    c = int(N[i])
    if c in dislikes:
        while c < 10 and c in dislikes:
            c += 1
        r += str(c)
        break
    r += str(c)
r += str(m_like) * (len(N)-1-i)
print(r)

Submission status: Wrong Answer

Solution code:

from itertools import product

N, K = [int(_) for _ in input().split()]
D = set([int(_) for _ in input().split()])
valid = list(set(range(10)) - D)

for r in range(1,6):
    for p in product(valid, repeat=r):
        n = int(''.join([str(i) for i in p]))
        if n >= N:
            print(n)
            exit()

Submission status: Wrong Answer

Solution code:

from itertools import product

N, K = [int(_) for _ in input().split()]
D = set([int(_) for _ in input().split()])
valid = list(set(range(10)) - D)

for p in product(valid, repeat=5):
    n = int(''.join([str(i) for i in p]))
    if n >= N:
        print(n)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
result = ['']
n = list(reversed(str(n)))
dislikes = list(map(int, input().split()))
for p in n:
  for x in range(10):
    if x not in dislikes and x>=int(p):
      #print("x is: ", x)
      result.append(str(x))
      break
  if result[-1] < p:
      result.append('0')
if result[-1] == '0':
    for x in range(1, 10):
        if x not in dislikes:
            result.append(str(x))
            break
print(''.join(reversed(result)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
result = []
n = list(str(n))
dislikes = map(int, input().split())
for p in n:
  for x in range(10):
    if x not in dislikes and x>=int(p):
      #print("x is: ", x)
      result.append(str(x))
      break
  if result[-1] < p:
      result[-2] = str(int(result[-1])+1)
      result.append('0')
print(''.join(result))

Submission status: Wrong Answer

Solution code:
#N<10000, K<10なので上位桁から探索していってもせいぜい10^5くらい
n, k = map(int, input().split())
n = str(n)
dislikes = map(int, input().split())
result = []
for p in n:
  for x in range(10):
    if x not in dislikes and x>=int(p):
      result.append(str(x))
      break
print(''.join(result))

Submission status: Wrong Answer

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

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

def run_code(N, K, ds):

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

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

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

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

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

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

        return to_num(n_digits)

    return search_nearest_larger(N)



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

Submission status: Wrong Answer

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

#N, K = (99999, 1)
#ds = [0]

def run_code(N, K, ds):

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

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

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

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

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

        for i in range(n):
            d_in = n_digits[i]
            inc, d_out = get_next_digit(d_in)
            if inc == 0 and d_in == d_out:
                continue

            if inc > 0:
                num += 10**(n-i)
                return search_nearest_larger(num)
            else:
                n_digits[i] = d_out
                return to_num(n_digits[:i+1] + [avail_min]*(n-i-1))

        return to_num(n_digits)

    return search_nearest_larger(N)



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

Submission status: Wrong Answer

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

def run_code(N, K, ds):

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

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

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

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

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

        for i in range(n):
            d_in = n_digits[i]
            inc, d_out = get_next_digit(d_in)
            if inc == 0 and d_in == d_out:
                continue

            if inc > 0:
                num += 10**(n-i)
                return search_nearest_larger(num)
            else:
                n_digits[i] = d_out
                return to_num(n_digits[:i+1] + [avail_min]*(n-i-1))


    res = search_nearest_larger(N)
    print(res)


run_code(N, K, ds)

Submission status: Wrong Answer

Solution code:
N, K = map(int, raw_input().split())
D = set("".join(raw_input().split()))
for i in xrange(N, 10000+1):
    if set(str(i)) & D == set():
        print i
        exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from itertools import combinations


def func(i, d, now, use, st):
    if i >= d:
        st.append(now)
        return

    for x in use:
        func(i + 1, d, now + str(x), use, st)


def solve():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))

    use = []
    for i in range(10):
        if i not in d:
            use.append(i)

    for i in range(len(str(n)), len(str(n)) + 1):
        st = []
        func(0, i, "", use, st)
        for x in sorted(st):
            if int(x) >= n:
                return x


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [int(i) for i in input().split()]
ablenum = [int(i) for i in range(10)]
lis_n = str(n)
lis_n = list(lis_n)

print(lis_n)

# 使用可能な数一覧
for i in d:
    ablenum.remove(i)

print(ablenum)

flag_bigdigit = -1

# max(ablenum)より大きい桁があるかどうか
for i in range(len(lis_n)):
    _i = len(lis_n) - i - 1
    if(int(lis_n[_i]) > max(ablenum)):
        flag_bigdigit = _i
        break

#  max(ablenum)より大きい桁があれば
if(flag_bigdigit != -1):
    flag_increaseDights = 1
    #  桁を増やす必要があるかどうか確認
    for i in range(flag_bigdigit-1, 0):
        # nの桁より大きい数字がablenumに存在していれば桁を増やす必要はない
        if(int(lis_n[i]) < max(ablenum)):
            flag_increaseDights = 0
            break
else:
    flag_increaseDights = 0

print("bigdigit:{0} increace:{1}".format(flag_bigdigit, flag_increaseDights))

ans = ""
# 桁を増やす必要があるならば
if(flag_increaseDights == 1):
    for i in range(len(lis_n)+1):
        # 一桁目は0以外の最も小さな数
        if(i == 0):
            mnum = min(ablenum)
            if(mnum == 0):
                mnum = ablenum[1]
            ans += str(mnum)
        # 2桁目以降は最も小さい数
        else:
            mnum = min(ablenum)
            ans += str(mnum)
# 桁を増やす必要がなければ、各桁の数字以上の最も小さい数を使う
else:
    flag_over = 0
    for i in range(len(lis_n)):
        if(flag_over == 0):
            mnum = min(ablenum)
            # その桁以上の数になるまで大きくする
            j = 0
            while mnum < int(lis_n[i]):
                #print("mnum:{0} j:{1}".format(mnum, j))
                j += 1
                mnum = ablenum[j]
            if(mnum > int(lis_n[i])):
                flag_over = 1
            ans += str(mnum)
        else:
            mnum = min(ablenum)
            ans += str(mnum)

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [int(i) for i in input().split()]
ablenum = [int(i) for i in range(10)]
lis_n = str(n)
lis_n = list(lis_n)

#print(lis_n)

# 使用可能な数一覧
for i in d:
    ablenum.remove(i)

#print(ablenum)

flag_bigdigit = -1

# max(ablenum)より大きい桁があるかどうか
for i in range(len(lis_n)):
    _i = len(lis_n) - i - 1
    if(int(lis_n[_i]) > max(ablenum)):
        flag_bigdigit = _i
        break

#  max(ablenum)より大きい桁があれば
if(flag_bigdigit != -1):
    flag_increaseDights = 1
    #  桁を増やす必要があるかどうか確認
    for i in range(flag_bigdigit-1, 0):
        # nの桁より大きい数字がablenumに存在していれば桁を増やす必要はない
        if(int(lis_n[i]) < max(ablenum)):
            flag_increaseDights = 0
            break
else:
    flag_increaseDights = 0

#print("bigdigit:{0} increace:{1}".format(flag_bigdigit, flag_increaseDights))

ans = ""
# 桁を増やす必要があるならば
if(flag_increaseDights == 1):
    for i in range(len(lis_n)+1):
        # 一桁目は0以外の最も小さな数
        if(i == 0):
            mnum = min(ablenum)
            if(mnum == 0):
                mnum = ablenum[1]
            ans += str(mnum)
        # 2桁目以降は最も小さい数
        else:
            mnum = min(ablenum)
            ans += str(mnum)
# 桁を増やす必要がなければ、各桁の数字以上の最も小さい数を使う
else:
    for i in range(len(lis_n)):
        mnum = min(ablenum)
        # その桁以上の数になるまで大きくする
        j = 0
        while mnum < int(lis_n[i]):
            #print("mnum:{0} j:{1}".format(mnum, j))
            j += 1
            mnum = ablenum[j]
        ans += str(mnum)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
D = map(int, sys.stdin.readline().split())
invD = []
for i in xrange(10):
    if i not in D:
        invD.append(i)
tempN = N
sepN = []
while tempN > 0:
    sepN.append(tempN % 10)
    tempN /= 10
sepN.reverse()
ret = 0
for i in xrange(len(sepN)):
    digit = 1
    for j in xrange(len(sepN) - 1 - i):
        digit *= 10

    for id in invD:
        if id >= sepN[i]:
            ret += id * digit
            break
    else:
        ret += invD[0] * digit
        continue
    if ret > N:
        while digit > 0:
            digit /= 10
            ret += invD[0] * digit
        break
print ret

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
D = map(int, sys.stdin.readline().split())
invD = []
for i in xrange(10):
    if i not in D:
        invD.append(i)
tempN = N
sepN = []
while tempN > 0:
    sepN.append(tempN % 10)
    tempN /= 10
sepN.reverse()
ret = 0
for i in xrange(len(sepN)):
    digit = 1
    for j in xrange(len(sepN) - 1 - i):
        digit *= 10

    for id in invD:
        if id >= sepN[i]:
            ret += id * digit
            break
    else:
        ret += invD[0] * digit
        continue
    while digit > 0:
        digit /= 10
        ret += invD[0] * digit
    break
print ret

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
D = map(int, sys.stdin.readline().split())
invD = []
for i in xrange(10):
    if i not in D:
        invD.append(i)
tempN = N
ret = 0
digit = 1
while tempN > 0:
    for id in invD:
        if id >= (tempN % 10):
            ret += id * digit
            break
    else:
        ret += invD[0] * digit
    tempN /= 10
    digit *= 10

if ret < N:
    ret += invD[0] * digit

print ret

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=[i for i in input().split()]
print(d)
while True:
    f=True
    for i in d:
        if i in str(n):
            f=False
            break
    if f:
        break
    n+=1
print(n)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
S = input().split()
A = ['0','1','2','3','4','5','6','7','8','9']
for c in S:
	A.remove(c)

ans = ''
flag = True

for i in range(len(N)):
	if N[i] in A:
		ans += N[i]
	else:
		for j in range(len(A)):
			if N[i] < A[j]:
				ans += A[j]
				flag = False
				break

if not flag:
	for k in range(len(N) - len(ans)):
		ans += min(A)

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = input().split()
A = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
for c in D:
	A.remove(c)
ans = ''

for i in range(len(N)):
	if N[i] in A:
		ans += N[i]
	else:
		for j in range(len(A)):
			if N[i] < A[j]:
				ans += A[j]
				break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(str, input().split())
D = list(map(int, input().split()))
ans = ""
kuriagari = 0
for i in reversed(range(len(str(N)))):
    n = int(N[i])
    if kuriagari + n > 9:
        n = 0
        kuriagari = 1
    if n in D:
        while(1):
            if n in D:
                if n + 1 > 9:
                    n = 0
                    kuriagari = 1
                else:
                    n += 1
                    kuriagari = 0
                continue
            else:
                break
    if i == 0:
        while(kuriagari in D):
            kuriagari += 1
        ans = str(kuriagari)+str(n)+ans
    else:
        ans = str(n) + ans
print(int(ans))

Submission status: Wrong Answer

Solution code:
N, K = map(str, input().split())
D = list(map(int, input().split()))
ans = ""
kuriagari = 0
for i in reversed(range(len(str(N)))):
    n = int(N[i])
    if kuriagari + n > 9:
        n = 0
        kuriagari = 1
    if n in D:
        while(1):
            if n in D:
                if n + 1 > 9:
                    n = 0
                    kuriagari = 1
                else:
                    n += 1
                    kuriagari = 0
                continue
            else:
                break
    if i == 0:
        ans = str(kuriagari)+str(n)+ans
    else:
        ans = str(n) + ans
print(int(ans))

Submission status: Wrong Answer

Solution code:
N, K = map(str, input().split())
D = list(map(int, input().split()))
ans = ""
kuriagari = 0
for i in reversed(range(len(str(N)))):
    n = int(N[i])
    if kuriagari + n > 9:
        n = 0
        kuriagari += 1
    if n in D:
        while(1):
            if n in D:
                if n + 1 > 9:
                    n = 0
                    kuriagari += 1
                else:
                    n += 1
                    kuriagari = 0
                continue
            else:
                break

    ans = str(n) + ans
    #ans += N[:i]+str(n)+N[i+1:]
print(int(ans))

Submission status: Wrong Answer

Solution code:
N, K = map(str, input().split())
D = list(map(int, input().split()))
ans = ""
for i in range(len(str(N))):
    n = int(N[i])
    if n in D:
        while(1):
            n += 1
            if n in D:
                continue
            else:
                break
    ans += str(n)
    #ans += N[:i]+str(n)+N[i+1:]
print(int(ans))

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
 
 
digits = list()
while(n):
	digits.append(n%10)
	n //= 10
digits.reverse()
 
 
ind = -2
for i in digits:
	if i not in liked:
		ind = digits.index(i)
		break
 
 
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js = []
 
 
m = 0
number = str()
flag = True
for i in jss:
	if m != ind+1:
		number += str(min(i))
		m += 1
		print(number)
	else:
		print(number)
		k = len(str(q)) - m
		val = int(number + str(min(liked))*k)
		if val <= 10000:
			print(val)
		else:
			print(10000)
		flag = False
		break
if flag:
	val1 = int(number)
	if val1 <= 10000:
		print(val1)
	else:
		print(10000)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
 
 
digits = list()
while(n):
	digits.append(n%10)
	n //= 10
digits.reverse()
 
 
ind = -2
for i in digits:
	if i not in liked:
		ind = digits.index(i)
		break
 
 
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js = []
 
 
m = 0
number = str()
flag = True
for i in jss:
	if m != ind+1:
		number += str(min(i))
		m += 1
	else:
		k = len(str(q)) - m
		val = int(number + str(min(liked))*k)
		if val <= q:
			print(val)
		else:
			print(q)
		flag = False
		break
if flag:
	val1 = int(number)
	if val1 <= q:
		print(val1)
	else:
		print(q)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
 
 
digits = list()
while(n):
	digits.append(n%10)
	n //= 10
digits.reverse()
 
 
ind = -2
for i in digits:
	if i not in liked:
		ind = digits.index(i)
		break
 
 
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js = []
 
 
m = 0
number = str()
flag = True
print(jss)
for i in jss:
	if m != ind+1:
		number += str(min(i))
		m += 1
	else:
		k = len(str(q)) - m
		print(number + str(min(liked))*k)
		flag = False
		break
if flag:
	print(number)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
not_liked = list(map(int, input().split()))
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
	digits.append(n%10)
	n = n // 10
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js.clear()
k=1
number = 0
for i in jss:
	number += min(i)*k
	k *= 10
print(number)

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
l = map(int, raw_input().split())

temp = n
a = []
while temp > 1:
    a.append(temp % 10)
    temp = int(temp / 10)

for i in range(len(a)):
    if a[i] in l:
        while a[i] in l:
            a[i] += 1
        if a[i] == 10:
            a[i] = 1
            a[i + 1] += 1
ans = 0
a.reverse()
for i in a:
    ans = ans * 10 + i
print ans

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
l = map(int, raw_input().split())

temp = n
a = []
while temp > 0:
    a.append(temp % 10)
    temp = int(temp / 10)

for i in range(len(a)):
    if a[i] in l:
        while a[i] in l:
            a[i] += 1
ans = 0
a.reverse()
for i in a:
    ans = ans * 10 + i
print ans

Submission status: Wrong Answer

Solution code:
N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
    candi.remove(d)

def decide(i):
    if i >= len(N):
        return ''
    for c in candi:
        if N[i] == c:
            return c + decide(i+1)
        elif N[i] < c:
            return c + candi[0] * (len(N) - i - 1)

if candi[-1] * len(N) > N:
    print decide(0)
else:
    print (candi[0] if candi[0] != '0' else candi[1]) + candi[0] * len(N)

Submission status: Wrong Answer

Solution code:
N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
    candi.remove(d)

def decide(i):
    if i >= len(N):
        return ''
    for c in candi:
        if N[i] == c:
            return c + decide(i+1)
        elif N[i] < c:
            return c + candi[0] * (len(N) - i - 1)
    else:
        return (candi[0] if candi[0] != '0' else candi[1]) + candi[0] * len(N)

print decide(0)

Submission status: Wrong Answer

Solution code:
N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
    candi.remove(d)

def decide(i):
    if i >= len(N):
        return ''
    for c in candi:
        if N[i] == c:
            return c + decide(i+1)
        elif N[i] < c:
            return c + candi[0] * (len(N) - i - 1)
    else:
        return (candi[0] if candi[0] != 0 else candi[1]) + candi[0] * len(N)

print decide(0)

Submission status: Wrong Answer

Solution code:
N,K = map(int,raw_input().split(" "))
A = map(int,raw_input().split(" "))
n = [int(c) for c in str(N)]
len_n = len(n)
digits = []
for i in range(10):
    if not(i in A):
        digits.append(i)


def need_big_keta():
    if n[0] <  digits[-1]:
        return False
    i=0
    while i < len_n and n[i] == digits[-1] :
        i+=1
    if i==len_n:
        return False
    if n[i] < digits[-1]:
        return False
    return True

if not need_big_keta():
    for i in range(N,int("9"*len_n)+1):
        j = i
        flag = True
        while j:
            if not j%10 in digits:
                flag = False
                break
            j/=10
        if flag:
            print i
            break
elif 0 in digits:
    print str(digits[1])+"0"*len_n
else:
    print digits[0]+(len_n+1)

Submission status: Wrong Answer

Solution code:
N,K = map(int,raw_input().split(" "))
A = map(int,raw_input().split(" "))
n = [int(c) for c in str(N)]
len_n = len(n)
digits = []
for i in range(10):
    if not(i in A):
        digits.append(i)


def need_big_keta():
    if n[0] <  digits[-1]:
        return False
    i=0
    while i < len_n and n[i] == digits[-1] :
        i+=1
    if i==len_n:
        return False
    if n[i] < digits[-1]:
        return False
    return True

if not need_big_keta():
    for i in range(N,int("9"*len_n)+1):
        j = i
        flag = True
        while j:
            if not j%10 in digits:
                flag = False
                break
            j/=10
        if flag:
            print i
            break
elif 0 in digits:
    print str(digits[1])+"0"*len_n
else:
    print digits[0]+(len_n+1)

Submission status: Wrong Answer

Solution code:
class IrohasObsession:
	def getMinimumValue(self,n,k,d):
		nums=list(set(d)^set([0,1,2,3,4,5,6,7,8,9]))
		if not n: print min(nums); return
		for i in range(9999):
			digits=[int(str(n)[i]) for i in range(len(str(n)))]
			flag=1
			for j in range(len(digits)):
				if not digits[j] in nums: flag=0
			if flag: print n; return
			n+=1
		print -1

if __name__ == "__main__":
	n,k=[int(i) for i in raw_input().split()]
	d=[int(i) for i in raw_input().split()]
	i=IrohasObsession()
	i.getMinimumValue(n,k,d)

Submission status: Wrong Answer

Solution code:
class IrohasObsession:
	def getMinimumValue(self,n,k,d):
		nums=list(set(d)^set([0,1,2,3,4,5,6,7,8,9]))
		for i in range(9999):
			digits=[int(str(n)[i]) for i in range(len(str(n)))]
			flag=1
			for j in range(len(digits)):
				if not digits[j] in nums: flag=0
			if flag: print n; return
			n+=1
		print -1

if __name__ == "__main__":
	n,k=[int(i) for i in raw_input().split()]
	d=[int(i) for i in raw_input().split()]
	i=IrohasObsession()
	i.getMinimumValue(n,k,d)

Submission status: Wrong Answer

Solution code:
def solve():
    n, _ = input().split()
    m = [int(i) for i in n]
    d = set(map(int, input().split()))
    ans = [''] * len(m)
    just = True
    for i in range(len(m)):
        if just:
            if m[i] not in d:
                ans[i] = m[i]
            else:
                for j in range(m[i] + 1, 11):
                    if j not in d:
                        ans[i] = j
                        just = False
                        break
        else:
            for j in range(10):
                if j not in d:
                    ans[i] = j
                    break
    for i in range(len(ans) - 1, 0, -1):
        if ans[i] == 10:
            for j in range(10):
                if j not in d:
                    ans[i] = j
                    break
            for j in range(ans[i - 1] + 1, 10):
                if j not in d:
                    ans[i - 1] = j
                    break
    for i in range(len(ans)):
        ans[i] = str(ans[i])
    print(''.join(ans))


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    n, _ = input().split()
    m = [int(i) for i in n]
    d = set(map(int, input().split()))
    ans = [''] * len(m)
    just = True
    for i in range(len(m)):
        if just:
            if m[i] not in d:
                ans[i] = m[i]
            else:
                for j in range(m[i] + 1, 11):
                    if j not in d:
                        ans[i] = j
                        just = False
                        break
        else:
            for j in range(10):
                if j not in d:
                    ans[i] = j
                    break
    for i in range(len(ans) - 1, 0, -1):
        if ans[i] == 10:
            for j in range(10):
                if j not in d:
                    ans[i] = j
                    break
            ans[i - 1] += 1
    for i in range(len(ans)):
        ans[i] = str(ans[i])
    print(''.join(ans))


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    n, _ = input().split()
    m = [int(i) for i in n]
    d = set(map(int, input().split()))
    ans = [''] * len(m)
    just = True
    for i in range(len(m)):
        if just:
            if m[i] not in d:
                ans[i] = m[i]
            else:
                for j in range(m[i] + 1, 11):
                    if j not in d:
                        ans[i] = j
                        just = False
                        break
        else:
            for j in range(10):
                if j not in d:
                    ans[i] = j
                    break
    for i in range(len(ans) - 1, 0, -1):
        if ans[i] == 10:
            ans[i] = 0
            ans[i - 1] += 1
    for i in range(len(ans)):
        ans[i] = str(ans[i])
    print(''.join(ans))


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    n, k = input().split()
    m = [int(i) for i in n]
    k = int(k)
    d = set(map(int, input().split()))
    ans = [''] * len(m)
    just = True
    for i in range(len(m)):
        if just:
            if m[i] not in d:
                ans[i] = str(m[i])
            else:
                for j in (m[i] + 1, 10):
                    if j not in d:
                        ans[i] = str(j)
                        just = False
                        break
        else:
            for j in range(10):
                if j not in d:
                    ans[i] = str(j)
                    break
    print(''.join(ans))


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def check(num,D):
    numStr = str(num)
    for i in range(len(numStr)):
        if int(numStr[i]) in D:
            return False
    return True

n = int(N)
for i in range(n,10000):
    if check(i,D):
        print( i )
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, raw_input().split())
D = map(str, raw_input().split())
for i in range(N, 10000):
    S = list(str(i))
    for l in S:
        try:
            D.index(l)
            break
        except ValueError:
            continue
    else:
        print i
        break

Submission status: Wrong Answer

Solution code:
#coding: utf-8
#ABC042C

n,k=map(int,raw_input().split())
d=map(int,raw_input().split())

e=[]

for i in xrange(10):
 if i not in d:
  e.append(i)

l=[int(x) for x in list(str(n))]

i=0
while l[i] in e and i<len(l)-1:
 i+=1
while l[i] not in e:
 l[i]=l[i]+1
i+=1
while i<len(l):
 l[i]=0
 i+=1

res=int(reduce(lambda x,y:x+y,[str(x) for x in l]))
print res

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
not_use = set(map(int, input().split())) # 使用不可な数字


def check(num):
    str_num = set([int(s) for s in str(num)])
    tmp = (str_num & not_use)
    if(len(tmp) > 0):
        return False
    else:
        print(num)
        return True

if __name__ == '__main__':
    while N < 10000:
        flag = check(N)
        if(flag):
            break
        else:
            N += 1