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):
S = input()
T = input()
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()

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 = S[:i] + T + S[i+len(T):]
        S = S.replace('?', 'a')
        print(S)
        break
else:
    print('UNRESTORABLE')

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

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

Solution (Python):

from collections import deque
S = input()
T = input()

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

word =[]

for i in range(s):
  for j in range(t):
    if S[i+j:i+j+1] =="?" or S[i+j:i+j+1]==T[j:j+1]:
      if j==t-1:
        tmp = S[0:i]+T+S[i+j+1:]
        for k in range(s):
          if tmp[k:k+1] =="?":
            tmp =tmp[0:k]+"a"+tmp[k+1:]
        word.append(tmp)
    else:
      break

word.sort()

if not word:
  print("UNRESTORABLE")
else:
  print(word[0])

Solution (Python):
import re

s = input().strip()
t = input().strip()

ls = len(s)
lt = len(t)

if ls < lt:
    print('UNRESTORABLE')
else:
    s = s.replace('?', '.')
    ans = []
    for i in range(len(s) - len(t) + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i]+t+s[i+lt:]).replace('.', 'a'))
    if not ans:
        print('UNRESTORABLE')
    else:
        print(min(ans))

Solution (Python):


s = input()
t = input()
ls = len(s)
lt = len(t)
ans = 0

for i in range(ls, lt-1, -1):
    temp = s[i-lt:i]
    
    counter = 0
    for j in range(lt-1, -1, -1):
        if t[j] == temp[j] or temp[j] == '?':
            counter += 1
            
            
    if counter == lt:
        ans = i
        break

if ans == 0:
    print('UNRESTORABLE')
else:
    print((s[:ans-lt]+t+s[ans:]).replace('?', 'a'))

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

index = len(S)
ans = []
isMatch = True


