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):
SD=list(input())
T=list(input())

for i in reversed(range(len(SD)-len(T)+1)):
  
  for j in range(len(T)):    
    if SD[i+j]!="?" and SD[i+j]!=T[j]:
      break
  else:
    for j in range(len(T)):
      if SD[i+j]=="?":
        SD[i+j]=T[j]
    for j in range(len(SD)):
      if SD[j]=="?":
        SD[j]="a"
    print("".join(SD))
    break
else:
  print("UNRESTORABLE")

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

found_s = False
for i in range(len(s) - len(t), -1, -1):
    for c1, c2 in zip(s[i:i+len(t)], t):
        if c1 == '?' or c1 == c2:
            continue
        else:
            break
    else:
        found_s = True
        s = s[:i] + t + s[i+len(t):]
        break

if found_s:
    print(s.replace('?', 'a'))
else:
    print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
lt=len(t)
ls=len(s)


if lt>ls:
    print("UNRESTORABLE")
else:
    
    
    ans=[]
    for i in range(ls-lt+1):
        flag=True
        for j in range(lt):
            if s[i+j]!="?" and s[i+j]!=t[j]:
                flag=False
                break                
        if flag: 
            tmp=s[:i]+t+s[i+lt:]
            tmp=tmp.replace("?", "a")
            ans.append(tmp)
            
      
    if ans:
        an=sorted(ans)
        print(an[0])
       
    else:
        print("UNRESTORABLE")

Solution (Python):
s_dash_rev = input()[::-1]
t_rev = input()[::-1]
s_length = len(s_dash_rev)
t_length = len(t_rev)
matched = False
for begin_index in range(s_length - t_length + 1):
    end_index = begin_index + t_length
    part_s_dash_rev = s_dash_rev[begin_index:end_index]
    part_matched = True
    for i in range(t_length):
        if part_s_dash_rev[i] != '?' and part_s_dash_rev[i] != t_rev[i]:
            part_matched = False
            break
    if part_matched:
        
        matched = True
        s_rev = s_dash_rev[:begin_index] + t_rev + s_dash_rev[end_index:]
        break
if not matched:
    print('UNRESTORABLE')
else:
    s = s_rev[::-1]
    print(s.replace('?', 'a'))

Solution (Python):
A = list(input())
B = list(input())
for i in reversed(range(len(A)-len(B)+1)):
    for j in reversed(range(len(B))):
        if A[j+i] == B[j] or A[j+i] == "?":
            pass
        else:
            j +=1
            break
    if j == 0:
        A[i:i+len(B)] = B
        A = "".join(A)
        A = A.replace("?","a")
        print(A)
        exit()
print("UNRESTORABLE")

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    s = list(input())
    t = list(input())
    n = len(s)
    m = len(t)
    ans = ''
    for i in range(n - m,-1,-1):
        flag = True
        for j in range(m):
            if s[i + j] != t[j] and s[i + j] != '?':
                flag = False
                break
        if flag:
            ans = s[:i] + t + s[i + m:]
            break
    if ans:
        for i in range(n):
            if ans[i] == '?':
                ans[i] = 'a'
        print(''.join(ans))
    else:
        print('UNRESTORABLE')
if __name__ == '__main__':
    main()

Solution (Python):
s = input()
t = input()
len_s = len(s)
len_t = len(t)

ans_ls = []
for start in range(len_s - len_t + 1):
    Pass = True
    for i in range(len_t):
        if s[start+i] != '?':
            if s[start+i] != t[i]:
                Pass = False
    if Pass:
        including = s[:start] + t + s[start + len_t:]
        replaced = including.replace('?', 'a')
        ans_ls.append(replaced)
ans_ls.sort()
if ans_ls:  
    print(ans_ls[0])
else:
    print('UNRESTORABLE')

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

n = len(sd)
m = len(t)

for i in reversed(range(n - m + 1)):
    t_kamo = sd[i:i+m]
    for j in range(len(t)):
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] == t[j]:
            continue
        else:
            break
    else:
        ans = (sd[:i] + t + sd[i+m:]).replace("?", "a")
        print(ans)
        exit()

print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
ns=len(s)
nt=len(t)
if t in s:
      print(s.replace('?','a'))
      exit()
