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: Runtime Error

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

for i in range(n, n*11):
  for d in Ds:
    if d in int(list(str(i))):
      break
  else:
    print(i)
    exit(0)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left as bl
N, K = map(list, input().split())
D = list(map(int, input().split()))
D = [i for i in range(10) if not i in D]
res = []
big = 0
if int("".join([str(D[-1])] * len(N))) < int("".join(N)):
  if D[0] == 0:
    res = [D[1]] + [0] * len(N)
  else:
    res = [D[1]] * (len(N) + 1)
else:
  for i in range(len(N)):
    if big == 0:
      res.append(D[bl(D, int(N[i]))])
    else: res.append(D[0])
    if res[i] > int(N[i]): big = 1
print("".join(list(map(str, res))))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60 ;
const ll MOD=1e9+7 ;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）

#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// ----- template end ---- //

// ------- library ------- //


// ----- library end ----- //



int main() {
  string N;
  ll K;
  cin >> N >> K;

  set<char> NOs;
  rep(i,K){
    char a;
    cin >> a;
    NOs.insert(a);
  }

  bool ansflag = false; //答えが見つかったら1
  int ans = 0;
  REP(i, stoi(N), 100000){
    ansflag = true; //一旦1にする
    for (char c : to_string(i)){
      if (NOs.find(c) != NOs.end()){ //もしcがNOsに入っていたら(ダメな数字を使っていたら)
        ansflag = false;
      }
    }
    if (ansflag){
      ans = i;
      break;
    }
  }

  cout << ans << endl;



}

Submission status: Runtime Error

Solution code:
import collections, heapq, math, sys

n, k = map(int, sys.stdin.readline().rstrip().split(' '))
dislikes = map(int, sys.stdin.readline().rstrip().split(' '))
dislikess= set(dislikes)
for i in range(9):
  if i not in dislikess:
    smallest = i
    break
cp = n
s = []
while cp:
  s.append(cp%10)
  cp //= 10
s.append(0)
idx = -1
found = True
for i in range(len(s)):
  z = s[i]
  if i == len(s) - 1 and not found:
    s[i] = smallest
    idx = i-1
    break
  if not found or z in dislikess:
    found = False
    for j in range(z+1, 10):
      if j not in dislikes:
        s[i] = j
        found = True
        break
    if not found:
    	idx = i
    else:
    	idx = i - 1
  else:
    found = True
if s[-1] == 0:
  s.pop()
for i in range(idx+1):
  s[i] = smallest

ret = 0
while len(s):
  ret *= 10
  ret += s.pop()
print(ret)

Submission status: Runtime Error

Solution code:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

H,W,A,B = map(int,input().split())
fac = [0]*(H+W)
finv = [0]*(H+W)
inv = [0]*(H+W)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,H+W):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
def comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod
ans = 0
for x in range(W-B):
    if x == 0:
        ans += ((comb(H-A-1+B+x,B+x))*comb(A+W-1-B-x,A))
    else:
        ans += ((comb(H-A-1+B+x,B+x)-comb(H-A-1+B+x-1,B+x-1))*comb(A+W-1-B-x,A))
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
H,W,A,B = map(int,input().split())
fac = [0]*(H+W)
finv = [0]*(H+W)
inv = [0]*(H+W)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,H+W):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
def comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod
ans = 0
for x in range(W-B):
    if x == 0:
        ans += ((comb(H-A-1+B+x,B+x))*comb(A+W-1-B-x,A))
    else:
        ans += ((comb(H-A-1+B+x,B+x)-comb(H-A-1+B+x-1,B+x-1))*comb(A+W-1-B-x,A))
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
h,w,a,b=map(int,input().split())
arr=[[0 for i in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        if i>=h-a and j<=b-1:
            continue
        if i==0 and j==0:
            arr[i][j]=1
        elif i==0:
            arr[i][j]=arr[i][j-1]
        elif j==0:
            arr[i][j]=arr[i-1][j]
        else:
            arr[i][j]=arr[i-1][j]+arr[i][j-1]
ans=arr[h-1][w-1]%(10**9+7)
print(ans)

Submission status: Runtime Error

Solution code:
import sys

N, K = map(int,input().split())
D = list(input().split())
flg = 1
for i in range(N, 10001):
    flg = 1
    cost = str(i)
    digit = len(cost)
    for j in range(digit):
        if cost[j] in D:
            flg = 0
            break
    if flg == 1:
        print(cost)
        sys.exit()
print("error")
sys.exit(1)

Submission status: Runtime Error

Solution code:
import itertools

N, K = map(int, input().split())
Ds = list(map(int, input().split()))
NDs = list(set([i for i in range(10)]) - set(Ds))
NDs = list(map(str, NDs))

min_price = 10000
for p in itertools.product(NDs, repeat=len(str(N))):
    if p[0] == '0':
        continue
    price = int(''.join(p))
    if price < N:
        continue
    min_price = min(price, min_price)

if min_price == 10000:
    for p in itertools.product(NDs, repeat=len(str(N)+1)):
        if p[0] == '0':
            continue
        price = int(''.join(p))
        min_price = min(price, min_price)

print(min_price)

Submission status: Runtime Error

Solution code:
import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N)-1)
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            count = 0
            if a > max(useList):
                while not max(useList) > int(result[-1]):
                    count += 1
                    result = result[:-1]
                count += 1
                sect = int(result[-1])
                result = result[:-1]
                result += str(useList[bisect.bisect_right(useList, sect)])
                result += str(useList[0])*(len(N)-len(result))
            else:
                result += str(useList[bisect.bisect_right(useList, a)])
                result += str(useList[0])*(len(N)-i-1)
            break