while index - len(T) >= 0:
  obj = S[index - len(T):index]
  
  for i in range(len(obj)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
  
  
  if isMatch:
    ans.append(S[0:index-len(T)] + T + S[index:])

  isMatch = True
  index = index - 1

if ans == []:
  print("UNRESTORABLE")
else:
  ans = sorted(ans)[0]
  for i in range(len(ans)):
    if ans[i] == "?":
      ans[i] = "a"
  print("".join(ans))

Solution (Python):
l = input().split()
S = l[0]
l = input().split()
T = l[0]

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



found = False

def match(pos, max_pos, src, dst):
    if pos == max_pos:
        return True
    if src[pos] == '?' or src[pos] == dst[pos]:
        return match(pos + 1, max_pos, src, dst)
    return False

for i in range(ls - lt + 1):
    index = ls - lt - i
    if match(0, lt, S[index:], T):
        S = S[:index] + T + S[index + lt:]
        found = True
        break

if found:
    S = S.replace('?', 'a')
    print(S)
else:
    print('UNRESTORABLE')

Solution (Python):
def main():
    S = list(input())
    T = list(input())
    S.reverse()
    T.reverse()
    SL = list(S)
    f = False
    for i in range(len(S) - len(T) + 1):
        SL = list(S)
        for j in range(len(T)):
            if S[i + j] == '?' or S[i + j] == T[j]:
                SL[i + j] = T[j]
            else:
                break
        else:
            f = True
            break
    if f is False:
        print('UNRESTORABLE')
    else:
        SL.reverse()
        print(''.join(SL).replace('?', 'a'))


main()

Solution (Python):
def main():
    S = list(input())
    T = list(input())
    S.reverse()
    T.reverse()
    SL = list(S)
    f = False
    for i in range(len(S) - len(T) + 1):
        SL = list(S)
        for j in range(len(T)):
            if S[i + j] == '?' or S[i + j] == T[j]:
                SL[i + j] = T[j]
            else:
                break
        else:
            f = True
            break
    if f is False:
        print('UNRESTORABLE')
    else:
        SL.reverse()
        print(''.join(SL).replace('?', 'a'))


main()

Solution (Python):

s = list(input())
h = list(input())

index = len(s)
omega = []
notFound = False
while index - len(h) >= 0 and not notFound:
    obj = s[index - len(h):index]
    
    for i in range(len(obj)):
        if not obj[i] == "?":
            if not obj[i] == h[i]:
                notFound = True

    if not notFound:
        omega.append(s[0:index-len(h)] + h + s[index:])

    notFound = False
    index -= 1

    

if omega == []:
    print('UNRESTORABLE')
else:
    ans = sorted(omega)[0]
    for i in range(len(ans)):
        if ans[i] == "?":
            ans[i] = "a"
    print("".join(ans))

Solution (Python):
S = input()
T = input()
def checkstr(ss):
    for (s,t) in zip(ss,T):
        check = True
        if s=="?":
            continue
        elif s!=t:
            check = False
            break
    return check
ans = ""
for i in range(len(S)-len(T)+1):
    strs = S[i:i+len(T)]
    if checkstr(strs):
        ans = S[:i].replace("?","a")+T+S[i+len(T):].replace("?","a")
if ans=="":
    print("UNRESTORABLE")
else:
    print(ans)

Solution (Python):
S = input()
T = input()
def checkstr(ss):
    for (s,t) in zip(ss,T):
        check = True
        if s=="?":
            continue
        elif s!=t:
            check = False
            break
    return check
ans = ""
for i in range(len(S)-len(T)+1):
    strs = S[i:i+len(T)]
    if checkstr(strs):
        ans = S[:i].replace("?","a")+T+S[i+len(T):].replace("?","a")
if ans=="":
    print("UNRESTORABLE")
else:
    print(ans)

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

SS.reverse()
T.reverse()

flag=0
for i in range(len(SS)-len(T)+1):
    if flag==0:
        for j in range(len(T)):
            if SS[i+j]==T[j] or SS[i+j]=='?':
                if j==len(T)-1:
                    flag=1
                    for k in range(len(T)):
                        SS[i+k]=T[k]
                    break
            else:
                break
            
            

ans=''
SS.reverse()
if flag==1:
    for i in range(len(SS)):
        if SS[i]=='?':
            SS[i]='a'
        ans+=SS[i]
else:
    ans='UNRESTORABLE'
print(ans)

Solution (Python):
flag = False

s = input()
t = input()
A = []
finish = False
for i in reversed(range(0,len(s)-len(t)+1)):
    flag = True
    for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != '?':
            flag = False
    if flag:
        finish = True
        ans = []
        for k in range(len(s)):
            if i <= k <=i + len(t) -1:
                ans.append(t[k-i])
            else:
                if s[k] == '?':
                    ans.append('a')
                else:
                    ans.append(s[k])
        A.append(ans)
if not finish:
    print('UNRESTORABLE')
else:
    A.sort()
    print(''.join(A[0]))

Solution (Python):
from re import*
s,t=open(0)
t=t[:-1]
u=''.join('(%s|\?)'%t for t in t)
a=[]
j=len(t)
for i in range(len(s)-j):
  if match(u,s[i:i+j]):
    a.append(sub('\?','a',s[:i])+t+sub('\?','a',s[i+j:]))
print(min(a or['UNRESTORABLE']))

Solution (Python):
from re import*
s,t=open(0)
t=t[:-1]
u=''.join('(%s|\?)'%t for t in t)
a=[]
j=len(t)
for i in range(len(s)-j):
  if match(u,s[i:i+j]):
    a.append(sub('\?','a',s[:i])+t+sub('\?','a',s[i+j:]))
print(min(a or['UNRESTORABLE']))

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

for i in range(len(Sd)-len(T)+1):
    for j in range(len(T)):
        if Sd[len(Sd)-i-j-1] not in (T[len(T)-j-1],'?'):
            break
    else:
        print((Sd[:len(Sd)-i-len(T)]+T+Sd[len(Sd)-i:]).replace('?','a'))
        exit()
print('UNRESTORABLE')

Solution (Python):


def main():
    moji = list(input())
    hint = list(input())


    for i in range(len(moji) - len(hint) + 1)[::-1]:
        flg = 1
        for j in range(len(hint)):
            if moji[i + j] == '?':
                continue
            if hint[j] != moji[i + j]:
                flg = 0
                break
        if flg:
            for j in range(len(hint)):
                moji[i + j] = hint[j]
            for j in range(len(moji)):
                if moji[j] == '?':
                    moji[j] = 'a'
            print(''.join(moji))
            break
    else:
        print('UNRESTORABLE')



if __name__ == '__main__':
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
import pdb

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    t = S()
    cands = []
    ans = 'z' * 50
    for st_ix in range(len(s)):
        cur_j = 0
        copy_s_list = list(s)
        is_cand = False 
        while cur_j < len(t) and st_ix + len(t) - 1< len(s):
            if s[st_ix + cur_j] == t[cur_j] or s[st_ix + cur_j] == '?':
                copy_s_list[st_ix + cur_j] = t[cur_j]
                cur_j += 1
                if cur_j == len(t):
                    is_cand = True
            else:
                break

        if is_cand: 
            for ix in range(len(copy_s_list)):
                if copy_s_list[ix] == '?':
                    copy_s_list[ix] = 'a'
            cands.append(''.join(copy_s_list))
    if cands == []:
        print("UNRESTORABLE")
    else:
        print(min(cands))

            
main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
import pdb

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    t = S()
    cands = []
    ans = 'z' * 50
    for st_ix in range(len(s)):
        i = st_ix 
        cur_j = 0
        copy_s_list = list(s)
        is_cand = False 
        while cur_j < len(t) and st_ix + len(t) - 1< len(s):
            if s[i] == t[cur_j] or s[i] == '?':
                copy_s_list[i] = t[cur_j]
                cur_j += 1
                i += 1
                if cur_j == len(t):
                    is_cand = True
            else:
                break

        if is_cand: 
            for ix in range(len(copy_s_list)):
                if copy_s_list[ix] == '?':
                    copy_s_list[ix] = 'a'
            cands.append(''.join(copy_s_list))
    if cands == []:
        print("UNRESTORABLE")
    else:
        print(min(cands))

            
main()

Solution (Python):
S=input()
T=input()
flg=False
ans='UNRESTORABLE'
for i in reversed(range(len(S)-len(T)+1)):
    if flg:
        break

    for j in range(len(T)):
        if S[i+j]==T[j] or S[i+j]=='?':
            pass
        else:
            break
        
        if j==len(T)-1:
            S=S.replace('?','a')
            ans=S[:i]+T+S[i+len(T):]
            flg=True
            break
print(ans)

Solution (Python):
S = list(input())
T = list(input())
ls = len(S)
lt = len(T)
count = 0
judge = 0

for i in range(ls - lt + 1):
    for j in range(lt):
        if S[i + j] == '?' or S[i + j] == T[j]:
            count += 1

    if count == lt:
        rep = i
        judge = 1
    
    count = 0

if judge == 0:
    print('UNRESTORABLE')
else:
    for i in range(lt):
        S[rep + i] = T[i]
    S = ''.join(S)
    print(S.replace('?','a'))

Solution (Python):

Sd = input()
T  = input()
cand = []
lent = len(T)

for idx in range(len(Sd)-lent+1):
    p = 0
    while p < lent:
        if Sd[idx+p] != T[p] and Sd[idx+p] != "?":
            break

        if p == lent - 1:
            can = ""
            if idx > 0: can = Sd[:idx]
            can += T
            if idx + lent < len(Sd):
                can += Sd[(idx+lent):]
            cand.append(can.replace("?","a"))
        p += 1
if len(cand) == 0:
    print("UNRESTORABLE")
else: 
    cand.sort()
    print(cand[0])

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

match = []
for i in range(len_s - len_t + 1):
    if s[i] == "?" or s[i] == t[0]:
        for s_j, t_j in zip(s[i:i+len_t], t):
            if s_j != t_j and s_j != "?":
                break
        else:
            temp = s[:i] + t + s[i + len_t:]
            match += [temp.replace("?", "a")]

print(min(match) if match != [] else "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):
import re
S = input()
T = input()

S = S.replace('?', '.')
t_len = len(T)
for i in reversed(range(len(S) - t_len + 1)):
    if re.match(S[i:i + t_len], T) is not None:
        S = S[:i] + T + S[i + t_len:]
        print(S.replace('.', 'a'))
        break
else:
    print('UNRESTORABLE')

Solution (Python):
import re
  

def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + lt:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)
  
  
s = input().strip()
t = input().strip()
  
print(solve(s, t))

Solution (Python):
import re
S = input().replace("?", ".")[::-1]
T = input()[::-1]

for i in range(len(S)-len(T)+1):
  if re.match(S[i:i+len(T)], T):
    S = S.replace(".", "a")
    ans = S[:i]+T+S[i+len(T):]
    print(ans[::-1])
    exit()    
print("UNRESTORABLE")

Solution (Python):
import re
s=input().replace("?",".")
t=input()
for i in range(len(s)-len(t),-1,-1):
    if re.match(s[i:i+len(t)],t):
        s=s.replace(".","a")
        print(s[:i]+t+s[i+len(t):])
        exit()
print("UNRESTORABLE")

Solution (Python):
s = input()
t = input()
flag = False
tlen = len(t)
slen = len(s)

def same(a,b):
    for aa, bb in zip(a,b):
        if not(aa =="?" or aa == bb):
            return False
    return True

if tlen <= slen:
    for i in range(slen-tlen,-1,-1):
        if same(s[i:i+tlen],t):
            flag = True
            s = s[:i]+t+s[i+tlen:]
            break
ans = ""
if flag:
    for ss in s:
        if ss == "?":
            ans += "a"
        else:
            ans += ss
    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):