ans=''
for i in range(ns-nt,-1,-1):
      flg=True
      for j in range(nt):
            if s[i+j]!='?' and s[i+j]!=t[j]:
                  flg=False
      if flg:
            ans=s[:i]+t+s[i+nt:]
            ans=ans.replace('?','a')
            break

print(ans if ans!='' else 'UNRESTORABLE')

Solution (Python):
S = input()[::-1]
T = input()[::-1]
n = len(S);m = len(T)
a = []
for i in range(0, n - m + 1):
    f = 1
    s = S[i:i+m]
    for j in range(m):
        if s[j] not in ["?",T[j]]:
            f = 0
            break
    if f:
        a = S[:i] + T + S[i+m:]
        break

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

Solution (Python):

s = input()
t = input()

ans = []
for i in range(1, len(s) + 1):
    l = s[:i - 1]
    r = s[i + len(t) - 1:]
    temp = l + t + r
    if len(temp) == len(s):
        for i in range(len(s)):
            if s[i] == '?' or s[i] == temp[i]:
                continue
            else:
                break
        else:
            ans.append(temp)
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    ans.sort()
    a = ans[0]
    a = a.replace('?', 'a')
    print(a)

Solution (Python):
s=input()
t=input()
ans="UNRESTORABLE"
for i in range(len(s)-len(t),-1,-1):
    ss=s[i:i+len(t)]
    flag=0
    for j in range(len(t)):
        if ss[j]=="?":
            ss=ss[0:j]+t[j]+ss[j+1:]
        if ss[j]!=t[j]:
            flag=1
            break
    if flag==0:
        ans=s[0:i].replace("?","a")+ss+s[i+len(t):].replace("?","a")
        break
print(ans)

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

st = []

for i,c in enumerate(s):
    if i + len(t) > len(s):
        break
    if c == t[0] or c == '?':
        isok = True
        for j, c2 in enumerate(t):
            if s[i+j] == c2 or s[i+j] == '?':
                continue
            else:
                isok = False
        if isok:
            st.append((s[:i] + t + s[i+len(t):]).replace('?', 'a'))
st.sort()
print('UNRESTORABLE' if len(st)==0 else st[0])

Solution (Python):
S = input()
T = input()
Ns = len(S)
Nt = len(T)
if Ns<Nt:
   print("UNRESTORABLE")
else:
   S_merge=""
   isok = True
   for i in range(Ns-Nt,-1,-1):
      isok = True
      
      for j in range(Nt):
         if not (S[i+j] == T[j] or S[i+j]=="?"):
            isok = False
            break
      if isok:
         
         S_merge = S[:i]+T+S[i+Nt:]
         
         
         break
   if not isok:
      print("UNRESTORABLE")
   else:
      
      S_ans =""
      for i in range(Ns):
         if S_merge[i]=="?":
            S_ans = S_ans+'a'
         else:
            S_ans = S_ans+S_merge[i]
      print(S_ans)

Solution (Python):
import sys
S=input()
T=input()
sl=len(S)
tl=len(T)
init=(['z']*sl)
init=''.join(init)
ans=init
for i in range(sl-tl+1):
    st=S[i:i+tl]
    flag=False
    for j in range(tl):
        if st[j]==T[j] or st[j]=='?':
            flag=True
        else:
            flag=False
            break
    if flag:
        anst=list(S)
        anst[i:i+tl]=T[:]
        anst=''.join(anst)
        anst=anst.replace('?','a')
        if anst<ans:
            ans=anst
if ans == init:
    print('UNRESTORABLE')
else:   
    print(ans)

Solution (Python):
s = input()
t = input()
tlen = len(t)
anslist = []
n = len(s)
'''
当てはまる文字列を全列挙してソート
'''
def mojiretu(a):
    global anslist
    a = list(a)
    for i in range(len(a)):
        if a[i] == '?':
            a[i] = 'a'
    anslist.append(''.join(a))

def hantei(ss):
    for i in range(len(ss)):
        if ss[i] != t[i] and ss[i] != '?':
            return False
    else:return True

for i in range(n+1-tlen):
    if s[i] == t[0] or s[i] == '?':
        if hantei(s[i:i+tlen]):
            mojiretu(s[:i] + t + s[i+tlen:])
