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


ups = []
downs = []
eqs = []
for i in range(3):
    if A[i] < B[i]:
        ups.append((A[i], B[i]))
    elif A[i] == B[i]:
        eqs.append((A[i], B[i]))
    else:
        downs.append((A[i], B[i]))
ans = N

if len(eqs) == 3:
    print(N)
    exit()

if len(ups) == 0:
    tmp = A
    A = B
    B = tmp
    tmp = ups
    ups = downs
    downs = tmp

if len(ups) == 3:
    gold_diff = B[0]-A[0]
    silver_diff = B[1]-A[1]
    cupper_diff = B[2]-A[2]
    for gold in range(N//A[0]+1):
        left = N - gold*A[0]
        for silver in range(left//A[1]+1):
            cupper = (left - silver*A[1])//A[2]
            tmp_ans = (N
                       + gold*gold_diff
                       + silver*silver_diff
                       + cupper*cupper_diff)
            ans = max(ans, tmp_ans)
    print(ans)
elif len(ups) == 2:
    gold_diff = ups[0][1]-ups[0][0]
    silver_diff = ups[1][1]-ups[1][0]
    for gold in range(N//ups[0][0]+1):
        left = N - gold*ups[0][0]
        silver = left // ups[1][0]
        tmp_ans = (N
                   + gold*gold_diff
                   + silver*silver_diff)
        ans = max(ans, tmp_ans)
    if len(downs) == 1:
        diff = downs[0][0]-downs[0][1]
        ans += (ans // downs[0][1]) * diff
    print(ans)
elif len(ups) == 1:
    bbans = N + (N//ups[0][0])*(ups[0][1]-ups[0][0])
    if len(downs) == 2:
        tmp_ans = bbans
        gold_diff = downs[0][0]-downs[0][1]
        silver_diff = downs[1][0]-downs[1][1]
        for gold in range(bbans//downs[0][1]+1):
            left = bbans - gold*downs[0][1]
            silver = left // downs[1][1]
            tmp_ans = (bbans
                       + gold*gold_diff
                       + silver*silver_diff)
            ans = max(ans, tmp_ans)
    elif len(downs) == 1:
        ans =bbans + (bbans//downs[0][1])*(downs[0][0]-downs[0][1])
    eise:
        ans = bbans
    print(ans)


Fixed submission:
N, K = map(int, input().split(" "))
if K == 1:
    print(0)
    exit()
print(str(N - K))
Buggy python submission (verdict: Runtime Error):
import itertools
from collections import Counter

N = int(input())
point = [tuple(map(int, input().split())) for _ in range(N)]

ans = Counter()
if N == 1:
    print(1)
    exit()

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    if sx-fx < 0 or sy-fy < 0:
        continue
    else:
        ans[(sx-fx, sy-fy)] += 1
print(min(1, N - ans.most_common()[0][1]))


Fixed submission:
import itertools
from collections import Counter

N = int(input())
point = [tuple(map(int, input().split())) for _ in range(N)]

ans = Counter()
if N == 1:
    print(1)
    exit()

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    ans[(sx-fx, sy-fy)] += 1

print(max(1, N - ans.most_common()[0][1]))

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

N = int(input())
point = [tuple(map(int, input().split())) for _ in range(N)]

ans = Counter()

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    if sx-fx < 0 or sy-fy < 0:
        continue
    else:
        ans[(sx-fx, sy-fy)] += 1
print(N - ans.most_common()[0][1])


Fixed submission:
import itertools
from collections import Counter

N = int(input())
point = [tuple(map(int, input().split())) for _ in range(N)]

ans = Counter()
if N == 1:
    print(1)
    exit()

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    ans[(sx-fx, sy-fy)] += 1

print(max(1, N - ans.most_common()[0][1]))
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            break
            flag = True
        count += c-A[now]
        b -= 1
        now += 1
        if now >= N:
            break
            flag = True
        if b <= 0:
            break
    if flag:
        break
print(sum(A) + count)


Fixed submission:
from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            flag = True
            break
        count += c-A[now]
        b -= 1
        now += 1
        if now >= N:
            flag = True
            break
        if b <= 0:
            break
    if flag:
        break
print(sum(A) + count)

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            break
            flag = True
        count += c-A[now]
        b -= 1
        now += 1
        if b <= 0:
            break
        if now >= N:
            break
    if flag:
        break
print(sum(A) + count)


Fixed submission:
from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            flag = True
            break
        count += c-A[now]
        b -= 1
        now += 1
        if now >= N:
            flag = True
            break
        if b <= 0:
            break
    if flag:
        break
print(sum(A) + count)
Buggy python submission (verdict: Runtime Error):
import math

def divisor(num):
    if num < 0:
        return 0
    if num == 1:
        return [1, ]

    divisor_list = [1, ]
    divisor_list_r = [num, ]

    i = 2
    while i * i <= num:
        if num % i == 0:
            divisor_list.append(i)
        i += 1

    return divisor_list

N = int(input())
divisor_list = divisor(N)
ans = 0
for i in divisor_list:
    tmp = (N - i) // i
    if i // tmp > 0:
        continue
    ans += tmp

print(ans)


Fixed submission:
import math

def divisor(num):
    if num < 0:
        return 0
    if num == 1:
        return [1, ]

    divisor_list = [1, ]
    divisor_list_r = [num, ]

    i = 2
    while i * i <= num:
        if num % i == 0:
            divisor_list.append(i)
        i += 1

    return divisor_list

N = int(input())
divisor_list = divisor(N)
ans = 0
for i in divisor_list:
    tmp = (N - i) // i
    if tmp == 0:
        continue
    if i // tmp > 0:
        continue
    ans += tmp

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())

area = [input() for _ in range(H)]

distance = [ [float('inf') for _ in range(W)] for _ in range(H)]
to_search = deque()
for i in range(H):
    for j in range(W):
        if area[i][j] == "#":
            to_search.appendleft((i, j, 0))
            distance[i][j] = 0
dist = [[1,0], [0,1], [-1,0], [0,-1]]
ans = 0
while len(to_search) > 0:
    nowi, nowj , nowd = to_search.pop()
    for di, dj in dist:
        nexti = nowi+di
        nextj = nowj+dj
        if 0<= nexti< H and 0<= nextj< W:
            if distance[nexti][nextj] > nowd+1:
                to_search.appendleft((nexti, nextj, nowd+1))
                distance[nexti][nextj] = nowd+1
                ans = max(ans, nowd+1)
print(ans)


Fixed submission:
from collections import deque
H, W = map(int, input().split())

area = [input() for _ in range(H)]

distance = [ [float('inf') for _ in range(W)] for _ in range(H)]
to_search = deque()
for i in range(H):
    for j in range(W):
        if area[i][j] == "#":
            to_search.appendleft((i, j, 0))
            distance[i][j] = 0
dist = [[1,0], [0,1], [-1,0], [0,-1]]
ans = 0
while len(to_search) > 0:
    nowi, nowj , nowd = to_search.pop()
    for di, dj in dist:
        nexti = nowi+di
        nextj = nowj+dj
        if 0<= nexti< H and 0<= nextj< W:
            if distance[nexti][nextj] > nowd+1:
                to_search.appendleft((nexti, nextj, nowd+1))
                distance[nexti][nextj] = nowd+1
                ans = max(ans, nowd+1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(' '))
H = list(map(int, input().split(' ')))

minimum_cost = [abs(H[i] - H[0]) for i in range(min(K+1, N))] \
               + [float('inf') for i in range(N-min(K+1, N))]

for i in range(2, N):
    for j in range(K+1):
        if i-j < 0:
            break
        temp = minimum_cost[i-j] + abs(H[i]-H[i-j])
        minimum_cost[i] = min(temp, minimum_cost[i])

print(minimum_cost[N-1])

Fixed submission:
import numpy as np

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

minimum_cost = np.zeros(N, dtype=int)
H = np.array(H)

for i in range(1, N):
    start = max(0, i-K)
    minimum_cost[i] = min(minimum_cost[start:i]
                          + np.abs(H[i] - H[start:i]))

print(minimum_cost[-1])

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

minimum_cost = [float('inf') for i in range(N)]
for i in range(min(K+1, N)):
    minimum_cost[i] = abs(H[i] - H[0])

for i in range(2, N):
    for j in range(K+1):
        if i-j < 0:
            break
        temp = minimum_cost[i-j] + abs(H[i]-H[i-j])
        minimum_cost[i] = min(temp, minimum_cost[i])

print(minimum_cost[N-1])


Fixed submission:
import numpy as np

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

minimum_cost = np.zeros(N, dtype=int)
H = np.array(H)

for i in range(1, N):
    start = max(0, i-K)
    minimum_cost[i] = min(minimum_cost[start:i]
                          + np.abs(H[i] - H[start:i]))

print(minimum_cost[-1])

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

minimum_cost = [float('inf') for i in range(N)]
for i in range(min(K+1, N)):
    minimum_cost[i] = abs(H[i] - H[0])
for i in range(1, N):
    for j in range(i, i+K+1):
        if j >= N:
            break
        temp = minimum_cost[i] + abs(H[j]-H[i])
        minimum_cost[j] = min(temp, minimum_cost[j])

print(minimum_cost[N-1])


Fixed submission:
import numpy as np

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

minimum_cost = np.zeros(N, dtype=int)
H = np.array(H)

for i in range(1, N):
    start = max(0, i-K)
    minimum_cost[i] = min(minimum_cost[start:i]
                          + np.abs(H[i] - H[start:i]))

print(minimum_cost[-1])
Buggy python submission (verdict: Runtime Error):
import math


def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


N, P = map(int, input().split(' '))
ans = 1
t = 2
while t**N <= P:
    t += 1
prime_nums = primes(t)
for a in prime_nums:
    if P % (a**N) == 0:
        temp = P // (a**N)
        count = 1
        while temp % (a**N) == 0:
            count += 1
            temp // (a**N)
        ans *= a**temp
    elif a**N > P:
        break
print(ans)


Fixed submission:
N = input()
count = 0
for i in range(len(N)):
    if N[i] == '2':
        count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = [list(map(int,input().split(' '))) for i in range(N)]
if (abs(X[0][0])+abs(X[0][1]))%2 == 0:
    flag = True
else:
    flag = False

flag2 = True
X_D = []
for i in range(len(X)):
    X_D.append(abs(X[i][0])+abs(X[i][1]))
    if flag:
        if X_D[i]%2 == 1:
            flag2 = False 
    else:
        if X_D[i]%2 == 0:
            flag2 = False

if not flag2:
    print('-1')
else:
    m = max(X_D)
    print(str(m))
    for i in range(m-1):
        print('1',end=' ')
    print('1')

    for i in range(N):
        ans = ''
        for x in range(abs(X[i][0])):
            if X[i][0]>=0:
                ans = ans + 'R'
            else:
                ans = ans + 'L'
        for y in range(abs(X[i][1])):
            if X[i][1]>=0:
                ans = ans+ 'U'
            else:
                ans = ans + 'D'

        flag3 = True
        for aaa in range(m - X_D[i]):
            if flag3:
                ans = ans + 'U'
                flag3 = False
            else:
                ans = ans + 'D'
                flag3 = True
        print(ans)

Fixed submission:
N = int(input())
XY = [list(map(int, input().split(" "))) for _ in range(N)]
parity = (XY[0][0] + XY[0][1]) % 2
maxXY = 0
for x, y in XY:
    if (x + y) % 2 != parity:
        print("-1")
        exit()
    maxXY = max(x+y, maxXY)
arm = [1, 1, ]
if parity == 1:
    arm[1] = 2

tmp = arm[1]
m = 2

for _ in range(40):
    tmp *= 2
    m += 1
    arm.append(tmp)
    if tmp > maxXY:
        break
print(m)
print(" ".join(map(str, arm)))
armR = arm[::-1]
for x, y in XY:
    nowX, nowY = [x, y]
    ansR = ""
    for l in armR:
        if abs(nowX) >= abs(nowY):
            if nowX >= 0:
                nowX -= l
                ansR += "R"
            else:
                nowX += l
                ansR += "L"
        else:
            if nowY >= 0:
                nowY -= l
                ansR += "U"
            else:
                nowY += l
                ansR += "D"
    print(ansR[::-1])
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N, X = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

A.append(X)
sortedA = sorted(A)
B = [sortedA[i+1] - sortedA[i] for i in range(len(sortedA)-1)]

ans = reduce(math.gcd, B)
print(ans)

Fixed submission:
from fractions import gcd
from functools import reduce

N, X = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

A.append(X)
sortedA = sorted(A)
B = [sortedA[i+1] - sortedA[i] for i in range(len(sortedA)-1)]

ans = reduce(gcd, B)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
flag = True
Cflag = False
for i, c in enumerate(S):
    if i == 0:
        if c == "A":
            continue
        else:
            flag = False
            break

    if c == "C" and i >= 2:
        if Cflag:
            flag = False
        cflag = True
    elif not (97 <= ord(c) <= 122):
        flag = False

if flag and cflag:
    print("AC")
else:
    print("WA")


Fixed submission:
S = input()
flag = True
cflag = False
for i, c in enumerate(S):
    if i == 0:
        if c == "A":
            continue
        else:
            flag = False
            break

    if c == "C" and 2 <= i < len(S)-1:
        if cflag:
            flag = False
        cflag = True

    elif not (97 <= ord(c) <= 122):
        flag = False


if flag and cflag:
    print("AC")
else:
    print("WA")
Buggy python submission (verdict: Runtime Error):
def calc_ABC(a, c, bq, aq):
    ans = 0
    if aq != 0:
        if bq != 0:
            ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \
                 * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))
        else:
            ans = ans + (a*pow(3, bq, MOD)) \
                 * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))
    else:
        if bq != 0:
            ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \
                 * (c*pow(3, aq, MOD))
        else:
            ans = ans + (a*pow(3, bq, MOD)) \
                 * (c*pow(3, aq, MOD))
    return ans % MOD


MOD = 10**9 + 7
S = raw_input()
ans = 0
count_a = 0
count_c = S.count('C')
count_afterq = S.count('?')
count_beforeq = 0

for i in range(len(S)):
    if S[i] == 'A':
        count_a += 1
    elif S[i] == 'B':
        ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)
        ans = ans % MOD
    elif S[i] == 'C':
        count_c -= 1
    elif S[i] == '?':
        count_afterq -= 1
        ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)
        ans = ans % MOD
        count_beforeq += 1