def main():
    
    S = input().replace('?', '.')
    T = input()

    import re
    import sys

    for i in range(len(S)-len(T),-1,-1):
        if(re.match(S[i:i+len(T)],T)):
            S = S.replace('.', 'a')
            print(S[:i]+T+S[i+len(T):])
            exit()
    else:
        print("UNRESTORABLE")
    
if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math



def do():
    S = input()
    T = input()
    s = len(S)
    t = len(T)
    flag = False
    for i in range(s-t,-1,-1):
        if S[i] == "?" or S[i] ==T[0]:
            flag = True
            for j in range(t):
                if T[j] == S[i+j] or S[i+j] == "?":
                    pass
                else:
                    flag = False
        if flag:
            break
    if flag:
        ans = list(S)
        for k in range(i,i+t):
            ans[k] = T[k-i]
        for i,temp in enumerate(ans):
            if temp == "?":
                ans[i] = "a"
        print("".join(ans))
    else:
        print("UNRESTORABLE")





if __name__ == "__main__":
    do()

Solution (Python):
s=list(input())[::-1]
t=list(input())[::-1]
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] not in ['?',t[j]]:break
		else:
			s[i:i+len(t)]=t
			break
	else:
		print('UNRESTORABLE')
		exit()
	print(''.join(s[::-1]).replace('?','a'))