anslist.sort()
if anslist:
    print(anslist[0])
else:
    print('UNRESTORABLE')

Solution (Python):
def resolve():
    ss = input()
    t = input()
    ans = 'UNRESTORABLE'

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

        if flg:
            ans = ss[:i] + t + ss[i + len(t):]
            ans = ans.replace('?', 'a')
            break

    print(ans)
    
resolve()

Solution (Python):
def resolve():

    
    
    ss = input()[::-1]
    t = input()[::-1]

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

        if flg:
            ans = ss[:i] + t + ss[i + len(t):]
            ans = ans.replace('?', 'a')[::-1]
            break

    print(ans)
    
resolve()

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















lens=len(sd)
lent=len(t)
yn="NG"
for i in range(lens-lent,-1,-1):
    yn=""
    for ii in range(lent):
        if sd[i+ii]==t[ii] or sd[i+ii]=="?":
            continue
        else:
            yn="NG"
            break
    if yn!="NG":
        yn="itchi"
        break
    
if yn=="NG":
    print("UNRESTORABLE")
else:
    s=""
    if i!=0:
        for ii in range(i):
            if sd[ii]=="?":
                si="a"
            else:
                si=sd[ii]
            s=s+si
    for ti in t:
        s=s+ti
    if i!=lens-lent:
        for ii in range(i+lent,lens,1):
            if sd[ii]=="?":
                si="a"
            else:
                si=sd[ii]
            s=s+si
    print(s)

Solution (Python):
import copy
s = input()
t = input()
for i in range(len(s)-len(t)+1):
  s1 = copy.deepcopy(s[len(s)-len(t)-i:len(s)-i])
  for j in range(len(t)):
    if t[j]==s1[j]:
      continue
    elif s1[j]=="?":
      s2 = list(s1)
      s2[j]=t[j]
      s1 = "".join(s2)
    else:
      break
  else:
    s3 = s[:len(s)-len(t)-i].replace("?","a")+s1+s[len(s)-i:].replace("?","a")
    print(s3)
    exit()
print("UNRESTORABLE")

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

startpoint=51

for i in range(len(sd)-len(t)+1):
	proflag=True
	
	for j in range(len(t)):
		if sd[i+j] == "?":
			continue
		elif sd[i+j] == t[j]:
			continue
		else:
			proflag=False
	if proflag:
		startpoint=i
		



if startpoint == 51:
	print("UNRESTORABLE")
else:
	sd=sd.replace('?','a')
	print(sd[:startpoint]+t+sd[startpoint+len(t):])

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

ans = [None for i in range(len(s))]
for i in range(len(s)):
    ans[i] = s[i]

for i in reversed(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:
        for j in range(len(t)):
            ans[i+j]=t[j]
        for j in range(len(s)):
            if ans[j]=="?":
                ans[j]="a"
        print("".join(ans))
        exit()

print("UNRESTORABLE")

Solution (Python):
Sd = str(input())
T = str(input())

NS = len(Sd)
NT = len(T)

if NS < NT:
  print("UNRESTORABLE")
else:
  flag = False
  for i in range(NS-NT+1):
    for j in range(NT):
      if Sd[i+j] != "?" and Sd[i+j] != T[j]:
        break
      if j == NT-1:
        flag = True
        if "change" not in locals():
          change = i 
        else:
          change = max(change,i) 
  if flag:
    if "change" in locals():
      ans = Sd[:change]+T+Sd[change+NT:]
    else:
      ans = Sd
    print(ans.replace("?","a"))
  else:
    print("UNRESTORABLE")

Solution (Python):
def hantei(start,key):
    if( ango[start]=="?" or ango[start]==key) and len(key)==1:
        return True
    if ango[start]=="?" or ango[start]==key[0]:
        key=key[1:]
        return hantei(start+1,key)
    else:
        return False
ango=input()
key=input()
top=key[0]
ans="UNRESTORABLE"
for i in range(len(ango)-len(key)+1):
    if hantei(i,key):
        ans=ango[:(i)]+key+ango[(i+len(key)):]
for j in range(len(ans)):
    if ans[j]=="?":
        ans=ans[:j]+"a"+ans[(j+1):]
print(ans)

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

DEBUG = False

reversed_S_dash = S_dash[::-1]
reversed_T = T[::-1]

for i in range(len(S_dash)-len(T)+1):
    flag = True
    for j in range(len(T)):
        if DEBUG:
            print("i: {}, j: {}".format(i, j))
            print("S_dash[i+j]: {}, T[j]: {}".format(reversed_S_dash[i+j], reversed_T[j]))
        if reversed_S_dash[i+j] != reversed_T[j] and reversed_S_dash[i+j] != '?':
            if DEBUG:
                print("miss match")
            flag = False
            break
    if flag:
        if DEBUG:
            print("find")
            print("from {} to {}".format(i, i+len(T)-1))
        ans = reversed_S_dash[:i]+reversed_T+reversed_S_dash[i+len(T):]
        ans = ans.replace('?', 'a')
        print(ans[::-1])
        exit(0)

print("UNRESTORABLE")

Solution (Python):
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), -1, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T):]
        flag = False
        break
