Problem:
 Score : 300 points    Problem Statement E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S' , which turns out to be the string S with some of its letters (possibly all or none) replaced with ? .  One more thing he found is a sheet of paper with the following facts written on it:   Condition 1: The string S contains a string T as a contiguous substring.  Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.   Print the string S . If such a string does not exist, print UNRESTORABLE .      Constraints  1 \leq |S'|, |T| \leq 50  S' consists of lowercase English letters and ? .  T consists of lowercase English letters.         Input Input is given from Standard Input in the following format:  S  T'       Output Print the string S . If such a string does not exist, print UNRESTORABLE instead.        Sample Input 1 ?tc????
coder      Sample Output 1 atcoder  There are 26 strings that satisfy Condition 1: atcoder , btcoder , ctcoder ,..., ztcoder .
Among them, the lexicographically smallest is atcoder , so we can say S = atcoder .       Sample Input 2 ??p??d??
abc      Sample Output 2 UNRESTORABLE  There is no string that satisfies Condition 1, so the string S does not exist.

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = input().rstrip()
    T = input().rstrip()
    slen = len(S)
    tlen = len(T)
    if slen < tlen:
        print('UNRESTORABLE')
        return 0

    changable_idx = None
    for i in range(slen-tlen+1):
        for idx,t in enumerate(T):
            if S[i+idx] != '?' and S[i+idx] != t:
                break
        else:
            changable_idx = i

    if changable_idx != None:
        S = S[:changable_idx] + T + S[changable_idx+tlen:]
        print(S.replace('?','a'))
    else:
        print('UNRESTORABLE')
        return 0

if __name__ == '__main__':
    main()

Solution (Python):
def matchtest(S,T):
    tlen = len(T)
    slen = len(S)

    ans = -1
    for i in range(slen-tlen,-1,-1):
        found = True
        for j in range(tlen):
            if S[i+j] == '?' or S[i+j] == T[j]:
                pass
            else:
                found = False
                break
        if found == True:
            ans = i
            break
    return ans

S = input()
T = input()

pos = matchtest(S,T)
if pos == -1:
    ans = 'UNRESTORABLE'
else:
    ans = ''
    for i in range(len(S)):
        if pos <= i and i < pos+len(T):
            ans += T[i-pos]
        else:
            if S[i] != '?':
                ans += S[i]
            else:
                ans += 'a'

print(ans)

Solution (Python):
S = input()
T = input()
L = len(S)
LL = len(T)

anslist = []
for i in range(L):
    if (S[i] == T[0] or S[i] == "?") and i+LL<=L:
        flag = 0
        for j in range(1,LL):
            if not(S[i+j] == T[j] or S[i+j] == "?"):
                flag = 1
        if flag == 0:
            anslist.append(i)

ans = "z"*51
LLL = len(anslist)
for i in range(LLL):
    j = anslist[i]
    tmp = ""
    for k in range(j):
        if S[k] == "?":
            tmp += "a"
        else:
            tmp += S[k]
    tmp += T
    for k in range(j+LL,L):
        if S[k] == "?":
            tmp += "a"
        else:
            tmp += S[k]
    if tmp < ans:
        ans = tmp
if ans == "z"*51:
    print("UNRESTORABLE")
else:
    print(ans)

Solution (Python):
S = input()
T = input()

for i in range(len(S)-len(T),-1,-1):
  flag = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      flag = False
  if flag:
    S = S[:i]+T+S[i+len(T):]
    S = S.replace('?','a')
    print(S)
    exit()

print('UNRESTORABLE')

Solution (Python):
import bisect


def main(S, T):
    for i in range(len(S)-len(T), -1, -1):
        flag = True
        for j in range(len(T)):
            if not (S[i+j] == '?' or S[i+j] == T[j]):
                flag = False
                break
        if flag:
            for k, c in enumerate(S):
                if i <= k <= i+j:
                    S[k] = T[k-i]
                elif S[k] == '?':
                    S[k] = 'a'
            return ''.join(S)
    return 'UNRESTORABLE'