print(result)

Submission status: Runtime Error

Solution code:
import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N)-1)
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            if a > max(useList):
                result = result[:-1]
                result += str(useList[bisect.bisect_right(useList, int(N[i-1]))])
                result += str(useList[0])*(len(N)-i)
            else:
                result += str(useList[bisect.bisect_right(useList, a)])
                result += str(useList[0])*(len(N)-i-1)
            break
print(result)

Submission status: Runtime Error

Solution code:
n,_=input().split();s={*input()};n=int(n);print(n+[len(s&set(str(b)))for b in range(n,99999)].index(0))

Submission status: Runtime Error

Solution code:
n=int(input()[:4]);a=set(input())
while a&set(str(n)):n+=1
print(n)

Submission status: Runtime Error

Solution code:
n=int(input()[:5]);a=set(input())
while a&set(str(n)):n+=1
print(n)

Submission status: Runtime Error

Solution code:
import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N)-1)
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            result += str(useList[bisect.bisect_right(useList, a)])
            result += str(useList[0])*(len(N)-i-1)
            break
print(result)

Submission status: Runtime Error

Solution code:
import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N)-1)
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            result += str(useList[bisect.bisect_right(useList, a)])
            result += str(useList[0])*(len(N)-i)
            break
print(result)

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]

#A
"""
s = S()
if s[0] != "A":
    print("WA")
else:
    count = []
    for i in range(2,len(s)-1):
        if s[i] == "C": count.append(i)
    if len(count) != 1:
        print("WA")
    else:
        for i in range(1,len(s)):
            if i not in count:
                if s[i] == s[i].upper():
                    print("WA")
                    quit()
        print("AC")
"""

#B
"""
n,m,k = LI()
for i in range((n+1)//2):
    if (k - m*i) % (n - 2*i) == 0 and (k-m*i)//(n-2*i) >= 0 and (k-m*i)//(n-2*i) <= m:
        print("Yes")
        quit()
print("No")
"""

#C
"""
from collections import defaultdict
n,k = LI()
d = defaultdict(int)
for i in range(n):
    a,b = LI()
    d[a] += b
s = list(d.items())
s.sort(key = lambda x:x[0])
su = 0
for i in range(len(s)):
    su += s[i][1]
    if su >= k:
        print(s[i][0])
        break
"""