print(ans)


Fixed submission:
def calc_ABC(a, c, bq, aq):
    ans = 0
    if aq != 0:
        if bq != 0:
            ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \
                 * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))
        else:
            ans = ans + (a*pow(3, bq, MOD)) \
                 * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))
    else:
        if bq != 0:
            ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \
                 * (c*pow(3, aq, MOD))
        else:
            ans = ans + (a*pow(3, bq, MOD)) \
                 * (c*pow(3, aq, MOD))
    return ans % MOD


MOD = 10**9 + 7
S = input()
ans = 0
count_a = 0
count_c = S.count('C')
count_afterq = S.count('?')
count_beforeq = 0

for i in range(len(S)):
    if S[i] == 'A':
        count_a += 1
    elif S[i] == 'B':
        ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)
        ans = ans % MOD
    elif S[i] == 'C':
        count_c -= 1
    elif S[i] == '?':
        count_afterq -= 1
        ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)
        ans = ans % MOD
        count_beforeq += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
nums = list(map(int, input().split(" ")))
sigma = []
temp = 0
for num in nums:
    temp += num
    sigma.append(temp)

ans = 0
for i, s in enumerate(sigma):
    if s == 0:
        ans += 1
    beforeSums = sorted(sigma[:i])
    li = bisect.bisect_left(beforeSums, s)
    if li >= i:
        continue
    while beforeSums[li] == s:
        ans += 1
        li += 1
        if li >= i:
            break