if __name__ == '__main__':
    S = input()
    T = input()
    print(main(list(S), T))

Solution (Python):
def main():
    S = input()
    T = input()

    top = -1
    for head in range(len(S) - len(T)+1):
        for i in range(len(T)):
            if T[i] == S[head + i] or S[head + i] == "?":
                continue
            else:
                break
        else:
            top = head

    if top == -1:
        print("UNRESTORABLE")
    else:
        password = S[:top] + T + S[top + len(T):]
        password = password.replace("?", "a")
        print(password)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
from fractions import gcd





def lcm(a, b):
    return a * b // gcd(a, b)

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

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

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()
SL = len(S)
TL = len(T)


for i in range(SL - TL + 1):
    PS = S[i:TL + i]
    if PS == T:
        print(S.replace('?', 'a'))
        exit()

S = list(S)
SR = S[::-1]
O_SR = SR[:]
TR = T[::-1]

for i in range(0, SL - TL + 1):
    PSR = SR[i:TL + i:]
    equal = True
    for s, t in zip(PSR, TR):
        if s == t or s == '?':
            pass
        else:
            equal = False
            break
    if equal:
        for j, t in zip(range(i, TL + i), TR):
            SR[j] = t
        break

if SR == O_SR:
    print("UNRESTORABLE")
else:
    print(''.join(SR[::-1]).replace('?','a'))

Solution (Python):
s = input()
t = input()

import re

s = s.replace("?", ".")[::-1]
t = t[::-1]

for i in range(len(s) - len(t) + 1):
    if re.match(s[i:i+len(t)], t):
        ans = s[:i] + t + s[i+len(t):]
        ans = ans.replace(".", "a")[::-1]
        break

else:
    ans = "UNRESTORABLE"

print(ans)

Solution (Python):
sd = input()
t = input()

found = False
for i in range(len(sd) - len(t), -1, -1):
    for j in range(len(t)):
        if sd[i+j] != "?" and sd[i+j] != t[j]:
            break
    else:
        ans = sd[:i] + t + sd[i+len(t):]
        ans = ans.replace("?", "a")
        break
else:
    ans = "UNRESTORABLE"

print(ans)

Solution (Python):
def resolve():
    ss = input()
    t = input()

    Srev = ss[::-1]
    Trev = t[::-1]

    initial_T = -1

    for i in range(len(Srev) - len(Trev) + 1):
        flg = True
        for j in range(len(Trev)):
            if Srev[i + j] != Trev[j] and Srev[i + j] != '?':
                flg = False
                break

        if flg:
            initial_T = i
            break

    Srep = Srev[:initial_T] + Trev + Srev[initial_T + len(Trev):]
    ans = Srep.replace('?', 'a')[::-1]

    if initial_T == -1:
        print('UNRESTORABLE')
    else:
        print(ans)

resolve()

Solution (Python):
import re
S_ = input()
T = input()

Srev = "".join(reversed(S_))
Trev = "".join(reversed(T))

pattern = "".join(["[{}?]".format(t) for t in Trev])
ans = re.sub(pattern, Trev, Srev, count=1)
ans = "".join(reversed(ans.replace("?", "a")))
if ans.count(T):
    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):
S = input().strip()
T = input().strip()


for i in range(len(S)-len(T), -1, -1):
  flag = True
  for di in range(len(T)):
    if S[i+di] == '?' or S[i+di] == T[di]:
      continue
    else:
      flag = False
      break
  if flag:
    ans = [None]*len(S)
    for j in range(len(S)):
      if i <= j < i+len(T):
        ans[j] = T[j-i]
      elif S[j] == '?':
        ans[j] = 'a'
      else:
        ans[j] = S[j]
    print(*ans, sep='')
    exit()
print('UNRESTORABLE')

Solution (Python):
S_ = input()
T = input()


def check(S1, S2):
    for i in range(len(S1)):
        if S1[i] == S2[i] or S1[i] == "?":
            continue
        else:
            return(False)

    return(True)