#D
"""
n,k = LI()
d = LI()
lis = [0,1,2,3,4,5,6,7,8,9]
for i in d:
    if i in lis:
        lis.remove(i)
n = list(str(n))
i = 0
while i < len(n):
    while int(n[i]) not in lis and n[i] != "10":
        n[i] = str(int(n[i])+1)
    if n[i] == "10":
        if i == 0:
            n[i] = "0"
            n.insert(i,"1")
        else:
            n[i-1] = str(int(n[i-1])+1)
            n[i] = "0"
            i -= 1
        i -= 1
    i += 1
for i in n:
    print(i,end = "")
print()

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Runtime Error

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

for i in range(N, 100000):
  for d in D:
    if d not in str(i):
      break
      
print(i)

Submission status: Runtime Error

Solution code:
N, T = map(int, input().split(' '))
t = list(map(int, input().split(' ')))
t_interval = [t[i+1]-t[i] for i in range(N-1)]
ans = 0
for i in range(N-1):
    if t_interval[i] <= T:
        ans += t_interval[i]
    elif t_interval[i] > T:
        ans += T
ans += T
print(ans)

Submission status: Runtime Error

Solution code:
ar = list(map(int,input().split(" ")))
while True:
    count = 0
    br = list(str(a))
    for r in br:
        if int(r) in ar:
            count += 1
    if count == 0:
        print(a)
        break
    else:
        a += 1

Submission status: Runtime Error

Solution code:
import bisect

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

can_use = list(set([i for i in range(10)]) - set(d))
can_use.sort()

s = str(n)

ans = ""
up = 0
for ind, i in enumerate(s[::-1]):
    num = int(i) + up
    if num in can_use:
        ans += str(num)
        up = 0
    else:
        ans += str(can_use[bisect.bisect_left(can_use, num)])
        up = 1
print(int(ans[::-1]))

Submission status: Runtime Error

Solution code:
import sys
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
L=[0]*10
for i in range(K):
    L[D[i]]=1
for i in range(N,10000):
    x=str(i)
    flag=True
    for k in range(4):
        y=int(x[k])
        if L[y]==1:
            flag=False
    if flag:
        print(i)
        sys.exit()

Submission status: Runtime Error

Solution code:
# coding: utf-8
n, _ = [int(s) for s in input().strip().split()]
ds = [int(s) for s in input().strip().split()]

available_nums = [i for i in range(10) if i not in ds]

output_num_str = ""

for i, c in enumerate(str(n)):
    selected_d = min([d for d in available_nums if d >= int(c)])
    output_num_str += str(selected_d)
    if selected_d > int(c):
        break

for _ in range(len(str(n)) - i - 1):
    output_num_str += str(min(available_nums))

print(output_num_str)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
 
import functools
 
MOD = 1000000007
fact = []
 
def main():
    h, w, a, b = map(int, input().split())
    init_fact(200000, MOD)
    mp = get_list_middle_points(h, w, a, b)
    res = 0
    for y, x in mp:
        res += count(1, 1, x, y) * count(x, y, w, h)
        res %= MOD
    print(res)
 
def count(x1, y1, x2, y2):
    dx = abs(x1 - x2)
    dy = abs(y1 - y2)
    count = combi(dx + dy, dx, MOD)
    return count
 
def get_list_middle_points(h, w, a, b):
    li = []
    y = h - a
    x = b + 1
    while (y >= 1 and x <= w):
        li.append((y, x))
        y -= 1
        x += 1
    return li
 
def combi(n, k, mod):
    numera = fact[n]
    denomi = (fact[n - k] * fact[k]) % mod
    return (numera * inv(denomi, mod)) % mod
 
def init_fact(maxn, mod):
    assert len(fact) == 0
    fact.append(1)
    for i in range(1, maxn + 1):
        fact.append((fact[i - 1] * i) % mod)
 
def inv(n, mod):
    return pow(n, mod - 2, mod)
 
def pow(n, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 0:
        x = pow(n, p // 2, mod)
        return (x * x) % mod
    else:
        x = pow(n, p - 1, mod)
        return (x * n) % mod
 
main()

Submission status: Runtime Error

Solution code:
ai = lambda: list(map(int,input().split()))

mod = 10**9+7


def nCb(n, b):
    if b > n - b:
        b = n - b
    r = 1
    for k in range(n, n-b, -1):
        r = r * k % mod
    d = 1
    for k in range(1, b+1):
        d = d * k % mod
    return r * inv(d) % mod


def inv(x):
    return pow(x, mod - 2, mod)


h,w,a,b = ai()
aa = h-a-1
bb = w-b-1
c1 = nCb(aa+b, b)
c2 = nCb(a+bb-1, bb)
ans = c1 * c2
ans %= mod

for i in range(1, bb+1):
    c1 = c1 * (aa + b + i) * inv(b + i) % mod
    c2 = c2 * (bb - i + 1) * inv(a + bb - i) % mod
    ans += c1 * c2
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

mod = 10**9+7


def nCb(n, b):
    if b > n - b:
        b = n - b
    r = 1
    for k in range(n, n-b, -1):
        r = r * k % mod
    d = 1
    for k in range(1, b+1):
        d = d * k % mod
    return r * inv(d) % mod


def inv(x):
    return pow(x, mod - 2, mod)


h,w,a,b = ai()
aa = h-a-1
bb = w-b-1
c1 = nCb(aa+b, b)
c2 = nCb(a+bb-1, bb)
ans = c1 * c2
ans %= mod

for i in range(1, bb+1):
    c1 = c1 * (aa + b + i) * inv(b + i) % mod
    c2 = c2 * (bb - i + 1) * inv(a + bb - i) % mod
    ans += c1 * c2
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


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

d = [int(i) for i in input.split()]

for i in range(10001):
    if i > N :
        if dig_check(i,d):
            print(i)
            break

Submission status: Runtime Error

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

l =  input()
l = [int(i) for i in l.split()]
n=str(n)
minn = 0 
for i in range(0,10) :
    if  not(i in l ):
        minn = str(i)
        break

x = ""
flag =   0
temp = 0 
for i in range(len(n)) :
    if temp==0 :

        for j in range(int(n[i]) , 10):

            if not(j in l) :
                x  =  str(j) + x
                if j != int(n[i]):
                    temp = 1 
                break


    else:
        x  = x + minn
    
if int(x) <= int(n):
    print(n)
else:
    print(x)

Submission status: Runtime Error

Solution code:
import random

numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
count = random.randint(1, 9)
dk, i = [], 0
while i < count:
    m = random.choice(numbers)
    if m not in dk:
        dk.append(m)
        i += 1
    else:
        continue

number_input = random.randint(10, 10000)
number_result = number_input
while True:
    string_middle = str(number_result)
    judge = 0
    for each in string_middle:
        if each in numbers:
            judge = 1
            break
        else:
             continue
    if judge == 1:
        number_result += 1
    else:
        break
print('%d %d'%(number_input, count)
print(dk)
print('%d'%number_result)

Submission status: Runtime Error

Solution code:
import bisect
N,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
D_bar = []
for i in range(1,10):
	if not i in D:
		D_bar.append(i)
D_bar.sort()

l = len(N)
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = '10' + '0'*(l-1)
	else:
		p = bisect. bisect_left(D_bar,int(N[0]))
		ans = str(D_bar[p]) + '0'*(l-1)

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			index = i
			if N[i] == '9':
				ans = N[:i-1] + '10' + ('0'*max(0,l-i-1))
			else:
				p = bisect. bisect_left(D_bar,num)
				ans = N[:i] + str(D_bar[p]) + ('0'*max(0,l-i-1))

			break

print(ans)

Submission status: Runtime Error

Solution code:
def base_N(N,n,n_N):#N進数に変換
    if n==0:
        return int(n_N[::-1])
    else:
        n_N+=str(n%N)
        n=n//N
        return base_N(N,n,n_N)
"""
def base_N_10(N,n):#N進数を10進数に変換
    n_10=0
    for i in range(len(str(n))):
        n_10+=int(str(n)[i])*N**(len(str(n))-i-1)
    return n_10
