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:
# -*- coding: utf-8 -*-
N,K = map(int, raw_input().split())
use = map(int,raw_input().split())
split_sum = []
use_num = []
sum = N
ans = str(sum)

def calc_ans():
    global ans
    # 一桁目の格納
    if 0 in use_num:
        ans+=str(use_num[1])
    else:
        ans+=str(use_num[0])

    for i in range(1,len(split_sum)):
        ans += str(use_num[0])
    
    if int(ans)<N:
        ans+=str(use_num[0])
    print ans

# 与えられた金額を桁ごとに分解する
while sum > 0:
    split_sum.append(sum%10)
    sum //= 10
split_sum.reverse()

# 使える数字の検索と格納
for i in range(0,10):
    if i in use:
        continue
    else:
        use_num.append(i)

# 与えられた金額と使える数字が丸かぶりしてないかの検索
flag = False
for i in split_sum:
    if i in use_num:
        flag = True
        continue
    else:
        flag = False
        break

if flag:
    print ans
else:
    ans = ""
    calc_ans()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import numpy as np

if __name__ == "__main__":
    
    raw = input()
    N, _ = raw.split(" ")
    
    raw = input()
    unlike_number = [int(f) for f in raw.split(" ")]
    
    like_number = np.delete(np.arange(10), unlike_number)
    
    payment = []
    for i in range(len(N)):
        for j in range(like_number.size):
            if int(N[i]) <= like_number[j]:
                payment.append(str(like_number[j]))
                break
    
    print("".join(payment))

Submission status: Wrong Answer

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

def hate_check(nums,price):
    for n in nums:
        if str(n) in str(price):
            return True
        else:
            return False


while (hate_check(n_number, n)):
    n += 1
print(n)

Submission status: Wrong Answer

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

def hate_check(nums,price):
    for n in nums:
        if str(n) in str(price):
            return True
        else:
            return False




while (hate_check(n_number, n)):
    n += 1
print(n)

Submission status: Wrong Answer

Solution code:
cost, hate = map(int, input().split())
hate_num = list(map(int, input().split()))

hate_str = list(str(hate_num))
pay = cost
flag = True
while flag:
    pay_str = list(str(pay))
    for i in reversed(range(len(pay_str))):
        if set([pay_str[i]]) - set(hate_str) != set([pay_str[i]]):
            pay += 10**(len(pay_str)-1-i)
            print(pay)
            flag = True
            break
        else:
            flag = False
print(pay)

Submission status: Wrong Answer

Solution code:
cost, hate = map(int, input().split())
hate_num = list(map(int, input().split()))

hate_str = list(str(hate_num))
pay = cost
flag = True
while flag:
    pay_str = list(str(pay))
    for i in range(len(pay_str)):
        if set([pay_str[i]]) - set(hate_str) != set([pay_str[i]]):
            pay += 10**(len(pay_str)-1-i)
            flag = True
            break
        else:
            flag = False
print(pay)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
D_ALL = [0,1,2,3,4,5,6,7,8,9]

# 使える値
like = sorted(list(set(D_ALL) - set(D)))
small = like[0]

is_inc = False
out = ""
for i, s in enumerate(str(N)):
    num = int(s)

    for i2, like_num in enumerate(like):

        if is_inc:
            out += str(small)
            break

        if like_num >= num:
            out += str(like_num)
            if like_num > num:
                is_inc = True
            break

        if i2 == len(like) - 1 and i == 0:
            out = str(like[1]) if small == 0 else str(small)
            out += str(small)
            is_inc = True

print(out)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
D_ALL = [0,1,2,3,4,5,6,7,8,9]

# 使える値
like = sorted(list(set(D_ALL) - set(D)))
small = like[0]

is_inc = False
out = ""
for i, s in enumerate(str(N)):
    num = int(s)
    
    for i2, like_num in enumerate(like):

        if is_inc:
            out += str(small)
            break

        if like_num >= num:
            out += str(like_num)
            if like_num > num:
                is_inc = True
            break
        
        if i2 == len(like) - 1 and i == 0:
            out += str(small)
            is_inc = True