Solution (Python):
S = input()[::-1]
T = input()[::-1]

ans = "UNRESTORABLE"

for i in range(len(S)-len(T)+1) :
    for j in range(len(T)) :
        if S[i+j] not in ["?", T[j]] : 
            break
    else :
        ans = (S[:i]+ T + S[i+len(T):])[::-1].replace("?", "a")
        break

print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  t=S()

  for i in range(len(s)-len(t)+1)[::-1]:
    x=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
      if t[j]!=x[j] and x[j]!='?':
        f=False

    if f:
      return s[:i].replace('?','a')+t+s[i+len(t):].replace('?','a')

  return 'UNRESTORABLE'

print(main())

Solution (Python):
S = input()
T = input()
lenS = len(S)
lenT = len(T)
flag = False
ans = list(S)

for i in range(lenS-lenT, -1, -1):
    for j in range(lenT):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        flag = True
        break

if flag:
    for k in range(lenT):
        ans[i+k] = T[k]
    
    for k in range(lenS):
        if ans[k] == '?':
            ans[k] = 'a'
    print("".join(ans))
            
else:
    print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
n = len(S)
t = len(T)
ans = ''
if t > n:
    flag = False
for i in range(t, n+1):
    flag = True
    for j in range(t):
        if S[-i+j] != '?' and S[-i+j] != T[j]:
            flag = False
            break
    if flag:
        break
