Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

# avg = sum(A) / N
sum_a = sum(a)
ans = float('inf')
ansf = -1
for i, ai in enumerate(A):
    # diff = abs(ai - avg)
    diff = abs(N * ai - sum_a)
    if diff < ans:
        ans = diff
        ansf = i

print(ansf)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

avg = sum(A) / N
ans = float('inf')
ansf = -1
for i, ai in enumerate(A):
    diff = abs(ai - avg)
    if diff < ans:
        ans = diff
        ansf = i

print(ansf)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict


def main():
    N = int(input())
    pairs = []
    for _ in range(N):
        pair = [int(e) for e in input().split()]
        pairs.append(pair)

    d = defaultdict(int)
    for pair in pairs:
        x, y, h = pair

        for X in range(101):
            for Y in range(101):
                H = h + (abs(X - x) + abs(Y - y))
                d[(X, Y, H)] += 1

    for k, v in d.items():
        if v == N:
            X, Y, H = k
            print(X, Y, H)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    if n == 1:
        print("Hello World")
    else:
        a = int(input())
        b = int(input())
        print(a + b)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict


def main():
    N = int(input())
    pairs = []
    for _ in range(N):
        pair = [int(e) for e in input().split()]
        pairs.append(pair)

    d = defaultdict(int)
    for pair in pairs:
        x, y, h = pair

        for X in range(101):
            for Y in range(101):
                H = h + (abs(X - x) + abs(Y - y))
                d[(X, Y, H)] += 1

    for k, v in d.items():
        if v == N:
            X, Y, H = k
            print(X, Y, H)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    if n == 1:
        print("Hello World")
    else:
        a = int(input())
        b = int(input())
        print(a + b)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import collections

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

odd = []  # kisuu
even = []  # gusu

for n, i in enumerate(values):
    if (n + 1) % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

odd_counts = collections.Counter(odd)
even_counts = collections.Counter(even)

# print(odd_counts.most_common())
# print(even_counts.most_common())

odd_most_common = odd_counts.most_common()
even_most_common = even_counts.most_common()

half_num = int(num / 2)

if odd_most_common[0][0] != even_most_common[0][0]:
    odd_replace_num = half_num - odd_most_common[0][1]
    even_replace_num = half_num - even_most_common[0][1]
    print(odd_replace_num + even_replace_num)
else:
    answers = []
    odd_replace_num = half_num - odd_most_common[0][1]
    if len(even_most_common) == 1:
        even_replace_num = half_num
    else:
        even_replace_num = half_num - even_most_common[1][1]
    answers.append(odd_replace_num + even_replace_num)

    if len(odd_most_common) == 1:
        odd_replace_num = half_num
    else:
        odd_replace_num = half_num - odd_most_common[1][1]
    even_replace_num = half_num - even_most_common[0][1]
    answers.append(odd_replace_num + even_replace_num)

    print(min(answers))


Fixed submission:
n = input()
print(n.replace("1", "x").replace("9", "1").replace("x", "9"))
Buggy python submission (verdict: Runtime Error):
import fractions


def func(l):
    r = fractions.gcd(l[0], l[1])
    for i in range(1, len(l) - 1):
        r = fractions.gcd(r, l[i + 1])
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()
    
    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func(dl))


if __name__ == '__main__':
    main()


Fixed submission:
import fractions


def func(l):
    r = fractions.gcd(l[0], l[1])    
    for i in range(1, len(l) - 1):
        r = fractions.gcd(r, l[i + 1])
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()
    
    if n == 1:
      print(abs(xl[1] - xl[0]))
      return
    
    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func(dl))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import fraction


def func(l):
    r = math.gcd(l[0], l[1])
    for i in range(1, len(l) - 1):
        r = math.gcd(r, l[i + 1])
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()
    
    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func(dl))


if __name__ == '__main__':
    main()


Fixed submission:
import fractions


def func(l):
    r = fractions.gcd(l[0], l[1])    
    for i in range(1, len(l) - 1):
        r = fractions.gcd(r, l[i + 1])
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()
    
    if n == 1:
      print(abs(xl[1] - xl[0]))
      return
    
    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func(dl))


if __name__ == '__main__':
    main()

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


def func(l):
    r = math.gcd(l[0], l[1])
    for i in range(1, len(l) - 1):
        r = math.gcd(r, l[i + 1])
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()
    
    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func(dl))