print(out)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
D_ALL = [0,1,2,3,4,5,6,7,8,9]

# 使える値
like = sorted(list(set(D_ALL) - set(D)))
small = like[0]

is_inc = False
out = ""
for s in str(N):
    num = int(s)

    for like_num in like:

        if is_inc:
            out += str(small)
            break

        if like_num >= num:
            out += str(like_num)
            if like_num > num:
                is_inc = True
            break

print(out)

Submission status: Wrong Answer

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
hate.sort()
like.sort()
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #5桁の場合
	for man in like:
		for sen in like:
			for hyaku in like:
				for ju in like:
					for ichi in like:
						if man*10000+sen*1000+hyaku*100+ju*10+ichi>=n:
							kane=man*10000+sen*1000+hyaku*100+ju*10+ichi
							pointer=1
							break
					if pointer==1:
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break				

if pointer==1:
	print(kane)
else:
	print("Error!!")

Submission status: Wrong Answer

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
hate.sort()
like.sort()
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #5桁の場合
	for man in like:
		for sen in like:
			for hyaku in like:
				for ju in like:
					for ichi in like:
						if sen*1000+hyaku*100+ju*10+ichi>=n:
							kane=sen*1000+hyaku*100+ju*10+ichi
							pointer=1
							break
					if pointer==1:
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break				

if pointer==1:
	print(kane)
else:
	print("Error!!")

Submission status: Wrong Answer

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
hate.sort()
like.sort()
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==1:
	print(kane)

Submission status: Wrong Answer

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
hate.sort()
like.sort()
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==1:
	print(kane)
else:
	print("Error!!")

Submission status: Wrong Answer

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==1:
	print(kane)
else:
	print("Error!!")

Submission status: Wrong Answer

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==1:
	print(kane)
else:
	print("Error!!")

Submission status: Wrong Answer

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break

if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break

if pointer==1:
	print(kane)
else:
	print("Error!!")

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
l = list(input().split())
#print(l)
l1 = [i for i in range(10) if i not in l]
#print(l1)
l2 = [False]*len(str(n))
for i in range(n,10000000):
  for j in range(len(str(n))):
    if str(i)[j] not in l:
      l2[j] = True
      a = i
    else:
      break
  if all(l2):
    print(a)
    break
  else:
    continue

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
l = list(input().split())
l1 = [i for i in range(10) if i not in l]
l2 = [False]*len(str(n))
for i in range(n,1000001):
  for j in range(len(str(n))):
    if str(i)[j] not in l:
      l2[j] = True
      a = i
    else:
      break
  if all(l2):
    print(a)
    break
  else:
    continue

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
l = list(input().split())
#print(l)
l1 = [i for i in range(10) if i not in l]
#print(l1)
l2 = [False]*len(str(n))
for i in range(n,100001):
  for j in range(len(str(n))):
    if str(i)[j] not in l:
      l2[j] = True
      a = i
    else:
      break
  if all(l2):
    print(a)
    break
  else:
    continue

Submission status: Wrong Answer

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

for i in range(N, 10000):
    i_list=list(map(int, str(i)))
    i_set=set(i_list)
    if i_set&D ==set():
        break
        
    else:pass

print(i)

Submission status: Wrong Answer

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

for i in range(N, 10000):
    i_list=list(map(int, str(i)))
    i_set=set(i_list)
    if i_set&D ==set():
        print(i)
        break
        
    else:pass

Submission status: Wrong Answer

Solution code:

def main():
    price, dilike_num = map(int, input().split())
    # dislike_data = list(map(int, input().split()))
    dislike_data = input().split()
    dislike_set = set(dislike_data)

    now_price = 0
    while 1:
        now_price += price
        now_price_set = set(list(str(now_price)))
        if len(now_price_set & dislike_set) == 0:
            break

    print(now_price)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

label = [i for i in range(10)]

for i in D:
    label.remove(i)

d4 = 10000
d3 = 1000
d2 = 100
d1 = 10
d0 = 1
flag = True
i = 0