if flag:
    for s in S[:-i]:
        if s == '?':
            ans += 'a'
        else:
            ans += s
    ans += T
    if i != t:
        for s in S[-i+t:]:
            if s == '?':
                ans += 'a'
            else:
                ans += s
    print(ans)
else:
    print('UNRESTORABLE')

Solution (Python):
from itertools import product
s=input()
t=input()
t_point=-1
for i in range(len(s)-len(t)+1):
     for j in range(len(t)):
          if s[i+j]=='?':
               continue
          elif s[i+j]!=t[j]:
               break
     else:
          t_point=i
if t_point<0:
     print('UNRESTORABLE')
else:
     s=[x for x in s]
     for j in range(len(t)):
          s[t_point+j]=t[j]
     for i in range(len(s)):
          if s[i]=='?':
               s[i]='a'
     print(''.join(s))

Solution (Python):
import re
s = input()
t = input()
 
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):
    s = s[:i].replace(".","a") + t + s[i+len(t):].replace(".","a")
    print(s[::-1])
    break
else:
  print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
c = 0
idx = 0
ans = []
for i, s in enumerate(S):
    if s == T[0] or s == '?':
        tmp = S[i:min(i+len(T), len(S))]
        flg = True
        if len(T) != len(tmp):
            continue
        for j, c in enumerate(tmp):
            if c != T[j] and c != '?':
                flg = False
                break
        if flg:
            ans.append((S[:i] + T + S[i+len(T):]).replace('?', 'a'))
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

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

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):
    s = s[:i].replace(".","a") + t + s[i+len(t):].replace(".","a")
    print(s[::-1])
    break
else:
  print("UNRESTORABLE")

Solution (Python):
hoge=input()
key=input()
ans=[]
for i in range(len(hoge)-len(key)+1):
  flag=0
  for j in range(len(key)):
    if(hoge[i+j]==key[j] or hoge[i+j]=="?"):
      flag+=1
  if(flag==len(key)):
    kari=hoge[:i]+key+hoge[i+len(key):]
    ans.append(kari.replace("?","a"))
    
if(len(ans)>0):
  ans.sort()
  print(ans[0])
else:
  print("UNRESTORABLE")

Solution (Python):


import re



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

    S = S.replace("?",".")

    pos = []
    for i in range(0,len(S)-len(T)+1):
        s =  S[i:i+len(T)]
        m = re.match(s,T)
        if m: 
            pos.append(i)

    if len(pos) == 0:
        print("UNRESTORABLE")
        return

    S = S.replace(".","a")
    si = max(pos)

    print(S[0:si] + T + S[si+len(T):])




    pass

if __name__ == '__main__':
    main()

Solution (Python):
S = list(input())[::-1]
T = list(input())[::-1]

for n in range(0, len(S) - len(T) + 1):
	for i, t in enumerate(T):
		if "?" == S[n + i]:
			continue
		if t != S[n + i]:
			break
	else:
		S[n:n + len(T)] = T
		print("".join(S[::-1]).replace("?", "a"))
		break
else:
	print("UNRESTORABLE")

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

