Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02732 (python)

Fixed submission:
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        if col[key] < 2:
            com[key] = 0
        else:
            com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = com[v] - c
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = com[v] - c
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = combinations_count(c, 2)
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = combinations_count(c, 2)
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()
Problem p02780 (python)

Fixed submission:

url = "https://atcoder.jp//contests/abc154/tasks/abc154_d"

def search_ind(lis, k):
    tmp = sum(lis[0:k])
    m = tmp
    inds = [0, k - 1]
    for i in range(0, len(lis) - k):
        tmp = tmp - lis[i] + lis[i + k]
        # print(tmp, lis[i + k])
        if tmp > m:
            inds = [i + 1, i + k]
            m = tmp
    return inds

def main():
    n, k = list(map(int, input().split()))
    daice = list(map(int, input().split()))
    f, t = search_ind(daice, k)
    kitai = daice[f:t + 1]
    ans = 0
    for v in kitai:
        sumt = 0
        for i in range(1, v + 1):
            sumt += i * (1 / v)
        ans += sumt
    print(ans)




if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, k = list(map(int, input().split()))
    daice = list(map(int, input().split()))
    daice_kitai = [0]

    tmp = 0
    for i in range(1, 7):
        tmp += i
        daice_kitai.append(tmp * (1 / i))
    for i in range(0, len(daice) - k + 1):
        count = 0
        tmp = 0
        for j in range(i, i + k):
            tmp += daice_kitai[daice[j]]
        count = tmp if tmp > count else count
    print(count)


if __name__ == '__main__':
    main()
Problem p02830 (python)

Fixed submission:
def main():
    input()
    l = list(input().split())
    ans = []
    for i in range(len(l[0])):
        ans.append(l[0][i])
        ans.append(l[1][i])
    print(''.join(ans))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    input()
    l = list(input().split())
    ans = []
    for i in range(len(l)):
        ans.append(l[0][i])
        ans.append(l[1][i])
    print(''.join(ans))

if __name__ == '__main__':
    main()
Problem p02995 (python)

Fixed submission:
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



def main2():
    a, b, c, d = list(map(int, input().split()))

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    di = lcm(c,d)
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()

Buggy submission (verdict: Runtime Error):
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)



def main2():
    a, b, c, d = list(map(int, input().split()))

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    di = lcm(c,d)
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()
Problem p03380 (python)

Fixed submission:
def main3():
    input()
    t = sorted(list(map(int, input().split())))
    ma = t.pop(-1)
    r = min(t, key=lambda x: abs(x - ma / 2))
    print(ma, r)

if __name__ == '__main__':
    main3()

Buggy submission (verdict: Runtime Error):
import math