for p in label:
    for q in label:
        for r in label:
            for s in label:
                x = d3*p + d2*q + d1*r + d0*s
                if x>=N:
                    print(x)
                    exit(0)
                elif p==q==r==s==label[len(label)-1]:
                    flag = False

if flag == False:
    for p in label:
        for q in label:
            for r in label:
                for s in label:
                    x = d4*label[i] + d3*p + d2*q + d1*r + d0*s
                    if x>=N:
                        print(x)
                        exit(0)
                    elif p==q==r==s==label[len(label)-1]:
                        i += 1

Submission status: Wrong Answer

Solution code:

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

label = [i for i in range(10)]

for i in D:
    label.remove(i)

d3 = 1000
d2 = 100
d1 = 10
d0 = 1

for p in label:
    for q in label:
        for r in label:
            for s in label:
                x = d3*p + d2*q + d1*r + d0*s
                if x>=N:
                    print(x)
                    exit(0)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input=sys.stdin.readline
    N,K=map(int,input().split())
    D=list(map(int,input().split()))
    L=[]
    for i in range(10):
        if i not in D:
            L.append(i)
    for p in L:
        if len(str(N))==1:
            if p>=N:
                print(p)
                return
        else:
            for q in L:
                if len(str(N))==2:
                    pay=p*10+q
                    if pay>=N:
                        print(pay)
                        return
                else:
                    for r in L:
                        if len(str(N))==3:
                            pay=p*100+q*10+r
                            if pay>=N:
                                print(pay)
                                return
                        else:
                            for s in L:
                                pay=p*1000+q*100+r*10+s
                                if pay>=N:
                                    print(pay)
                                    return
    if L[0]==0:
        print(L[1]*10**len(str(N)))
    else:
        print("".join([str(L[0]) for _ in range(len(str(N)))]))
    return
            

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

C = []
for k in range(10):
    if not k in D:
        C.append(k)

def num(a):
    if len(a) == n:
        if int(a) >= N:
            return a
        return 114514
    d=1145141919
    for c in C:
        d =min(d, int(num(a + str(c))))
    return d

print(num(''))

Submission status: Wrong Answer

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

C = []
for k in range(10):
    if not k in D:
        C.append(k)

def num(a):
    if len(a) == n:
        if int(a) >= N:
            return a
        return False
    for c in C:
        d = num(a + str(c))
        if not d is False:
            break
    return d

print(num(''))

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input=sys.stdin.readline
    N,K=map(int,input().split())
    D=list(map(int,input().split()))
    L=[]
    for i in range(10):
        if i not in D:
            L.append(i)
    for p in L:
        for q in L:
            for r in L:
                for s in L:
                    pay=p*1000+q*100+r*10+s
                    if pay>=N:
                        print(pay)
                        return
    if L[0]==0:
        print(L[1]*10000)
    else:
        print(L[0]*11111)
    return
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = input().split()
arr = list(input().split())
s = ""
for dig in n:
    if dig in arr:
        n = (int(dig) + 1) % 10
        while str(n) in arr:
            n = (n + 1) % 10
        s += str(n)
    else:
        s += dig
print(int(s))

Submission status: Wrong Answer

Solution code:
n, k = input().split()
arr = list(input().split())
s = ""
for dig in n:
    if dig in arr:
        n = (int(dig) + 1) % 10
        while n in arr:
            n = (n + 10) % 10
        s += str(n)
    else:
        s += dig
print(s)

Submission status: Wrong Answer

Solution code:
n, k = input().split()
arr = list(input().split())
s = ""
for dig in n:
  print(dig)
  if dig in arr:
    n = (int(dig) + 1) % 10
    while n in arr:
      n = (n + 10) % 10
    s += str(n)
  else:
    s += dig
print(s)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
x=[]
for i in range(10):
    if(i not in l):
        x.append(i)
x.sort()

        


aux=[]
tmp=n
while(tmp>0):
    aux.append(tmp%10)
    tmp=tmp//10
aux1=[0 for i in range(len(aux))]
for i in range(1,len(aux)+1):
    aux1[len(aux)-i]=aux[i-1]