S = S_.replace('.', 'a')

if flag:
    print('UNRESTORABLE')
else:
    print(S)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
T = input()
sl = len(S)
tl = len(T)

def f(idx):
    if idx + tl > sl:
        return False
    for i in range(tl):
        if S[idx + i] != '?' and S[idx + i] != T[i]:
            return False

    ret = [''] * sl
    for i in range(sl):
        ret[i] = T[i - idx] if idx <= i < idx + tl else S[i] if S[i] != '?' else 'a'

    return "".join(ret)

def solve():
    for i in range(sl, -1, -1):
        if f(i):
            print(f(i))
            return

    print("UNRESTORABLE")

solve()

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


def match(k):
    for i in range(len(t)):
        if t[i] != s[i + k] and s[i + k] != "?":
            return False
    return True


def construct(k):
    ans = list(s)
    for i in range(len(t)):
        ans[k + i] = t[i]
    for i in range(len(s)):
        if ans[i] == "?":
            ans[i] = "a"
    return "".join(ans)


K = len(s) - len(t) + 1

pw_candid = []

for i in range(K):
    if match(i):
        pw_candid.append(construct(i))
        
        
if len(pw_candid):
    print(sorted(pw_candid)[0])
else:
    print("UNRESTORABLE")

Solution (Python):
sp_l = list(input())
t_l = list(input())

candidates = []
for i in range(len(sp_l)): 
    s_l = sp_l[:] 
    if sp_l[i] == t_l[0] or sp_l[i] == '?':
        s_l[i] = t_l[0]
        for j in range(1,len(t_l)):
            if i+j >= len(sp_l):
                break
            if sp_l[i+j] == t_l[j] or sp_l[i+j] == '?':
                s_l[i+j] = t_l[j]
            else:
                break
        else:
            candidates.append(''.join(s_l))

if len(candidates) == 0:
    print('UNRESTORABLE')
else:
    for i in range(len(candidates)):
        candidates[i] = candidates[i].replace('?','a')
    candidates.sort()
    print(candidates[0])

Solution (Python):
s_prime=list(input())
t=list(input())
ls=len(s_prime)
lt=len(t)
s_prime.reverse()
t.reverse()


if lt>ls:
    print('UNRESTORABLE')
else:
    def check(t,s):
        l=len(t)
        c=0
        for i in range(l):
            if s[i]!='?' and s[i]!=t[i]:
                c=1
        return True if c==0 else False
    c=0            
    for i in range(ls-lt+1):
        print()
        if check(t,s_prime[i:i+lt])==1:
            t_in=s_prime[:i]+t+s_prime[i+lt:] 
            for k in range(ls):
                if t_in[k]=='?':
                    t_in[k]='a'
            t_in.reverse()   
            print(''.join(t_in))
            c=1
            break
    print('UNRESTORABLE') if c==0 else exit()

Solution (Python):
import bisect
def resolve():
    S = input()
    T = input()
    lenT = len(T)
    found = False
    for i in range(len(S)-lenT, -1, -1):
        for j in range(0, lenT):
            if not (S[i+j] == "?" or S[i+j] == T[j]):
                break
        else:
            S = S[:i] + T + S[i+lenT:]
            found = True
            break
    if found:
        print(S.replace("?", "a"))
    else:
        print("UNRESTORABLE")