ans_list = []
for i in reversed(range(len(S_) - len(T) + 1)):
    result = check(S_[i:i+len(T)], T)
    if result:
        ans = list(S_)
        for j in range(len(T)):
            ans[i+j] = T[j]
        for j in range(len(ans)):
            if ans[j] == "?":
                ans[j] = "a"
        ans_list.append("".join(ans))

if len(ans_list) == 0:
    print("UNRESTORABLE")
else:
    print(min(ans_list))

Solution (Python):
S_ = input()
T = input()
ans = list(S_)


def check(S1, S2):
    for i in range(len(S1)):
        if S1[i] == S2[i] or S1[i] == "?":
            continue
        else:
            return(False)

    return(True)


for i in reversed(range(len(S_) - len(T) + 1)):
    result = check(S_[i:i+len(T)], T)
    if result:
        for j in range(len(T)):
            ans[i+j] = T[j]
        for j in range(len(ans)):
            if ans[j] == "?":
                ans[j] = "a"
        print("".join(ans))

        exit(0)

print("UNRESTORABLE")

Solution (Python):
S,T=input(),input();l,m=len(S),len(T)
for i in range(l-m+1):
 if all(c in"?"+d for c,d in zip(S[-i-m:],T)):S=S.replace("?","a");print(S[:-i-m]+T+S[l-i:]);quit()
print("UNRESTORABLE")

Solution (Python):
def chk(a,b):
	if len(a)!=len(b):
		return False
	for i in range(len(a)):
		if a[i]!=b[i] and a[i]!='?' and b[i]!='?':
			return False
	return True

s=list(input())
t=list(input())
ans=[]

l=len(s)-len(t)+1
for i in range(l):
	if chk(s[i:i+len(t)],t):
		ans.append((''.join(s[:i]+t+s[i+len(t):])).replace('?','a'))
if ans==[]:
	print('UNRESTORABLE')
else:
	print(min(ans))

Solution (Python):


def main(S_,T):
    for i in range(len(S_)-len(T)+1):
        for j in range(len(T)):
            if S_[i+j]!="?" and T[j]!=S_[i+j]:break
        else:
            print(''.join(list(reversed((S_[:i]+T+S_[i+j+1:]).replace("?","a")))))
            exit()
    print("UNRESTORABLE")

if __name__ == '__main__':
    S_ = "".join(list(reversed(input())))
    T = "".join(list(reversed(input())))
    main(S_,T)

Solution (Python):
S = input()
T = input()
N = len(S)
M = len(T)

judge = False
for i in range(N-M+1):
    c = N-M-i
    for j,t in enumerate(T):
        if c > N-1:
            break
        if t == S[c] or S[c] == "?":
            c += 1
            if j == M-1:
                judge = True
        else:
            break
    if judge:
        S= S[:N-M-i]+T+S[N-i:]
        break

if judge:
    for i in range(N):
        print(S[i] if S[i] != "?" else "a",end="")
else:
    print("UNRESTORABLE")

Solution (Python):
import copy

S = list(input())
T = list(input())
candidate = []
if len(T) > len(S):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T) + 1):
    c = 0
    A = copy.copy(S)
    check = False
    for j in range(len(T)):
        if A[i + j] == T[j]:
            c += 1
        elif A[i + j] == "?":
            A[i + j] = T[j]
            c += 1
        else:
            break
        if c == len(T):
            candidate = A
print("".join(candidate).replace("?", "a") if candidate else "UNRESTORABLE")

Solution (Python):
def solve():
    s = input()
    t = input()
    ls = len(s)
    lt = len(t)
    for i in range(ls - lt + 1)[::-1]:
        if all([si == ti or si == "?" for si, ti in zip(s[i:i + lt], t)]):
            return (s[:i] + t + s[i + lt:]).replace("?", "a")
    return "UNRESTORABLE"


def resolve():
    print(solve())


if __name__ == "__main__":
    resolve()

Solution (Python):
S = input().strip()
T = input().strip()

ls = len(S)
lt = len(T)