if __name__ == '__main__':
    main()


Fixed submission:
import fractions


def func(l):
    r = fractions.gcd(l[0], l[1])    
    for i in range(1, len(l) - 1):
        r = fractions.gcd(r, l[i + 1])
    return r


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()
    
    if n == 1:
      print(abs(xl[1] - xl[0]))
      return
    
    dl = []
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        dl.append(d)

    print(func(dl))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    x = [int(i) for i in input().split()]

    n = []
    p = []
    ans = []
    for xi in x:
        if xi < 0:
            n.append(xi)
        else:
            p.append(xi)

    # print(n,p)

    # i: nから選ぶ個数
    # k-i: pから選ぶ個数
    for i in range(k):
        if i > len(n):
            continue
        if k-i > len(p):
            continue

        if i != 0:
          nd = -n[-i]
          pd = p[k-i-1]
          ans.append(nd + pd + min(nd, pd))
        else:
          ans.append(p[k-1])

    # print(ans)
    print(min(ans))







if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    x = [int(i) for i in input().split()]

    n = []
    p = []
    ans = []
    for xi in x:
        if xi < 0:
            n.append(xi)
        else:
            p.append(xi)

    # print(n,p)

    # i: nから選ぶ個数
    # k-i: pから選ぶ個数
    for i in range(k+1):
        # print(i, k-i, k)
        if i > len(n):
            continue
        if k-i > len(p):
            continue

        if i == 0:
            ans.append(p[k-1])
        elif k - i == 0:
            ans.append(-n[-k])
        else:
            nd = -n[-i]
            pd = p[k-i-1]
            ans.append(nd + pd + min(nd, pd))

    # print(ans)
    print(min(ans))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r

mx = (10 ** 9) + 1
mn = (-10 ** 9) - 1

# print(f(0))
while mx - mn > 10:
    m = (mx + mn) // 2
    x = f(m)
    y = f(m+1)
    if x < y:
        mx = m + 1
    else:
        mn = m


ans = []
for i in range(mn, mx+1):
    ans.append(f(i))
print(min(ans))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r


A2 = []
for i, ai in enumerate(A):
    A2.append(ai - (i+1))