if '__main__' == __name__:
    resolve()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = list(input())
    t = list(input())
    ls = len(s)
    lt = len(t)

    s_true = ""
    from copy import copy

    for i in range(ls - lt + 1):
        s_temp = copy(s)
        for j in range(lt):
            if s[i + j] == t[j]:
                pass
            elif s[i + j] == "?":
                s_temp[i + j] = t[j]
            else:
                break

            if j == lt - 1:
                s_true = copy(s_temp)

    if not s_true:
        print("UNRESTORABLE")
    else:
        for i in range(ls):
            if s_true[i] == "?":
                s_true[i] = "a"

    print("".join(s_true))


if __name__ == '__main__':
    main()

Solution (Python):
S = list(input())
T = list(input())
flag1 = 1
for i in range(len(S) - len(T), -1, -1):
    flag2 = 1
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            flag2 = 0
    if flag2:
        S[i:i+len(T)] = T[:]
        flag1 = 0
        break

if flag1:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if S[i] == '?':
            S[i] = 'a'
    print(''.join(S))

Solution (Python):
from sys import stdin

Sp = stdin.readline().rstrip()
T =  stdin.readline().rstrip()


N = len(Sp)
M = len(T)

def check_feasibility(S, T, i):
    S_temp = S[i:i+M]
    index=0
    for j in range(M):
        if S_temp[j]=="?" or S_temp[j]==T[j]:
            index+=1
            continue
        else:
            break
    if index==len(T):
        return 1
    else:
        return 0

pos=-1
for i in range(N-M+1):
    is_ok = check_feasibility(Sp, T, i)
    if is_ok:
        pos=i
        
if pos==-1:
    print("UNRESTORABLE")
else:
    new_s = Sp[:pos] + T + Sp[pos+M:]
    new_s = new_s.replace("?","a")
    print(new_s)

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

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


    anss = []
    for i in range(max(0, len(S)-len(T)+1)):
        ans = ""
        for j in range(i):
            if S[j] == "?":
                ans += "a"
            else:
                ans += S[j]

        for j in range(i, i+len(T)):
            if S[j] == T[j-i]:
                ans += S[j]
            elif S[j] == "?":
                ans += T[j-i]
            else:
                break

        for j in range(i+len(T), len(S)):
            if S[j] == "?":
                ans += "a"
            else:
                ans += S[j]

        if len(ans) == len(S):
            anss.append(ans)

    if len(anss):
        print(min(anss))
    else:     
        print("UNRESTORABLE")

if __name__ == "__main__":
    main()

Solution (Python):
s=input()
t=input()
sl=len(list(s))
tl=len(list(t))
for i in range(sl-tl+1)[::-1]:
    c=0
    for j in range(tl):
        if s[i+j]==t[j] or s[i+j]=='?':c+=1
        else:break
    if c==tl:
        print((s[:i]+t+s[i+tl:]).replace("?", "a"))
        exit()
print('UNRESTORABLE')

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

for i in reversed(range(len(S) - len(T) + 1)):
  T_flg = S[i: i + len(T)]
  for j in range(len(T)):
    if T_flg[j] != T[j] and T_flg[j] != "?":
      break
  else:
    flag = True
    S[i:i + len(T)] = T
    break

if flag == False:
  print("UNRESTORABLE")
else:
  for i in range(len(S)):
    if S[i] == "?":
      S[i] = "a"
  print("".join(map(str,S)))

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

n = len(S)
m = len(T)


for i in reversed(range(n - m + 1)):
  t_kamo = S[i: i + m]
  for j in range(m + 1):
    if j == m:
      print((S[:i] + T +  S[i + m:]).replace("?", "a"))
      exit()
    if t_kamo[j] == "?":
      continue
    elif t_kamo[j] != T[j]:
      break

print("UNRESTORABLE")

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

n = len(sd)
m = len(t)
s = []


for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

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

s = len(S)
t = len(T)

if t > s:
    print('UNRESTORABLE')
    exit()