print(ans)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split(" ")))
S = [0, ]
now = 0
for n in A:
    now += n
    S.append(now)
Scounter = Counter(S)
ans = 0
for c, n in Scounter.most_common():
    if n >= 2:
        ans += n*(n-1)//2
    else:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = list(map(int, input().split(" ")))
before = []
ans = 0
for n in nums:
    nextNums = []
    if n == 0:
        ans += 1
    nextNums.append(n)
    for bNum in before:
        if bNum + n == 0:
            ans += 1
        nextNums.append(bNum + n)
    before = nextNums
print(ans)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split(" ")))
S = [0, ]
now = 0
for n in A:
    now += n
    S.append(now)
Scounter = Counter(S)
ans = 0
for c, n in Scounter.most_common():
    if n >= 2:
        ans += n*(n-1)//2
    else:
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
N, H = map(int, input().split(' '))
a = []
b = []
for i in range(N):
    temp_a, temp_b = input().split(' ')
    a.append(int(temp_a))
    b.append(int(temp_b))
maxa = max(a)
c = [i for i in b if i > maxa]
sorted_b = sorted(b)[::-1]
i = 0
while(H > 0 and i != N):
    if maxa < sorted_b[i]:
        H -= sorted_b[i]
        i += 1
    else:
        break
left = 0
if H > 0:
    left = (H + maxa - 1) // maxa