if ls < lt:
    print('UNRESTORABLE')
    exit()

for i in reversed(range(ls - lt + 1)):
    match = True
    for s, t in zip(S[i:lt + i], T):
        if s != t and s != '?':
            match = False
            break
    if match:
        ans = ''
        ans += S[:i]
        ans += T
        ans += S[i+lt:]
        print(ans.replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Solution (Python):
import sys
S=''.join(list(reversed(input())))
T=''.join(list(reversed(input())))
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j]!="?" and T[j]!=S[i+j]:break
    else:
        print(''.join(list(reversed((S[:i]+T+S[i+j+1:]).replace("?","a")))))
        sys.exit()
print("UNRESTORABLE")

Solution (Python):
S=''.join(list(reversed(input())))
T=''.join(list(reversed(input())))
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j]!="?" and T[j]!=S[i+j]:break
    else:
        print(''.join(list(reversed((S[:i]+T+S[i+j+1:]).replace("?","a")))))
        exit()
print("UNRESTORABLE")

Solution (Python):
s = input()[::-1]
t = input()[::-1]
idx = -1
for si in range(len(s)):
    if si + len(t) > len(s): break

    find = True
    for ti in range(len(t)):
        if s[si + ti] != '?' and s[si + ti] != t[ti]:
            find = False
            break
    if find:
        idx = si
        break

if idx < 0:
    print('UNRESTORABLE')
    exit()

p1 = s[:idx] if idx > 0 else ''
p2 = s[idx + len(t):]
print((p1 + t + p2).replace('?', 'a')[::-1])

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    s = input().strip()
    t = input().strip()
    ans = []
    for i in range(len(s) - len(t) + 1):
        ok = True
        
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == "?":
                pass
            else:
                ok = False
                break
        if ok:
            ans.append((s[:i] + t + s[i+len(t):]).replace("?", "a"))
    if len(ans) > 0:
        print(min(ans))
    else:
        print("UNRESTORABLE")



if __name__ == "__main__":
    main()

Solution (Python):
S=''.join(list(reversed(input())))
T=''.join(list(reversed(input())))
for i in range(len(S)-len(T)+1):
  for j in range(len(T)):
    if S[i+j]!="?" and T[j]!=S[i+j]:break
  else:
    print(''.join(list(reversed((S[:i]+T+S[i+j+1:]).replace("?","a")))))
    exit()
print("UNRESTORABLE")

Solution (Python):
s = input()
t = input()
li = []

if t in s:
    if "?" in s:
        print(s.replace("?", "a"))
        exit()
    else:
        print(s)
        exit()

for i in range(len(s) - len(t) + 1):
    target = s[i:i+len(t)]
    flag = True
    for j in range(len(t)):
        if target[j] != "?" and target[j] != t[j]:
            flag = False
    if flag:
        li.append(s[:i] + t + s[i+len(t):])

if len(li) == 0:
    print("UNRESTORABLE")
    exit()

li = sorted(li)
print(li[0].replace("?", "a"))

Solution (Python):

S_prime = str(input())
T = str(input())
ans = []

if len(S_prime) >= len(T):
    times = len(S_prime) - len(T) + 1
    for i in range(times):
        count = 0
        for j in range(len(T)):
            if S_prime[i+j] == '?':
                count = count + 1
            elif S_prime[i+j] != T[j]:
                continue
            else:
                count = count + 1
            
        if count == len(T):
            S = S_prime[:i] + T + S_prime[(i+len(T)):]
            S = S.replace('?', 'a')
            ans.append(S)


if len(ans) != 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

Solution (Python):
def main():
    s = input()
    t = input()
    s_len = len(s)
    t_len = len(t)
    def t_check(t_true,t_can):
            for tt,tc in zip(t_true,t_can):
                if tc != '?' and tt != tc:
                    return False
            else:
                return True

    if s_len < t_len:
        print('UNRESTORABLE')
    elif s_len == t_len:
        if t_check(t,s):
            print(t)
        else:
            print('UNRESTORABLE')
    else:
        ans = ""
        for i in range(s_len - t_len + 1)[::-1]:
            if t_check(t,s[i:i+t_len]):
                ans = s[:i] + t + s[i+t_len:]
                ans = ans.replace('?','a')
                print(ans)
                break
        else:
            print('UNRESTORABLE')