# print(aux1)
aux3=[-1 for i in range(len(aux))]
for i in range(len(aux)):
    if(aux1[i] in l):
        lol=0
        for j in range(len(x)):
            if(x[j]>aux1[i]):
                lol=x[j]
                aux3[i]=lol
                break
        
    else:
        aux3[i]=aux1[i]
# print(aux3)
flg=0
if(aux3[0]==-1):
    flg=1
    if(x[0]!=0):
        aux3[0]=x[0]
    else:
        aux3[0]=x[1]

for i in range(1,len(aux3)):
    if(aux3[i]==-1):
        flg=1
        aux3[i]=x[0]
if(flg==1):
    aux3.append(x[0])

# print(aux3)
final=0
# print(len(aux3))
for i in range(len(aux3)):
    final+=aux3[i]*(10**(len(aux3)-i-1))
print(final)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 26 04:39:44 2019

@author: matsui
"""

N,K=map(int,input().split())
D=input().split()
D=[int(D[i]) for i in range(K)]
    
        
for n in range(N,10000):
    a=n//1000
    b=n%1000//100
    c=n%100//10
    d=n%10
    
    if a+b+c ==0:
        if d not in D :
            print(n)
            break
    elif a+b ==0:
        if c not in D and d not in D :
            print(n)
            break
    elif a ==0:
        if b not in D and c not in D and d not in D :
            print(n)
            break
    else:
        if a not in D and b not in D and c not in D and d not in D :
            print(n)
            break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 26 04:39:44 2019

@author: matsui
"""

N,K=map(int,input().split())
D=input().split()
D=[int(D[i]) for i in range(K)]
    
        
for n in range(N,10000):
    a=n//1000
    b=n%1000//100
    c=n%100//10
    d=n%10
    if a not in D and b not in D and c not in D and d not in D :
        print(n)
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
sets = set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
set_D = set(map(int, input().split()))
set_diff = sets - set_D
n = str(N)


ans = ""
for c in n:
    c = int(c)
    while c in set_D:
        c += 1
    ans += str(c)
    l = len(ans)
    if int(ans) > int(n[:l]):
        ans += str(min(set_diff)) * (len(n) - l)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
sets = set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
set_D = set(map(int, input().split()))
set_diff = sets - set_D
print(set_diff)
n = str(N)


ans = ""
for c in n:
    c = int(c)
    while c in set_D:
        c += 1
    ans += str(c)
    l = len(ans)
    if int(ans) > int(n[:l]):
        ans += str(min(set_diff)) * (len(n) - l)
        break
print(ans)

Submission status: Wrong Answer

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


ans = ""
for c in n:
    c = int(c)
    while c in lst_D:
        c += 1
    ans += str(c)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*- 
price, K = map(int, input().split())
 
kirai_data =input().split()
#print(set(data))
 
lst = list(range(price,10001))
for min in lst:
   
    shugo = set(kirai_data) & set(list(str(min))) 
    if  len(shugo) == 0 :                         
        print(min)
        break
    else:
        continue

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*- 
price, K = map(int, input().split())
 
kirai_data =input().split()
#print(set(data))
 
lst = list(range(price,10001))
for min in lst:
   
    shugo = set(kirai_data) & set(list(str(min))) 
    if  len(shugo) > 0 :                         
        continue
    else:
      #print(price)
      print(min)
      break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*- 
price, K = map(int, input().split())
 
kirai_data =input().split()
#print(set(data))
 
lst = list(range(price,10001))
for min in lst:
   
    shugo = set(kirai_data) & set(list(str(min))) 
    if  len(shugo) != 0 :                         
        continue
    else:
      #print(price)
      print(min)
      break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*- 
price, K = map(int, input().split())
 
kirai_data =list(input().split())
#print(set(data))
 
lst = list(range(price,10001))
for min in lst:
   
    shugo = set(kirai_data) & set(list(str(min))) 
    if  len(shugo) != 0 :                         
        continue
    else:
      #print(price)
      print(min)
      break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*- 
price, K = map(int, input().split())

data =list(input().split())
#print(set(data))