for i in range(len(S) - len(T) + 1):
    if i == 0:
        seq = S[-len(T)-i:]
    else:
        seq = S[-len(T)-i:-i]
    for j in range(len(T)):
        if seq[j] == "?":
            seq = seq[:j]+T[j]+seq[j+1:]

    if seq == T:
        if i == 0:
            print((S[:-len(T)-i]+T).replace("?", "a"))
        else:
            print((S[:-len(T)-i]+T+S[-i:]).replace("?", "a"))
        exit()

print("UNRESTORABLE")

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

def seq(inlist):
	global t
	dismatch = 0
	for i in range(len(t)):
		if t[i] != inlist[i] and inlist[i] != "?":
			dismatch = 1
			break
	return dismatch


ans = "UNRESTORABLE"
if ls >= lt:

	d = -1
	for i in range(ls-lt+1):
		if seq(s[i:i+lt]) == 0:
			d = i
	if d != -1:

		for i in range(lt):
			s[d+i] = t[i]
		for i in range(ls):
			if s[i] == "?":
				s[i] = "a"

		ans = "".join(s)

print(ans)

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

candi = []

for i in range(len(s)-len(t)+1):
    c = 0
    k = s[:]
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            k[i+j] = t[j]
            c += 1
    
    
    if c == len(t):
        candi.append(k)

if len(candi) == 0:
    print('UNRESTORABLE')
    
else:
    for i in range(len(candi)):
        for j in range(len(s)):
            if candi[i][j] == '?':
                candi[i][j] = 'a'

    candi = sorted(candi)

    print(''.join(candi[0]))

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

def check(s):
    for t in range(len(T)):
        if S[s+t] != "?" and S[s+t] != T[t]:
            return False
    return True

p = -1
for s in range(len(S)-len(T)+1):
    c = check(s)
    if c:
        p = s

S = S.replace("?", "a")

if p == -1:
    print "UNRESTORABLE"
else:
    print S[:p] + T + S[(p + len(T)):]

Solution (Python):
def m():
    Sdash = input()
    T = input()

    diff = len(Sdash) - len(T)

    if diff < 0:
        print('UNRESTORABLE')
        return

    index = -1
    for i in range(diff+1):
        Sp = Sdash[i:i+len(T)]
        for j in range(len(T)):
            if T[j] == Sp[j] or Sp[j] == '?':
                pass
            else:
                break
        else:
            index = i
    if index < 0:
        print('UNRESTORABLE')
        return

    res = Sdash.replace('?', 'a')
    res = res[0:index] + T + res[index+len(T):]
    print(res)


if __name__ == '__main__':
    m()

Solution (Python):

S = input()
T = input()


found = []
for i in range(len(S) - len(T) + 1):
    for cs, ct in zip(S[i:], T):
        if cs != "?" and cs != ct:
            break
    else:
        found.append(i)


if not found:
    ans = "UNRESTORABLE"
else:
    ans = "z" * 51
    for i in found:
        tmp = S[:i] + T + S[i+len(T):]
        ans = min(ans, tmp.replace("?", "a"))
print(ans)

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

cnd = []
for i in range(len(s) - len(t) + 1):
    if all(s[i + j] == t[j] or s[i + j] == '?' for j in range(len(t))):
        cnd.append(i)

if cnd:
    x = [s[:k] + t + s[k + len(t):] for k in cnd]
    x = [v.replace('?', 'a') for v in x]
    print(sorted(x)[0])
else:
  	print('UNRESTORABLE')

Solution (Python):
import re
Srd = "".join(reversed(input()))
T = input()
Tr = "".join(reversed(T))
Trd = "".join(["[{}?]".format(x) for x in Tr])

S = "".join(reversed(re.sub(Trd, Tr, Srd, 1))).replace("?", "a")
if S.count(T):
  print(S)
else:
  print("UNRESTORABLE")

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

for i in range(len(s)-len(t),-1,-1):
    tmp = s[i:i+len(t)]
    ans = ''
    for j in range(len(t)):
        if tmp[j] != t[j] and tmp[j] != '?':
            break
        ans += t[j]
        if j == len(t)-1:
            ans = s[:i]+ans+s[len(t)+i:]
            print(ans.replace('?','a'))
            exit()