if __name__ == "__main__":
    main()

Solution (Python):
SS = input()
T = input()
ans = "z"*(len(SS)+1)

for i in range(len(SS) - len(T) + 1):
	temp = "?"*i + T + "?"*(len(SS)-i-len(T))
	cond = True
	for i in range(len(SS)):
		if SS[i] == "?" or temp[i] == "?":
			continue
		else:
			if SS[i] != temp[i]:
				cond = False
	if cond:
		temp_2 = []
		for i in range(len(SS)):
			if SS[i] == "?" and temp[i] == "?":
				temp_2.append("a")
			elif SS[i] == "?" and temp[i] != "?":
				temp_2.append(temp[i])
			else:
				temp_2.append(SS[i])
		temp_3 = "".join(temp_2)
		if temp_3 <= ans:
			ans = temp_3

if ans == "z"*(len(SS)+1):
	print("UNRESTORABLE")
else:
	print(ans)

Solution (Python):
s_dash = input()
t = input()

ans = []
for i in range(len(s_dash) - len(t) + 1):
    candidate = []
    for j in range(i):
        candidate.append('a' if s_dash[j] == '?' else s_dash[j])
    found = True
    for j in range(len(t)):
        if s_dash[i + j] == '?' or t[j] == s_dash[i + j]:
            candidate.append(t[j])
        else:
            found = False
            break
    if found:
        for j in range(len(t) + i, len(s_dash)):
            candidate.append('a' if s_dash[j] == '?' else s_dash[j])
        ans.append("".join(candidate))
if 0 == len(ans):
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])

Solution (Python):
s = list(input())
t = list(input())
ans_bag = []
possible_ans_bag = []
flag = False
for i in range(len(s)-len(t)+1):
  ans = []
  check = True
  for j in range(len(t)):
    if j == 0:
      for k in range(i):
        ans += s[k]
    if s[i+j] == '?':
      ans += [t[j]]
    elif s[i+j] != t[j]:
      ans += [s[i+j]]
      check = False
      break
    else:
      ans += [s[i+j]]
  if len(t) <= i+len(t) and check:
    for k in range(i+len(t), len(s)):
      ans += [s[k]]
  if len(ans) == len(s) and check:
    ans_bag += [ans]
    flag = True
    
if flag:
  for possible_ans in ans_bag:
    for i in range(len(s)):
      if possible_ans[i] == '?':
        possible_ans[i] = 'a'
    possible_ans_bag += [possible_ans]

  print(''.join(sorted(possible_ans_bag)[0]))
else:
  print('UNRESTORABLE')

Solution (Python):
s_d = input()
t = input()
if len(s_d) >= len(t):
    for i in range(len(s_d) - len(t), -1, -1):
        possible = True
        for j in range(len(t)):
            if s_d[i + j] == t[j] or s_d[i + j] == "?":
                continue
            else:
                possible = False
                break
        if possible == False:
            continue
        else:
            s = s_d[:i] + t + s_d[i+len(t):]
            for k in range(len(s)):
                if s[k] == "?":
                    s = s[:k] + "a" + s[k+1:]
            break
else:
    possible = False
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Solution (Python):
import copy

S=list(input())
T=list(input())



flag = False

for i in range(len(S)+1-len(T)):
    if S[i]==T[0] or S[i]=="?":
        
        for j in range(len(T)):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                
                break
        else:
            result=copy.copy(S)
            for j in range(len(T)):
                flag=True
                result[i+j]=T[j]
                


if flag==True:
    print("".join(result).replace("?","a"))
else:
    print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
s_list = []
for i in range(len(S)):
    if i+len(T) > len(S):
        break
    j=0
    for _ in range(len(T)):
        if S[i+j] == '?' or S[i+j] == T[j]:
            j+=1
            continue
        break
    if j==len(T):
        s_list.append(S[:i] + T + S[i+len(T):])