lst = list(range(price,10001))
for kari in lst:
   
    shugo = set(data) & set(list(str(kari))) 
    if  len(shugo) != 0 :                         
        continue
    else:
      #print(price)
      print(kari)
      break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
L = input()
def func1(N):
  if len(str(N)) == 4:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L or str(N)[3] in L:
      return False
  elif len(str(N)) == 3:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L:
      return False
  elif len(str(N)) == 2:
    if str(N)[0] in L or str(N)[1] in L:
      return False
  elif len(str(N)) == 1:
    if str(N)[0] in L:
      return False
  else:
    return True
while func1(N) == False:
  N += 1
print(N)

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]

    if A[0] == 0:
        if N == 0:
            ANS.append(0)
        else:
            ANS = [A[1]*11111]
    else:
        ANS = [A[0]*11111]
    for i in range(1,5):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]

    if A[0] == 0:
        ANS = [A[1]*11111]
    else:
        ANS = [A[0]*11111]
    for i in range(1,5):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    l = len(NN)
    ANS = []
    now = 0
    MIN = [0, A[0], A[0]*11, A[0]*111, A[0]*1111]
    check = 0
    for i in range(l):
        for a in A:
            if a > NN[0]:
                ANS.append(now*10**(l-i)+a*10**(l-1-i) + MIN[l-1-i])
                now = now*10+a
                break
            elif a == NN[0]:
                now = now*10+NN[0]
                check += 1
    if check == l:
        ANS.append(now)
    if not ANS:
        ANS.append( A[0]*( int( "1"*(l+1))))
    print( min(ANS))
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
L = input()
a = 0
b = 0
c = 0
while str((N//1000)%10) in L:
  N += 1000
  a += 1
if a > 0:
  while str((N//100)%10) in L:
    N -= 100
  while str((N//10)%10) in L:
    N -= 10
  while str(N%10) in L:
    N -= 1
else:
  while str((N//100)%10) in L:
    N += 100
    b += 1
  if b > 0:
    while str((N//10)%10) in L:
      N -= 10
    while str(N%10) in L:
      N -= 1
  else:
    while str((N//10)%10) in L:
      c +=1
      N += 10
    if c > 0:
      while str(N%10) in L:
        N -= 1
    else:
      while str(N%10) in L:
        N += 1
print(N)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
L = input()
A = [i for i in range(10) if not (str(i) in L)]
while str(N%10) in L:
  N += 1
while str((N//10)%10) in L:
  N += 10
while str((N//100)%10) in L:
  N += 100
while str((N//1000)%10) in L:
  N += 1000
print(N)

Submission status: Wrong Answer

Solution code:
def search_more(ans, i, nums, oks):
    # i以下の数字をmin(oks)にする
    for k in range(i-1, -1, -1):
        ans.pop()
        for o in oks:
            if o > nums[k]:
                # 以上がみつかった
                ans.append(o)
                for l in range(k, len(nums)):
                    ans.append(min(oks))
                return ans
    
    # だめだったので桁増やす
    if 0 in oks:
        oks.remove(0)
        ans.append(min(oks))
        for k in range(0, len(nums)):
            ans.append(0)
    else:
        for k in range(0, len(nums) + 1):
            ans.append(min(oks))
    return ans

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

nums = list(map(int, list(str(n))))
# print("nums", nums, oks)
ans = []
for i in range(0, len(nums)):
    # 上から見る
    for j in oks:
        if j >= nums[i]:
            # 以上のやつを見つけた
            ans.append(j)
            # ピッタシかどうか確認
            if j > nums[i]:
                # print("全部ぴったしじゃなかった")
                for k in range(0, len(nums)-i-1):
                    ans.append(min(oks))
                ans = ''.join(map(str, ans))
                print(ans)
                exit(0)
    # もし以上のやつがみつからなかったら前に戻りつつ以上にできるところを探し，それ以下の数字を小さいやつにする
    ans = search_more(ans, i, nums, oks)
    ans = ''.join(map(str, ans))
    print(ans)
    exit(0)
    
# 全部ぴったし
# print("全部ぴったし")
ans = ''.join(map(str, ans))
print(ans)