print('UNRESTORABLE')

Solution (Python):
import math
import fractions
import copy

def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)





a = input()                                  






b = input()
matchplace = []
diff = len(a)-len(b)
for i in range(len(a)-len(b)+1):
    cut = a[i:i+(len(b))]
    for k in range(len(cut)):
        if not(cut[k] == b[k] or cut[k] == '?'):
            break
        else:
            if k == len(b)-1:
                matchplace.append(i)
wordlist = []
for i in matchplace:
    cword = [ a[:i],b,a[(i+len(b)):] ]
    cword = ''.join(cword)
    cword = cword.replace('?','a')
    wordlist.append(cword)
if len(matchplace) == 0:
    print("UNRESTORABLE")
else:
    wordlist.sort()
    print(wordlist[0])

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

ans = []
for i in range(len(S) - len(T) + 1):
    c = ""
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
        c += T[j]
    if len(c) == len(T):
        ans.append((S[:i] + c + S[i+len(T):]).replace("?", "a"))
print(min(ans) if ans else "UNRESTORABLE")

Solution (Python):
from copy import deepcopy

S = str(input())
T = str(input())

if len(S) < len(T):  
  print('UNRESTORABLE')
  exit()

solve = []
for i in range(len(S)-len(T)+1):
  bool_match = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      bool_match = False
      break
  if bool_match == True:
    if len(S) == len(T):
      S_tmp = T
    elif i == 0:
      S_tmp = T + S[len(T):]
    elif i+len(T) == len(S):
      S_tmp = S[:-len(T)] + T
    else:
      S_tmp = S[:i] + T + S[i+len(T):]
    solve.append(S_tmp.replace('?', 'a'))

if len(solve) == 0:
  print('UNRESTORABLE')
else:
  print(sorted(solve)[0])

Solution (Python):



words= list(input())
target = list(input())
i=len(words)-len(target)
flag=False
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
s = len(S)
t = len(T)
q = []
for i in range(s+1-t):
  f = True
  for j in range(t):
    if S[i+j] == '?' or S[i+j] == T[j]:
      continue
    f = False
  if f:
    
    tmp = S[:i] + T + S[i+t:]
    
    q.append(tmp.replace('?','a'))
    q.sort()
if len(q) == 0:
  print('UNRESTORABLE')
else:
  print(q[0])

Solution (Python):
S=list(input())
T=list(input())
L=[]
if len(S)-len(T)<0:
    print('UNRESTORABLE')
    exit()
for i in range(len(S)-len(T)+1):
    if all(S[i:i+len(T)+1][j]==T[j] or S[i:i+len(T)+1][j]=='?' for j in range(len(T))):
        L.append(''.join((S[0:i]+T+S[i+len(T):])).replace('?','a'))
if L==[]:
    print('UNRESTORABLE')
    exit()
else:
    print(sorted(L)[0])

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

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

flg = 0
y = s[::-1]
z = t[::-1]
result = []
for j,x in enumerate(range(0,len(y))):
    result = []
    for i,k in enumerate(y[x:x+len(t)]):
        if (k == z[i])|(k=="?"):
            result.append(True)
    if all(result)&(len(result)==len(t)):
        flg = 1
        break
if flg == 1:
    print((s[:len(s)-j-len(t)]+t+s[len(s)-j:]).replace("?","a"))
else:
    print("UNRESTORABLE")

Solution (Python):
from sys import exit, stdin
S = stdin.readline().rstrip()
T = stdin.readline().rstrip()
LOS, LOT = len(S), len(T)
for i in range(LOS)[::-1]:
    p = S[i:i+LOT]
    LOP = len(p)
    if LOP != LOT:
        continue

    ok = True
    for j in range(LOP):
        if p[j] == '?':
            continue
        if p[j] != T[j]:
            ok = False

    if ok:
        print(S[:i].replace('?', 'a')+T+S[i+LOT:].replace('?', 'a'))
        exit()
print("UNRESTORABLE")