if len(s_list) > 0:
    s_list.sort()
    print(s_list[0].replace('?', 'a'))
else:
    print("UNRESTORABLE")

Solution (Python):
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ss = []
for i in range(0, len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] not in ('?', t[j]):
            break
    else:
        c = s[:i] + t + s[i+len(t):]
        ss.append(c.replace('?', 'a'))
if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')

Solution (Python):
import collections 
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

s = list(input())
t = list(input())
ans = []

for i in range(len(s)-len(t)+1)[::-1]:
    bb = True
    for j in range(len(t)):
        if s[i+j] == '?':
            continue
        else:
            if s[i+j] != t[j]:
                bb = False
    if bb == True:
        ss = s[:]
        for _ in range(len(s)):
            if _ < i:
                if ss[_] == '?':
                    ss[_] = 'a'
            elif _ < i + len(t):
                ss[_] = t[_-i]
            else:
                if ss[_] == '?':
                    ss[_] = 'a'
        ans.append(''.join(ss))

if ans == []:
    print('UNRESTORABLE')
else:
    ans.sort
    print(ans[0])

Solution (Python):
import os
S = input()
T = input()

T_idx = 0
def can_apply(s, t):
    for i in range(len(t)):
        if s[i] == t[i] or s[i] == '?':
            continue
        else:
            return False
    return True

start_idx = -1
for i in range(len(S)-len(T)+1):
    if can_apply(S[i:i + len(T)], T):
        start_idx = i

if start_idx < 0:
    print("UNRESTORABLE")
    os.sys.exit()
ans = [S[i] for i in range(len(S))]
for i in range(len(T)):
    if ans[start_idx + i] == '?':
        ans[start_idx + i] = T[i]

for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'

ans_str = ""
for _a in ans:
    ans_str += _a
print(ans_str)

Solution (Python):
ss = input()
tt = input()
ans = ''
for i in range(len(ss)-len(tt)+1):
    flag = True
    for s,t in zip(ss[i:],tt):
        if s != '?' and s != t:
            flag = False
            break
    if flag:
        ans = ss[:i] + tt + ss[i+len(tt):]

if ans !='':
    print(ans.replace('?','a'))
else:
    print('UNRESTORABLE')

Solution (Python):
s_ = input()
t = input()

exit_flag = True
for i in range(len(s_) - len(t) + 1):
    flag = True
    for j in range(len(t)):
        if (s_[i+j] != '?') and (s_[i+j] != t[j]):
            flag = False
    
    if flag:
        h = ''
        for index in range(len(s_)):
            if (i <= index <= i + len(t) -1):
                h += t[index - i]
            else:
                h += s_[index]
        exit_flag = False

if exit_flag:
    print('UNRESTORABLE')
    exit()

h = h.replace('?', 'a')
print(h)

Solution (Python):
S = input()
T = input()

ans = ""
for i in range(len(S)-len(T)+1):
    flag = True
    for s,t in zip(S[i:],T):
        if s != "?" and s != t:
            flag = False
            break
    if flag:
        ans = S[:i]+T+S[i+len(T):]
if ans != "":
    print(ans.replace("?","a"))
else:
    print("UNRESTORABLE")

Solution (Python):
S = [i for i in input()]
T = [i for i in input()]
size_s = len(S)
size_t = len(T)
kouho = []
if size_t > size_s :
    print("UNRESTORABLE")
else :
    for i in range(size_s-size_t+1):
        p = [i for i in S]
        for j in range(size_t):
            if S[i+j] == T[j] or S[i+j] == "?" :
                continue   
            else :
                break 
        else :
            for j in range(size_s):
                if S[j] == "?" :
                    p[j] = "a"
            for j in range(size_t):
                p[i+j] = T[j]
            kouho.append("".join(p))

    if len(kouho) == 0 :
        print("UNRESTORABLE")
    else:
        kouho.sort()
        print(kouho[0],end = " ")