for i in range(s-t,-1,-1):
    for j in range(t):
        if S[i+j] != '?' and S[i+j] != T[j]:
            break
        else:
            continue
    else:
        A = []
        for j in range(s):
            if i <= j < i+t:
                A.append(T[j-i])
            elif S[j] == '?':
                A.append('a')
            else:
                A.append(S[j])
        ans = A[0]
        for j in range(1,s):
            ans = ans + A[j]
        print(ans)
        break
else:
    print('UNRESTORABLE')

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

a = len(s)
b = len(t)
ans = []

if a-b < 0:
    print("UNRESTORABLE")
    exit()

for i in range(a-b+1):
    frag = True
    for j in range(b):
        if s[i+j] != t[j] and s[i+j] != "?":
            frag = False
    if frag == True:
        code = s[:i] + t + s[i+b:]
        ans.append(code.replace("?","a"))

if len(ans) == 0:
    print("UNRESTORABLE")
    exit()
else:
    ans.sort()
    print(ans[0])

Solution (Python):
s = input()
t = input()
ans = []
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

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


    if flag == True:
        prot = "".join(prot).replace("?", "a")
        ans.append(prot)

if ans == []:
    print("UNRESTORABLE")
else:
    ans = sorted(ans)
    print(ans[0])

Solution (Python):
import copy

s=str(input())
t=str(input())
ls=len(s)
lt=len(t)
S=list(s)
T=list(t)



def fill(List):
    for j in range(len(List)):
        if List[j]=='?':
            List[j]='a'
    return List


def change1(index):
    global lt

    cS=copy.copy(S)
    cT=copy.copy(T)
    for k in range(index+1,index+lt):
        if cS[k]=='?':
            cS[k]=cT[k-index]
        elif cS[k]==cT[k-index]:
            pass
        else:
            return False,''
            break
    else:
        return True,''.join(fill(cS))

def change2(index):
    global lt

    cS=copy.copy(S)
    cT=copy.copy(T)
    cS[index]=cT[0]
    for k in range(index+1,index+lt):
        if cS[k]=='?':
            cS[k]=cT[k-index]
        elif cS[k]==cT[k-index]:
            pass
        else:
            return False,''
            break
    else:
        return True,''.join(fill(cS))



L=[]
for i in range(ls-lt+1):
    
    if S[i]==T[0]:
        
        if change1(i)[0]:
            L.append(change1(i)[1])
    elif S[i]=='?':
        if change2(i)[0]:
            L.append(change2(i)[1])
    


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

Solution (Python):

import sys  
import numpy as np

input = sys.stdin.readline

S_ = input()
T = input()

S_ = list(S_)[:-1]
T = list(T)[:-1]

j = False
for i in range(len(S_)-len(T)+1):
    if i==0:
        part = S_[-len(T):]
    else :
        part = S_[-len(T)-i:-i]
    j = False
    for k in range(len(part)-1,-1,-1):
        if part[k] == "?":
            if k==0:
                j = True
            continue
        elif part[k] == T[k]:
            if k==0:
                j = True
        else:
            break
    if j:
        break


if j:
    for p in range(len(T)):
        S_[len(S_)-len(T)-i+p] = T[p]
    
    for k in range(len(S_)):
        if S_[k] == "?":
            S_[k] = "a"

    print("".join(S_))
else:
    print("UNRESTORABLE")

Solution (Python):
S_=input()
T=input()
N=len(S_)
M=len(T)
posi=[]

for i in range(N-M+1):
  flag=True
  for j in range(i,i+M):
    if S_[j]!=T[j-i] and S_[j]!="?":
      flag=False
  if flag==True:
    posi.append(S_[:i]+T+S_[i+M:])

    
if posi==[]:
  print("UNRESTORABLE")
else:
  ans_list=[]
  for item in posi:
    ans=""
    for str in item:
      if str=="?":
        ans += "a"
      else:
        ans += str
    ans_list.append(ans)
  ans_list.sort()
  print(ans_list[0])

Solution (Python):
S_dash = list(input())
M = len(S_dash)

T = list(input())
N = len(T)

match = [False for _ in range(M)]

last_match = -100
for i in range(M - N + 1):
    for j in range(N):
        if S_dash[i+j] == "?":
            continue
        elif S_dash[i+j] == T[j]:
            continue
        elif S_dash[i+j] != T[j]:
            break
    else:
        match[i] = True
        last_match = i