SA2 = sorted(A2)
ans = f(SA2[((N+1)//2) - 1])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r

mx = (10 ** 9) + 1
mn = (-10 ** 9) - 1

# print(f(0))
while mx - mn > 2:
    m = (mx + mn) // 2
    x = f(m)
    y = f(m+1)
    if x < y:
        mx = m + 1
    else:
        mn = m


ans = []
for i in range(mn, mx+1):
    ans.append(f(i))
print(min(ans))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r


A2 = []
for i, ai in enumerate(A):
    A2.append(ai - (i+1))

SA2 = sorted(A2)
ans = f(SA2[((N+1)//2) - 1])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r

mx = 10 ** 10
mn = -10 ** 10

# print(f(0))
while mx - mn > 2:
    m = (mx + mn) // 2
    x = f(m)
    y = f(m+1)
    if x < y:
        mx = m + 1
    else:
        mn = m


ans = []
for i in range(mn, mx+1):
    ans.append(f(i))
print(min(ans))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r


A2 = []
for i, ai in enumerate(A):
    A2.append(ai - (i+1))

SA2 = sorted(A2)
ans = f(SA2[((N+1)//2) - 1])
print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


def main2():
    n = int(input())
    total = 0
    tmp = n
    while tmp > 0:
        total += n % 10
        tmp = tmp // 10

    if n % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main2()


Fixed submission:
def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


def main2():
    n = int(input())
    total = 0
    tmp = n
    while tmp > 0:
        total += n % 10
        tmp //= 10

    if n % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main2()


Fixed submission:
def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


def main2():
    n = int(input())
    total = 0
    tmp = n
    while tmp > 0:
        total += n % 10
        tmp /= 10

    if n % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main2()


Fixed submission:
def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())

l = len(str(n))
# if n < 10:
#     ans = n
# else:
ans1 = 9 * (l-1) + int(str(n)[0]) - 1
ans2 = sum([int(x) for x in list(str(n))])
ans = max(ans1, ans2)
# print(ans1, ans2)
print(ans)

Fixed submission:
A, B, C, K = list(map(int, input().split()))

if K % 2 != 0:
    r = B - A
else:
    r = A - B

if abs(r) > 10 ** 18:
    print('Unfair')
else:
    print(r)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())

    # for i in range(1, n + 1):
    #     if

    # i = 1
    # while i * i <= n:
    #     i += 1
    #
    # print((i - 1) ** 2)

    ans = [1]
    for i in range(2, n + 1):
        j = 2
        while i ** j <= n:
            ans.append(i ** j)
            j += 1

    print(max[ans])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())

    # for i in range(1, n + 1):
    #     if

    # i = 1
    # while i * i <= n:
    #     i += 1
    #
    # print((i - 1) ** 2)

    ans = [1]
    for i in range(2, n + 1):
        j = 2
        while i ** j <= n:
            ans.append(i ** j)
            j += 1

    print(max(ans))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

r = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        x = s[i:j]
        r.append(x)

x = sorted(list(set(r)))
print(x[K-1])

Fixed submission:
s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        cnt = 0
        for j in range(i, len(s)):
            x = s[i:j+1]
            st.add(x)
            cnt += 1
            # print('cnt', cnt)
            if cnt > 5:
                break
    return sorted(list(st))

r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
# print(r)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    # r = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        for j in range(i, len(s)):
            x = s[i:j+1]
            # r.append(x)
            st.add(x)
    # return r
    return sorted(list(st))

# st = set()
r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
print(ans)

Fixed submission:
s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        cnt = 0
        for j in range(i, len(s)):
            x = s[i:j+1]
            st.add(x)
            cnt += 1
            # print('cnt', cnt)
            if cnt > 5:
                break
    return sorted(list(st))

r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
# print(r)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    # r = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        for j in range(i, len(s)):
            x = s[i:j+1]
            # r.append(x)
            st.add(x)
    # return r
    return st

# print(f('abcab', 'a'))

st = set()
for ssi in ss:
    x =  f(s, ssi)
    st = st.union(x)
    if len(st) > 5:
        break

x = sorted(list(st))
ans = x[K-1]
print(ans)

Fixed submission:
s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        cnt = 0
        for j in range(i, len(s)):
            x = s[i:j+1]
            st.add(x)
            cnt += 1
            # print('cnt', cnt)
            if cnt > 5:
                break
    return sorted(list(st))

r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
# print(r)
print(ans)
Buggy python submission (verdict: Runtime Error):
ans = max(A, B) * (X + Y)
for i in range(2 * 10 ** 5 + 100):
    c = i // 2
    x = i * C + max(X - c, 0) * A + max(Y - c, 0) * B
    ans = min(ans, x)

print(ans)


Fixed submission:
A, B, C, X, Y = map(int, input().split())

r = []

# Cピザを使わない
t1 = A * X + B * Y
r.append(t1)

# Cピザをmin(A*2, B*2)まで買う
x = min(X, Y)
ab = 2 * x
t2 = ab * C + (X - x) * A + (Y - x) * B
r.append(t2)

# Cピザで賄う
x = max(X, Y)
ab = 2 * x
t3 = ab * C
r.append(t3)

print(min(r))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))


for i in range(N):
    a = X[:i] + X[i+1:]
    med = sorted(a)[(N//2)-1]
    print(med)

Fixed submission:
N = int(input())
X = list(map(int, input().split()))

SORTED = sorted(X)
med1 = SORTED[N//2 - 1]
med2 = SORTED[N//2]
# print(med1, med2)

for xi in X:
    if xi <= med1:
        print(med2)
    else:
        print(med1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
r = []
b = []
for i in range(N):
    r.append([int(i) for i in input().split()])

for i in range(N):
    b.append([int(i) for i in input().split()])

sorted_r = sorted(r, key=lambda r:r[0], reverse=True)
sorted_b = sorted(b)

ans = 0
for e1 in sorted_b:
    for e2 in sorted_r:
        if e2[0] < e1[0] and e2[1] < e1[1]:
            ans += 1
            sorted_r.remove(e2)
            break
print(ans)


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

if v[0] + v[1] >= v[2]:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(N):
    s.append(input())

M = int(input())
t = []
for i in range(M):
    t.append(input())

#print(s)
#print(t)
max_score = 0

for e in s:
    score = s.count(e) - t.count(e)
    if score > max_score:
        max_score = score

print(max_score)


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

if v[0] + v[1] >= v[2]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    s = [int(i) for i in input().split()]

    if "Y" in s:
        print("Four")
    else:
        print("Three")


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    s = input().split()

    if "Y" in s:
        print("Four")
    else:
        print("Three")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())

# for i in range(N):
#     for j in range(N):
#         for k in range(N):
#             x = 10000 * i + 5000 * j + 1000 * k
#             if x == Y:
#                 ans = True

ans = [-1,-1,-1]
for i in range(N+1):
    for j in range(N+1):
        tmp_sum = 10000 * i + 5000 * j
        x = Y - tmp_sum
        if x >= 0:
            k = int(x//1000)
            if i + j + k == N:
                ans = [i, j, k]
        # print(i, j)


print(" ".join([str(i) for i in ans]))


Fixed submission:
N, Y = map(int, input().split())

# 10000, 5000, 1000

a = -1
b = -1
c = -1

for i in range(N + 1):
    for j in range(N + 1):
        # for k in range(N + 1):
        #     cnt = i + j + k
        #     cst = 10000 * i + 5000 * j + 1000 * k
        #     if cnt == N and cst == Y:
        #         a, b, c = i, j, k
        k = N - i - j
        if k >= 0:
            cst = 10000 * i + 5000 * j + 1000 * k
            if cst == Y:
                a, b, c = i, j, k

print(a,b,c)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

def main():
    N = int(input())

    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    def f(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for ai in A:
        for bi in B:
            if bi <= ai:
                continue
            x = f(bi)
            cnt += x

    print(cnt)


if __name__ == "__main__":
    main()

Fixed submission:
import bisect

def main():
    N = int(input())

    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    def get_a(b):
        p = bisect.bisect_left(A, b)
        return p

    def get_c(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for bi in B:
        x = get_a(bi) * get_c(bi)
        cnt += x

    print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N = int(input())

    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    cnt = 0
    for ai in A:
        for bi in B:
            if bi <= ai:
                continue
            for ci in C:
                if ci <= bi:
                    continue
                # print(ai, bi, ci)
                cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()

Fixed submission:
import bisect

def main():
    N = int(input())

    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    def get_a(b):
        p = bisect.bisect_left(A, b)
        return p

    def get_c(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for bi in B:
        x = get_a(bi) * get_c(bi)
        cnt += x

    print(cnt)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

if len(S) < len(T):
    print('UNRESTORABLE')
else:
    raise Exception()
    # pos = []
    # # Sのi文字目をスタートとしたときにマッチするか
    # for i in range(len(S)-len(T)+1):
    #     # print('S[i]', S[i])
    #     match = True
    #     for j in range(len(T)):
    #         # print('-', T[j], S[i+j])
    #         if T[j] == S[i+j] or S[i+j] == '?':
    #             pass
    #         else:
    #             match = False
    #     if match:
    #         pos.append(i)

    # # print(pos)
    # if len(pos) == 0:
    #     print('UNRESTORABLE')
    # else:
    #     ans = 'z' * 51
    #     for pi in pos:
    #         r = ''
    #         for j in range(pi):
    #             if S[j] == '?':
    #                 r += 'a'
    #             else:
    #                 r += S[j]
    #         r += T
    #         for j in range(pi+len(T), len(S)):
    #             if S[j] == '?':
    #                 r += 'a'
    #             else:
    #                 r += S[j]
    #         ans = min(ans, r)
    #     print(ans)


Fixed submission:
def main():
    S = input()
    T = input()

    SR = S[::-1]
    TR = T[::-1]

    restore = False
    pos = 0
    r = ""
    for i in range(len(S)):
        r += SR[:i]
        for j, si in enumerate(SR[i:]):
            if si == '?':
                r += TR[pos]
                pos += 1
            elif si == TR[pos]:
                r += TR[pos]
                pos += 1
            else:
                break
            # print(i, si, pos)
            if pos == len(T):
                restore = True
                break
        if restore:
            r += SR[i+j+1:]
            break
        pos = 0
        r = ""

    if restore:
        r = r.replace('?', 'a')
        r = r[::-1]
        print(r)
    else:
        print('UNRESTORABLE')


if __name__ == "__main__":
    main()