Solution (Python):
s = input()
t = input()
lt = len(t)
ls = len(s)
li = []
if ls < lt:
    ans = "UNRESTORABLE"
else:
    for i in range(ls-lt+1):
        subs = s[i:i+lt]
        for c,d in zip(subs,t):
            if c == d or c == "?":
                continue
            else:
                break
        else:
            li.append((s[0:i]+t+s[i+lt:]).replace("?","a"))
    li.sort()
    ans = li[0] if li else "UNRESTORABLE"
print(ans)

Solution (Python):
s = input()
t = input()

ans = ['?' for i in range(len(s))]
start_pos = 0
cond = False
count = 0

if len(s) < len(t):
    print('UNRESTORABLE')
else:
    for i in range(len(s) - len(t) + 1):
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == "?":
                count += 1
        if count == len(t):
            start_pos = i
            cond = True
        count = 0
    if cond:
        ans = list(s)
        for k in range(len(t)):
            ans[start_pos+k] = t[k]
        ans = "".join(ans)
        ans = ans.replace("?", "a")
        print(ans)
    else:
        print('UNRESTORABLE')

Solution (Python):
S2 = input()
T = input()
for i in reversed(range(0, len(S2)-len(T)+1)):
  s = S2[i:i+len(T)]
  
  ok = True
  for j in range(len(T)):
    if not(s[j] == "?" or s[j] == T[j]):
      ok = False
  if ok:
    S = S2[:i] + T + S2[i+len(T):]
    S = S.replace("?", "a")
    print(S)
    exit()
print("UNRESTORABLE")

Solution (Python):
S=input()
T=input()
l=len(T)

pos=[]
for i in range(len(S)-l+1):
    s_tmp=S[i:i+l]
    for s,t in zip(s_tmp, T):
        if s==t or s=="?":
            continue
        else:
            break
    else:
        pos.append(i)

if pos:
    p=pos[-1]
    S=S[:p]+T+S[p+l:]
    ans=""
    for s in S:
        if s=="?":
            ans+="a"
        else:
            ans+=s
    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):
s = input()
t = input()

flag = False
idx = 0

for i in range(len(s)-len(t)+1):
    if flag == True:
        break
    for j in range(len(t)):
        if s[len(s)-1-i-j] == '?' or s[len(s)-1-i-j] == t[len(t)-1-j] :
            if j == len(t)-1:
                flag = True
                idx = i
                break
        else:
            break
        
if flag == False:
    print('UNRESTORABLE')
    exit()
    
ans = []
num = 0

idx = len(s)-1-idx-len(t)+1
S1 = s[:idx] + t + s[idx+len(t):]
S1 = S1.replace('?', 'a')
print(S1)

Solution (Python):
s = input()
t = input()

flag = False
idx = 0

for i in range(len(s)-len(t)+1):
    if flag == True:
        break
    for j in range(len(t)):
        if s[len(s)-1-i-j] == '?' or s[len(s)-1-i-j] == t[len(t)-1-j] :
            if j == len(t)-1:
                flag = True
                idx = i
                break
        else:
            break
        
if flag == False:
    print('UNRESTORABLE')
    exit()
    
ans = []
num = 0

for i in range(len(s)):
    if len(s)-1-idx >= i and len(s)-1-idx-len(t)+1 <= i:
        ans.append(t[num])
        num += 1
        
    elif s[i] == '?':
        ans.append('a')
    else:
        ans.append(s[i])

print(*ans,sep='')

Solution (Python):
S = input()
T = input()
l = []
for i in range(len(S)-len(T)+1):
    flag = 0
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != "?":
            flag = 1
    if flag == 0:
        S1 = S[:i]+T+S[i+len(T):]
        S2 = S1.replace("?","a")
        l.append(S2)
print(sorted(l)[0] if len(l) > 0 else "UNRESTORABLE")

Solution (Python):
S = list(input())
T = list(input())