S = S_dash

if last_match == -100:
    print("UNRESTORABLE")
else:
    for i in range(N):
        S[last_match+i] = T[i]
    for i in range(M):
        if S[i] == "?":
            S[i] = "a"
    print("".join(str(x) for x in (S)))

Solution (Python):

S_dash = list(input())
M = len(S_dash)

T = list(input())
N = len(T)

match = [False for _ in range(M)]

last_match = -100
for i in range(M - N + 1):
    for j in range(N):
        if S_dash[i+j] == "?":
            continue
        elif S_dash[i+j] == T[j]:
            continue
        elif S_dash[i+j] != T[j]:
            break
    else:
        match[i] = True
        last_match = i
S = S_dash.copy()

if last_match == -100:
    print("UNRESTORABLE")
else:
    for i in range(N):
        S[last_match+i] = T[i]
    for i in range(M):
        if S[i] == "?":
            S[i] = "a"
    print("".join(str(x) for x in (S)))

Solution (Python):
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    S = input()
    T = input()
    p = -1
    for i in range(len(S) - len(T) +1):
        match = True
        for j in range(len(T)):
            if not(S[i+j] == '?' or S[i+j] == T[j]):
                match = False
                break
        if match:
            p = i

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

    

if __name__ == '__main__':
    main()

Solution (Python):
from copy import copy
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = copy(S)
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

a = []
if exist == 1: 
    L = len(l)
    for i in range(L):
        tmp = copy(l[i])
        for j in range(N):
            if tmp[j] == "?":
                tmp[j] = "a"
        a.append(tmp)
    a.sort()
    ans = "".join(a[0])
    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):
s = list(input())
t = list(input())
n = len(s)
m = len(t)
if n < m:
    print('UNRESTORABLE')
else:
    f2 = False
    for i in range(n, m-1 , -1):
        f = True
        num = i
        for j in range(1,m+1):
            if s[i-j] != t[-j] and s[i-j] != '?':
                f = False
                break
        if f:
            f2 = True
            break
    if f2:
        for j in range(1, m+1):
            s[num-j] = t[-j]
        for i in range(n):
            if s[i] =='?':
                s[i]= 'a'
        print(''.join(s))
    else:
        print('UNRESTORABLE')

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

a = len(s)
b = len(t)
ans = []
if a-b+1 < 0:
    print("UNRESTORABLE")
    exit()

for i in range(a-b+1):
    p = 0
    for j in range(b):
        if s[i+j] != t[j] and s[i+j] != "?":
            p = 1
            break
    if p == 0:
        kar = s[:i] + t + s[i+b:]
        kar = kar.replace("?","a")
        ans.append(kar)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])

Solution (Python):
s = input()
n = len(s)
t = input()
m = len(t)
ans = []
res = []
for start in range(n):
    ok = True
    for i in range(len(t)):
        if i+start > n-1:
            ok = False
            break
        if not(t[i] == s[i+start] or s[i+start] == '?'):
            ok = False
            break
    
    
    if ok:res.append(start)
for st in res:
    string = ""
    for i in range(0,st):
        if s[i] == '?':
            string +='a'
        else:
            string += s[i]
    string += t
    for i in range(st+m,n):
        if s[i] == '?':string += 'a'
        else:string += s[i]
    ans.append(string)
if len(ans) >0:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

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

if len(S_dush) < len(T):
    print("UNRESTORABLE")
    exit()

S_dush_list = []
for i in range(len(S_dush)):
    S_dush_list.append(S_dush[i])

def judge():
    for i in range(len(S_dush)-len(T),-1,-1):
        T_index = 0
        for j in range(i,i+len(T)):
            if S_dush_list[j] != "?":
                if S_dush_list[j] != T[T_index]:
                    break
            T_index += 1
            if len(T) == T_index:
                return j
    return -1

index = judge()
if index == -1:
    print("UNRESTORABLE")
    exit()

for i in range(index-len(T)+1,index+1):
    S_dush_list[i] = T[i-index+len(T)-1]

for i in range(len(S_dush)):
    if S_dush_list[i] == "?":
        S_dush_list[i] = "a"

print(''.join(S_dush_list))