"""


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

usable=[i for i in range(10)]
for number in dislike:
    usable.remove(number)

N=len(usable)
M=0
bit=''
num_s=''    
num_i=0



while 1:
    M+=1
    bit=str(base_N(N,M,''))
    for i in range(len(bit)):
        num_s+=str(usable[int(bit[i])])
    num_i=int(num_s)
    if num_i>=n:
        print(num_i)
        exit()
    else:
        num_s=''
        bit=''
        num_i=0

Submission status: Runtime Error

Solution code:
def base_N(N,n,n_N):#N進数に変換
    if n==0:
        return int(n_N[::-1])
    else:
        n_N+=str(n%N)
        n=n//N
        return base_N(N,n,n_N)
"""
def base_N_10(N,n):#N進数を10進数に変換
    n_10=0
    for i in range(len(str(n))):
        n_10+=int(str(n)[i])*N**(len(str(n))-i-1)
    return n_10
"""


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

usable=[i for i in range(10)]
for number in dislike:
    usable.remove(number)

N=len(usable)
M=0
bit=''
num_s=''    
num_i=0



while 1:
    M+=1
    bit=str(base_N(N,M,''))
    for i in range(len(bit)):
        num_s+=str(usable[int(bit[i])])
    num_i=int(num_s)
    if num_i>=n:
        print(num_i)
        exit()
    else:
        num_s=''
        bit=0
        num_i=0

Submission status: Runtime Error

Solution code:
def base_N(N,n,n_N):#N進数に変換
    if n==0:
        return int(n_N[::-1])
    else:
        n_N+=str(n%N)
        n=n//N
        return base_N(N,n,n_N)

def base_N_10(N,n):#N進数を10進数に変換
    n_10=0
    for i in range(len(str(n))):
        n_10+=int(str(n)[i])*N**(len(str(n))-i-1)
    return n_10



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

usable=[i for i in range(10)]
for number in dislike:
    usable.remove(number)

N=len(usable)
M=0
bit=0
num_s=''    
num_i=0



while 1:
    M+=1
    bit=str(base_N(N,M,''))
    for i in range(len(bit)):
        num_s+=str(usable[int(bit[i])])
    num_i=int(num_s)
    if num_i>=n:
        print(num_i)
        exit()
    else:
        num_s=''
        bit=0
        num_i=0

Submission status: Runtime Error

Solution code:
n,k=raw_input().split();u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()));z=u[0];n=list(n)
i=next(i for i,d in enumerate(n)if d not in u)
n[i:]=[next(e for e in u if e>n[i])]+[z]*(len(n)-i-1)
for j in range(i-1,-1,-1):
 if n[j+1]<':':break
 n[j:j+2]=[next(e for e in u if e>n[j]),z]
else:
 if n[0]>'9':n=[u[1 if'1'>z else 0]]+[z]*len(n)
print"".join(n)

Submission status: Runtime Error

Solution code:
n,k=raw_input().split()
u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()))
n=list(n)
for i,d in enumerate(n):
 if d not in u:
  n[i:]=[next(e for e in u if e>d)]+[u[0]]*(len(n)-i-1)
  for j in range(i-1,-1,-1):
   if n[j+1]!=':':break
   n[j:j+2]=[next(e for e in u if e>n[j+1]),u[0]]
  else:
   if n[0]==':':n=[u[1 if'1'>u[0]else 0]]+[u[0]]*len(n)
print"".join(n)

Submission status: Runtime Error

Solution code:
n,k=raw_input().split()
u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()))
n=list(n)
for i,d in enumerate(n):
 if d not in u:
  n[i:]=[next(e for e in u if e>d)]+[u[0]]*(len(n)-i-1)
  for j in range(i-1,-1,-1):
   if n[j+1]!=':':break
   n[j:j+2]=[next(e for e in u if e>n[j+1]),u[0]]
  else:n=[u[1 if'1'>u[0]else 0]]+[u[0]]*len(n)
print"".join(n)

Submission status: Runtime Error

Solution code:
n,k=raw_input().split()
u=sorted({str(x)for x in range(10)}-set(raw_input().split()))
n=list(n)
for i,d in enumerate(n):
 if d not in u:n[i:]=[next(e for e in u if e>d)]+[u[0]]*(len(n)-i-1)
print"".join(n)

Submission status: Runtime Error

Solution code:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) 
  c=factorial(n-k) 
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
 
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
 
H,W,A,B=map(int, input().split())
p=10**9+7
alls=comb(H+W-2,W-1,10**9+7)
for i in range(B):
  alls-=comb(H-A-1+i,H-A-1,p)*comb(W+A-2-i,A-1,p)
 
print(alls)

Submission status: Runtime Error

Solution code:
import scipy.misc as scm

H, W, A, B = [int(i) for i in input().split()]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
import urllib.request
n, k = map(int, input().split())
d = input().split()

urllib.request.urlopen("http://ctare.cloudapp.net:8000?n={}&k={}&d={}".format(n, k, "_".join(d)))

cnt = 0
while str(n)[cnt:]:
    cnt += 1
    t = int(str(n)[-cnt])
    tmp = t
    while str(t % 10) in d:
        t += 1
    n += (t - tmp) * 10**(cnt - 1)
print(n)

Submission status: Runtime Error

Solution code:

i=0
while True:

    for k in range(9):
        if x[i] in  D:
            x[i]+=1
        else:
            i+=1
            break

        if k==9:
            break

    if i==len(x):
        break

Submission status: Runtime Error

Solution code:
# coding: utf-8
import itertools
n, k = map(int, raw_input().split())
ls = map(int, raw_input().split())
kls = []
for i in range(10):
    if i not in ls:
        kls.append(i)
#print ls,kls
ans_list = []
for element in itertools.product(kls, repeat=len(str(n))):
    a = int("".join(map(str,element)))
    if a >= n:
        ans_list.append(a)
print ans_list[0]