last = -1
for i in range(len(S)-len(T) + 1) :
    for j in range(len(T)) :
        if S[i+j] != T[j] and S[i+j] != '?' :
            break
    else :
        last = i

if last == -1 :
    print('UNRESTORABLE')
else :
    S[last:last+len(T)] = T[::]
    print(''.join(S).replace('?', 'a'))

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

S = list(input())
T = list(input())

for i in range(len(S)-len(T), -1 ,-1):
	judge = 1
	for j in range(len(T)):
		if S[i + j] != T[j] and S[i + j] != '?':
			judge = 0
			break
	if judge == 1:
		S[i:i+len(T)] = T[0:len(T)]
		for j in range(len(S)):
			if S[j] == '?':
				S[j] = 'a'
		print("".join(S))
		exit()

print("UNRESTORABLE")

Solution (Python):
def main():
    S = input()
    T = input()
    ns, nt = len(S), len(T)
    if nt > ns: return "UNRESTORABLE"
    cand = []
    for i in range(ns-nt+1):
        isFound = True
        for j in range(nt):
            if S[i+j] != "?" and S[i+j] != T[j]:
                isFound = False
                break
        if isFound:
            cand.append(S[:i] + T + S[i+nt:])
    if len(cand) == 0:
        return "UNRESTORABLE"
    else:
        filled = []
        for s in cand:
            t = ""
            for c in s:
                t += "a" if c == "?" else c
            filled.append(t)
        filled = sorted(filled)
        return filled[0]


if __name__ == '__main__':
    print(main())

Solution (Python):
S = input()
T = input()

ans = []

for i in range(len(S) + 1 - len(T)):
	if S[i] == T[0] or S[i] == '?':
		s = ''
		flag = True
		
		for j in range(i):
			if S[j] == '?':
				s += 'a'
			else:
				s += S[j]
		
		for j in range(i, i + len(T)):
			if S[j] == T[j - i] or S[j] == '?':
				s += T[j - i]
			else:
				flag = False
				break
		
		if flag:
			for j in range(i + len(T), len(S)):
				if S[j] == '?':
					s += 'a'
				else:
					s += S[j]
			ans.append(s)

if len(ans) > 0:
	ans.sort()
	print(ans[0])
else:
	print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
Sa = S.replace('?', 'a')

def match(N):
  St = S[N:N + len(T)]
  for st, t in zip(St, T):
    if st == '?':
      continue
    elif t != st:
      return False
  return True

point = -1
for i in range(len(S) - len(T) + 1):
  if match(i):
    point = i
    
if point != -1:
  print(Sa[:point] + T + Sa[point + len(T):])

else:
  print('UNRESTORABLE')

Solution (Python):
S=input()
T=input()
for i in range(len(S)-len(T),-1,-1):
    for j in range(len(T)):
        if S[i+j]!=T[j] and S[i+j]!="?":
            break
    else:
        s=""
        for j in range(i):
            if S[j]=="?":
                s+="a"
            else:
                s+=S[j]
        for j in range(len(T)):
            s+=T[j]
        for j in range(i+len(T),len(S)):
            if S[j]=="?":
                s+="a"
            else:
                s+=S[j]
        break
else:
    s="UNRESTORABLE"
print(s)

Solution (Python):
s = str(input())
s = s[::-1]
t = str(input())
t = t[::-1]

found = False
for i in range(len(s) - len(t) + 1):
    ok = True
    for j in range(len(t)):
        if s[i + j] != "?" and s[i + j] != t[j]:
            ok = False
            break
    if ok:
        found = True
        s = s[:i] + t + s[i + len(t):]
        break

s = s[::-1]
if found:
    print(s.replace("?", "a"))
else:
    print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()

N = len(S)
M = len(T)

i_a = 0
for i in reversed(range(N-M+1)):
    ans = 0
    for j in range(M+1):
        if j == M:
            print((S[:i]+T+S[i+M:]).replace('?','a'))
            exit()
        if T[j] == S[i+j] or S[i+j] == '?':
            continue
        else:
            break

print('UNRESTORABLE')