def main2():
    input()
    t = sorted(list(map(int, input().split())))
    c = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2]) * math.factorial(t[len(t)//2]))
    c2 = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2 + 1]) * math.factorial(t[len(t)//2 + 1]))
    if c < c2:
        print(t[-1], t[len(t) // 2 + 1])
    else:
        print(t[-1], t[len(t) // 2])



if __name__ == '__main__':
    main2()

Buggy submission (verdict: Runtime Error):
import math

def main2():
    input()
    t = sorted(list(map(int, input().split())))
    combs = {}
    comb(t[-1], t[len(t)//2], exact=True)
    c = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2]) * math.factorial(t[len(t)//2]))
    c2 = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2 + 1]) * math.factorial(t[len(t)//2 + 1]))
    if c < c2:
        print(t[-1], t[len(t) // 2 + 1])
    else:
        print(t[-1], t[len(t) // 2])



if __name__ == '__main__':
    main2()

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb


def main2():
    input()
    t = sorted(list(map(int, input().split())))
    combs = {}
    c = comb(t[-1], t[len(t)//2], exact=True)
    c2 = comb(t[-1], t[len(t)//2 + 1], exact=True)
    if c < c2:
        print(t[-1], t[len(t) // 2 + 1])
    else:
        print(t[-1], t[len(t) // 2])



if __name__ == '__main__':
    main2()

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb

url = "https://atcoder.jp//contests/abc094/tasks/arc095_b"

def main():
    input()
    t = list(map(int, input().split()))
    combs = {}
    for i in range(len(t) - 1, len(t) - 1):
        for j in range(i + 1, len(t)):
            tmp = sorted([t[i], t[j]], reverse=True)
            combs[comb(tmp[0], tmp[1], exact=True)] = tmp[::]
    key = max(combs.keys())
    print(' '.join([str(v) for v in combs[key]]))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

url = "https://atcoder.jp//contests/abc094/tasks/arc095_b"

def main():
    input()
    t = list(map(int, input().split()))
    combs = {}
    for i in range(len(t)):
        for j in range(i + 1, len(t)):
            tmp = sorted([t[i], t[j]], reverse=True)
            combs[comb(tmp[0], tmp[1], exact=True)] = tmp[::]
    key = max(combs.keys())
    print(' '.join([str(v) for v in combs[key]]))

if __name__ == '__main__':
    main()
Problem p03455 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = a * b
if c % 2 != 0:
  print('Odd')
else:
  print('Even')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split(' '))
c = a * b
if C % 2 == 0:
  print(Odd)
else
  print(Even)
Problem p03469 (python)

Fixed submission:
if __name__ == '__main__':
    t = list(input())

    t[3] = '8'
    print(''.join(t))

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    t = int(input())
    s = []
    for i in range(t):
        s.append(int(input()))
    print(len(set(s)))

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    t = int(input())
    s = set()
    for i in range(t):
        s.add(int(input()))
    print(len(s))

Buggy submission (verdict: Runtime Error):
t = int(input())
s = set()
for i in range(t):
  s.add(int(input()))
print(len(s))
Problem p03471 (python)

Fixed submission:
def main2():
    t = (input().split(' '))
    t = [int(v) for v in t]
    if t[0] * 10000 < t[1]:
        print('-1 -1 -1')
        exit(0)
    for i in range(t[0] + 1):
        for j in range((t[0] + 1) - i):
            if (10000 * i) + (5000 * j) + ((t[0] - i - j) * 1000) == t[1]:
                print(i, j, (t[0] - i - j))
                exit(0)

    print('-1 -1 -1')


if __name__ == '__main__':
    main2()

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    t = (input().split(' '))
    t = [int(v) for v in t]
    for i in range(t[0]):
        for j in range(t[0] - i):
            for k in range(t[0] - j):
                if (10000 * i) + (5000 * j) + (k * 1000) == t[1]:
                    if i + j + k == t[0]:
                        print(i, j, k)
                        exit(1)

    print('-1 -1 -1')
Problem p03472 (python)

Fixed submission:
def main():
    n,h = list(map(int, input().split()))
    bi = []
    max_attack = [0,0]
    for i in range(n):
        a, b = list(map(int, input().split()))
        bi.append(b)
        max_attack[0] = max(a, max_attack[0])
        max_attack[1] = max(b, max_attack[1])
    bi.sort(reverse=True)
    idx = 0
    count = 0
    while h > 0:
        damage = 0
        if idx < len(bi) and max_attack[0] < bi[idx]:
            damage = bi[idx]
            idx += 1
        else:
            count += h // max_attack[0]
            count += 0 if h % max_attack[0] == 0 else 1
            break
        h -= damage
        count += 1
    print(count)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n,h = list(map(int, input().split()))
    bi = []
    max_attack = [0,0]
    for i in range(n):
        a, b = list(map(int, input().split()))
        bi.append(b)
        max_attack[0] = max(a, max_attack[0])
        max_attack[1] = max(b, max_attack[1])
    bi.sort(reverse=True)
    idx = 0
    count = 0
    while h > 0:
        damage = 0
        if max_attack[0] < bi[idx]:
            damage = bi[idx]
            idx += 1
        else:
            # count += max_attack[0] // h
            count += h // max_attack[0]
            break
        h -= damage
        count += 1
    print(count)



if __name__ == '__main__':
    main()
Problem p03477 (python)

Fixed submission:
t = [int(v) for v in input().split(' ')]
n = t[0] + t[1]
n2 = t[2] + t[3]
 
if n > n2:
  print('Left')
elif n < n2:
  print('Right')
elif n == n2:
  print('Balanced')

Buggy submission (verdict: Runtime Error):
t = [int(v) for v in input().split(' ')]
n = t[0] + t[1]
n2 = t[2] + t[3]

if n > n2:
  print(n)
elif n < n2:
  print()n2
Problem p03479 (python)

Fixed submission:
def main():
    f, t = [int(v) for v in input().split(' ')]
    count = 0
    d = 1
    tmp = f
    while True:
        tmp = tmp * 2
        if tmp > t:
            break
        count += 1

    print(count + 1)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    f, t = [int(v) for v in input().split(' ')]
    count = 0
    d = 1
    while True:
        tmp = f * 2
        if tmp > t:
            break
        count += 1
        print(tmp)
        d += 1
        f = tmp
    print(count + 1)
    print(read_val.get_file_value("ans"))



if __name__ == '__main__':
    main()
Problem p03486 (python)

Fixed submission:
url = "https://atcoder.jp/contests/abc082/tasks/abc082_b"


def main():
    s1, s2 = [input() for i in range(2)]
    l1 = sorted(list(s1))
    l2 = sorted(list(s2), reverse=True)
    indx = 0
    if len(l1) > len(l2):
        indx = len(l2)
    else:
        indx = len(l1)
    for i in range(indx):
        if l1[i] < l2[i]:
            print('Yes')
            exit()
    if len(l1) < len(l2) and l1[-1] <= l2[-1]:
        print('Yes')
        exit()
    print('No')




if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
url = "https://atcoder.jp/contests/abc082/tasks/abc082_b"


def main():
    s1, s2 = [input() for i in range(2)]
    l1 = sorted(list(s1))
    l2 = sorted(list(s2), reverse=True)
    for i in range(len(l1)):
        if l1[i] < l2[i]:
            print('Yes')
            exit()
    if len(l1) < len(l2) and l1[-1] <= l2[-1]:
        print('Yes')
        exit()
    print('No')




if __name__ == '__main__':
    main()
Problem p03501 (python)

Fixed submission:
tmp = input().split()
val = [int(v) for v in tmp]
if val[0] * val[1] >= val[2]:
  ans = val[2]
else:
  ans = val[0] * val[1]
print(ans)

Buggy submission (verdict: Runtime Error):

tmp = list(input()).split()
val = [int(v) for v in tmp]
if val[0] * val[1] >= val[2]:
  ans = val[2]
  else:
    ans = val[0] * val[1]
Problem p03607 (python)

Fixed submission:

url = "https://atcoder.jp//contests/abc073/tasks/abc073_c"

def main():
    li = {}
    n = int(input())
    for i in range(n):
        ind = int(input())
        li.setdefault(ind, 0)
        if li[ind] == 0:
            li[ind] = 1
        else:
            li[ind] = 0
    print(list(li.values()).count(1))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

url = "https://atcoder.jp//contests/abc073/tasks/abc073_c"

def main():
    li = [0] * (10 ** 5)
    li.append(0)

    n = int(input())
    for i in range(n):
        ind = int(input())
        if li[ind] == 0:
            li[ind] = 1
        else:
            li[ind] = 0
    print(li.count(1))
if __name__ == '__main__':
    main()
Problem p03611 (python)

Fixed submission:
n = int(input())
cnt = [0] * 100002
a = list(map(int, input().split()))
for v in a:
    cnt[v] += 1
    cnt[v+1] += 1
    cnt[v+2] += 1
    
print(max(cnt))

Buggy submission (verdict: Runtime Error):
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        v_1 = s_li.count(v - 1)
        v_0 = s_li.count(v) + s_li.count(v + 1)
        v_2 = s_li.count(v + 2)
        t_c = v_1 + v_0
        t_c2 = v_2 + v_0

        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if count > len(s_li):
            break
        s_li = s_li[s_li.index(v + 1):]
    print(count)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import read_val
import copy


def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
            if vv > v + 2:
                break
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    t = input()
    if t == "1":
        print(input())
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        list_2 = list(filter(lambda x: x == v - 1 or x == v or x == v + 1, s_li))
        if len(list_2) > count:
            count = len(list_2)

    print(count)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import read_val
import copy


def main():
    t = input()
    if t == "1":
        print(input())
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        list_2 = list(filter(lambda x: x == v - 1 or x == v or x == v + 1, s_li))
        if len(list_2) > count:
            count = len(list_2)

    print(count)



if __name__ == '__main__':
    main()
Problem p03623 (python)

Fixed submission:
t = [int(v) for v in input().split(" ")]

n = t[0] - t[1]
n2 = t[0] - t[2]
if abs(n) > abs(n2):
  print('B')
else:
  print('A')

Buggy submission (verdict: Runtime Error):
t = [int(v) for v in split(input())]

n = t[0] - t[1]
n2 = t[0] - t[2]
if abs(n) > abs(n2):
  print(n2)
else:
  print(n)
Problem p03624 (python)

Fixed submission:
alph = [chr(i) for i in range(97, 97+26)]

s = input()
s_li = set(sorted(list(s)))

for v in alph:
    if v not in s_li:
        print(v)
        exit(0)
print('None')

Buggy submission (verdict: Runtime Error):
lph = [chr(i) for i in range(97, 97+26)]

s = input()
s_li = set(sorted(list(s)))

for v in alph:
    if v not in s_li:
        print(v)
        exit(0)
print('None')
Problem p03643 (python)

Fixed submission:
def main():
    n = input()
    print('ABC%s' % n)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    n = input()
    print(f'ABC{n}')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    print(f'ABC{input()}')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    print(f'ABC{input()}')

if __name__ == '__main__':
    main()
Problem p03695 (python)

Fixed submission:
def main():
    input()
    rate = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 4800]
    t = list(map(int, input().split()))
    ret = {399: 0, 799: 0, 1199: 0, 1599: 0, 1999: 0, 2399: 0, 2799: 0, 3199: 0, 4800: 0}
    for v in t:
        for r in rate:
            if v <= r:
                ret[r] += 1
                break
    count = 0
    for k in ret:
        if ret[k] >= 1 and k != 4800:
            count += 1
    if count == 0:
        print(1, count + ret[4800])
    else:
        print(count, count + ret[4800])
    # print(ret)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    input()
    rate = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 3200]
    t = list(map(int, input().split()))
    ret = {399: 0, 799: 0, 1199: 0, 1599: 0, 1999: 0, 2399: 0, 2799: 0, 3199: 0, 4800: 0}
    for v in t:
        for r in rate:
            if v <= r:
                ret[r] += 1
                break
    count = 0
    for k in ret:
        if ret[k] >= 1 and k != 4800:
            count += 1
    print(count, count + ret[4800])
    # print(ret)



if __name__ == '__main__':
    main()
Problem p03699 (python)

Fixed submission:
def main():
    n = int(input())
    test = [int(input()) for i in range(n)]
    score = sum(test)
    test.sort()
    x_test = list(filter(lambda x:x % 10 != 0, test))
    if len(x_test) == 0:
        print(0)
        exit()
    elif score % 10 != 0:
        print(score)
        exit()
    x_test.sort()
    print(score - x_test[0])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    test = [int(input()) for i in range(n)]
    score = sum(test)
    test.sort()
    if len(list(filter(lambda x:x % 10 == 0, test))) == n:
        print(0)
        exit()

    ind = 0
    while score % 10 == 0 or score > 10:
        tmp = []
        for i in range(len(test)):
            tmp.append(score - test[i])
        score = max(tmp)
        test.pop(tmp.index(max(tmp)))
    print(score)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    test = [int(input()) for i in range(n)]
    score = sum(test)
    test.sort()
    if len(list(filter(lambda x:x % 10 == 0, test))) == n:
        print(0)
        exit()
    tmp = []
    ind = 0
    while score % 10 == 0:
        for i in range(len(test)):
            tmp.append(score - test[i])
        score = max(tmp)
        test.pop(tmp.index(max(tmp)))
    print(score)

if __name__ == '__main__':
    main()
Problem p03729 (python)

Fixed submission:
def main():
    a,b,c = input().split(' ')
    if a[-1] == b[0] and b[-1] == c[0]:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b,c = list(map(int, input().split()))
    if a[-1] == b[0] and b[-1] == c[0]:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()
Problem p03846 (python)

Fixed submission:
import math

def fail():
    print(0)
    exit()

def main():
    n = int(input())
    As = list(map(int, input().split(' ')))
    ind_lis = {}
    idx = n - 1
    while idx >= 0:
        ind_lis[idx] = 0
        idx -= 2
    for a in As:
        if a not in ind_lis:
            fail()
        ind_lis[a] += 1
        if a == 0 and ind_lis[a] > 1:
            fail()
        elif ind_lis[a] > 2:
            fail()
    print(2**(n//2)%(10**9 + 7))



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
def main():
    n = int(input())
    As = list(map(int, input().split(' ')))
    ind_lis = {}
    idx = n - 1
    while idx >= 0:
        ind_lis[idx] = 0
        idx -= 2
    for a in As:
        ind_lis[a] += 1
        if a == 0 and ind_lis[a] > 1:
            print(0)
            exit()
        elif ind_lis[a] > 2:
            print(0)
            exit()
    print(2**(n//2)%(10**9 + 7))



if __name__ == '__main__':
    main()
Problem p03854 (python)

Fixed submission:

url = "https://atcoder.jp//contests/abc049/tasks/arc065_a"

def main():
    words = ['dream','dreamer', 'erase', 'eraser']
    s = input()
    rs = s[::-1]
    while rs != '':
        tmp = len(rs)
        for word in words:
            if len(word) > len(rs):
                continue
            rs = rs[0:len(word)].replace(word[::-1], '') + rs[len(word):]
        if tmp == len(rs):
            print('NO')
            exit()
    print('YES')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

url = "https://atcoder.jp//contests/abc049/tasks/abc049_b"

def main():
    h, w = list(map(int, input().split()))
    ss = [input() for _ in range(h)]
    for s in ss:
        print(s)
        print(s)

if __name__ == '__main__':
    main()
Problem p04029 (python)

Fixed submission:
url = "https://atcoder.jp/contests/abc043/tasks/abc043_a"

def main():

    a = int(input())
    ans = 0
    for i in range(1, a + 1):
        ans += i
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    t = input().split()
    dis = list(map(int, input().split()))
    like = []
    for i in range(0,10):
        if i not in dis:
            like.append(i)
    ans = []
    digit = False
    for i in range(len(t[0])):
        if digit:
            break
        ans.append(-1)
        for j, v in enumerate(like):
            if int(t[0][i]) == v:
                ans[-1] = j
                break
            elif int(t[0][i]) < v:
                ans[-1] = j
                for m in range(i + 1, len(t[0])):
                    ans.append(0)
                digit = True
                break

    ind = 0
    ans_s = []
    for i in reversed(ans):
        if i == -1:
            ind += 1
            ans_s.append(0)
        elif ind > 0:
            if i == len(like) - 1:
                ans_s.append(0)
            else:
                ans_s.append(i + ind)
                ind = 0
        else:
            ans_s.append(i)
    print(ans_s)
    if ind > 0:
        ans_s.append(-1)
    ans_s.reverse()
    if len(ans_s) == 1 and int(t[0][0]) > like[ans_s[0]]:
        ans_s.append(0)
    for i in range(0, len(ans_s)):
        ans_s[i] = str(like[ans_s[i]])
    print(''.join(ans_s))


if __name__ == '__main__':
    main()