print(i + left)


Fixed submission:
print('2018'+input()[4:])
Buggy python submission (verdict: Runtime Error):
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var inputLine string
	fmt.Scan(&inputLine)
	runeS := []rune(inputLine)
	var nums []int
	for _, c := range runeS {
		n, _ := strconv.Atoi(string(c))
		nums = append(nums, n)
	}

	var temp int
	var s string
	for i := 0; i < (1 << uint(len(nums)-1)); i++ {
		temp = nums[0]
		s = strconv.Itoa(nums[0])
		for j := 0; j < (len(nums) - 1); j++ {
			if (i>>uint(j))&1 == 1 {
				temp += nums[j+1]
				s += "+" + strconv.Itoa(nums[j+1])
			} else {
				temp -= nums[j+1]
				s += "-" + strconv.Itoa(nums[j+1])
			}
		}
		if temp == 7 {
			s += "=7"
			fmt.Println(s)
			break
		}
	}
}


Fixed submission:
S = input()

for i in range(1 << (len(S)-1)):
    temp = int(S[0])
    ans = str(S[0])
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 1:
            temp -= int(S[j+1])
            ans = ans + '-' + str(S[j+1])
        else:
            temp += int(S[j+1])
            ans = ans + '+' + str(S[j+1])
    if temp == 7:
        break
print(ans+'=7')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

sorted_a = sorted(a)
sorted_b = sorted(b)
sorted_c_r = sorted(c)[::-1]
ans = 0
for each_b in sorted_b:
    count_a = 0
    for each_a in sorted_a:
        if each_b > each_a:
            count_a += 1
        else:
            break
    count_c = 0
    for each_c in sorted_c_r:
        if each_c > each_b:
            count_c += 1
        else:
            break
    ans += count_a * count_c
print(ans)


Fixed submission:
N = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

sorted_a = sorted(a)
sorted_b = sorted(b)
sorted_c = sorted(c)
ans = 0
before_a = 0
before_c = 0
count_a = 0
count_c_rest = 0
for each_b in sorted_b:
    for ai in range(before_a, len(sorted_a)):
        if each_b > sorted_a[ai]:
            count_a += 1
            before_a += 1
        else:
            before_a = ai
            break

    for ci in range(before_c, len(sorted_c)):
        if sorted_c[ci] <= each_b:
            count_c_rest += 1
            before_c += 1
        else:
            before_c = ci
            break

    ans += count_a * (len(sorted_c)-count_c_rest)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
r_S = S[::-1]
r_T = T[::-1]
if T in S:
    q_ans = r_S
else:
    for i in range(len(r_S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if r_S[i+j] == '?':
                pass
            elif r_S[i+j] == r_T[j]:
                pass
            elif r_S[i+j] != r_T[j]:
                flag = False
                break
        if flag:
            q_ans = r_S[:i] + r_T + r_S[i+len(T):]
            break
    if not flag:
        print('UNRESTORABLE')
        exit()

q_ans = q_ans[::-1]
ans = ''
for i in q_ans:
    if i == '?':
        ans += 'a'
    else:
        ans += i
print(ans)


Fixed submission:
S = input()
T = input()
r_S = S[::-1]
r_T = T[::-1]
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
if T in S:
    q_ans = r_S
else:
    for i in range(len(r_S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if r_S[i+j] == '?':
                pass
            elif r_S[i+j] == r_T[j]:
                pass
            elif r_S[i+j] != r_T[j]:
                flag = False
                break
        if flag:
            q_ans = r_S[:i] + r_T + r_S[i+len(T):]
            break
    if not flag:
        print('UNRESTORABLE')
        exit()

q_ans = q_ans[::-1]
ans = ''
for i in q_ans:
    if i == '?':
        ans += 'a'
    else:
        ans += i
print(ans)