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):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    return


def B():
    return


def C():
    s = S()
    t = S()
    ansa = []
    anslis = []
    lisans = []
    for i in range(len(s)):
        for j in range(len(t)):
            if 0 <= i + j < len(s) and (s[i + j] == t[j] or s[i + j] == "?"):
                continue
            break
        else:
            ansa.append((i, i + j))
    if len(ansa) == 0:
        print("UNRESTORABLE")
        return
    for ans in ansa:
        a = ""
        for num in range(len(s)):
            i = s[num]
            if ans[0] <= num <= ans[1]:
                i = t[num-ans[0]]
            a += i
        anslis.append(a)
    for ans in anslis:
        k = ""
        for i in ans:
            if i == "?":
                k += "a"
            else:
                k += i
        lisans.append(k)
    lisans.sort()
    print(lisans[0])
        
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    A()



"""
r = I()
g = I()
print(2*g-r)
"""


"""
n = I()
k = I()
ans = 1
for i in range(n):
    ans = min(ans * 2, ans + k)
print(ans)
"""



    



"""
n = I()
t = LI()
v = LI()
"""
if __name__ == "__main__":
    C()

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

if len(s) < len(t):
  print('UNRESTORABLE')
else:
  cands = []
  for i in range(len(s) - len(t) + 1):
    is_match = True
    for _s, _t in zip(s[i:i+len(t)], t):
      if _s != '?':
        if _s != _t:
          is_match = False
          break
    if is_match:
      cand = s.replace('?', 'a')
      cand = cand[:i] + t + cand[i+len(t):]
      cands.append(cand)
  if cands:
    print(list(sorted(cands))[0])
  else:
    print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
t = len(T)
indices = []
for i in range(len(S) - t + 1):
    for j, s in enumerate(S[i:i+t]):
        if s == '?':
            continue
        if s != T[j]:
            break
    else:
        indices.append(i)
if len(indices) == 0:
    print('UNRESTORABLE')
else:
    cand = []
    for ind in indices:
        ans = ''
        for i, s in enumerate(S):
            if i == ind:
                ans += T
            elif ind < i < ind + t:
                continue
            elif s == '?':
                ans += 'a'
            else:
                ans += s
        cand.append(ans)
    cand = sorted(cand)
    print(cand[0])

Solution (Python):
input_A = input()
input_T = input()
input_A, input_T = list(input_A), list(input_T)

if len(input_A) >= len(input_T):
    for i in range(len(input_A)-len(input_T), -1, -1):
        clear_flg = True
        for j in range(len(input_T)):
            if not (input_A[i + j] == '?' or input_A[i + j] == input_T[j]):
                clear_flg = False
                break

        if clear_flg is True:
            input_A[i:i + len(input_T)] = input_T
            input_A = ''.join(input_A).replace('?', 'a')
            break
else:
    clear_flg = False

if clear_flg is True:
    print(input_A)
else:
    print('UNRESTORABLE')

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

S = input()
T = input()
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
result = []
for sidx, s in enumerate(S):
    
    
    if sidx + len(T) > len(S):
        continue
    for tidx, t in enumerate(T):
        
        if S[sidx+tidx] == '?':
            continue
        if t != S[sidx+tidx]:
            
            break
    else:
        
        
        ans = S[:sidx] + T
        if sidx + len(T) < len(S):
            ans += S[sidx+len(T):]
        ans = ans.replace('?', 'a')
        result.append(ans)
if result:
    print(min(result))
else:
    print('UNRESTORABLE')

Solution (Python):


s = list(input())
t = list(input())

slen = len(s)
tlen = len(t)

cand = []
for i in range(slen - tlen + 1):
    match = True
    for j in range(tlen):
        if s[i + j] == "?" or s[i + j] == t[j]:
            pass
        else:
            match = False
    if match:
        cand.append(i)

if len(cand) != 0:
    cand.reverse()
    ans = ""
    for i in range(slen):
        if not (cand[0] <= i < cand[0] + tlen):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        else:
            ans += t[i - cand[0]]
    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
for i in reversed(range(len(S) - len(T) + 1)):
    frag = True
    for j in range(len(T)):
        if S[i + j] == T[j] or S[i + j] == "?":
            continue
        else:
            frag = False
            break
    if frag:
        ans = S[:i] + T
        if i + len(T) < len(S):
            ans += S[i + len(T):]
        ans = ans.replace("?", "a")
        print(ans)
        exit()
print("UNRESTORABLE")

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

Sd = Sd[::-1]
T = T[::-1]
flg = False
for s in range(len(Sd) - len(T)+1):
    
    cnt = 0
    for t in range(len(T)):
        
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T, 1)
        S = S.replace("?", "a")
        print(S[::-1])
        flg = True
        break

if flg is False:
    print("UNRESTORABLE")

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

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

if (matched_index > -1) :
    out_str = S[0:matched_index] + T + S[matched_index+len(T):]
    out_str = out_str.replace("?", "a")
    print(out_str)
else :
    print("UNRESTORABLE")

Solution (Python):
sp = input()
t = input()
len_t = len(t)
len_s = len(sp)
cand = []
part_start = -1

for i in range(len_s - len_t + 1):
    num = 0
    for j in range(len_t):
        if (sp[i + j] == '?' or sp[i + j] == t[j]):
            num += 1

    if (num == len_t):
        part_start = i

if part_start != -1:
    
    ans = sp[:part_start] + t + sp[part_start + len_t:]
    ans = ans.replace('?', 'a')
    print(ans)
else:
    print('UNRESTORABLE')

Solution (Python):
sp = input()
t = input()
len_t = len(t)
len_s = len(sp)
cand = []
part_start = -1

for i in range(len_s - len_t + 1):
    num = 0
    for j in range(len_t):
        if (sp[i + j] == '?' or sp[i + j] == t[j]):
            num += 1
    
    if (num == len_t):
        part_start = i

if part_start != -1:
    
    ans = sp[:part_start] + t + sp[part_start + len_t:]
    ans = ans.replace('?', 'a')
    print(ans)
else:
    print('UNRESTORABLE')

Solution (Python):
if __name__ == '__main__':
    hidden_key = input()
    flag_string = input()

    key_length = len(hidden_key)
    flag_length = len(flag_string)

    if key_length < flag_length:
        print('UNRESTORABLE')
        exit()

    key_list = list(hidden_key.replace('?', 'a'))

    for i in reversed(range(key_length - flag_length + 1)):
        part_key = hidden_key[i:i + flag_length]
        is_match = True

        for j in range(flag_length):
            if part_key[j] != '?' and part_key[j] != flag_string[j]:
                is_match = False
                break
            
        if is_match:
            for k in range(flag_length):
                key_list[i + k] = flag_string[k]
            print(''.join(key_list))
            break

    if not is_match:
        print('UNRESTORABLE')

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

pushable = [1] * (len(s) - len(t) + 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] != "?":
            pushable[i] = 0
            break

if 1 not in pushable:
    print("UNRESTORABLE")
    exit()

ans = []
for i, p in enumerate(pushable):
    cand = s
    if p:
        for j in range(len(t)):
            cand = cand[:i+j] + t[j] + cand[i+j+1:]
        for j in range(len(s)):
            if cand[j] == "?":
                cand = cand[:j] + "a" + cand[j+1:]
        ans.append(cand)

print(sorted(ans)[0])

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

last = -1
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] is T[j] or S[i+j] is '?':
            if j == len(T)-1:
                last = i
        else:
            break
if last != -1:
    S = S[:last] + T + S[last+len(T):]
    S = S.replace('?', 'a')
    print(S)
    exit()

print('UNRESTORABLE')

Solution (Python):
import copy
S=list(input())
S1 = "".join(S)
T=list(input())
T1 = "".join(T)
F = ["?"]*len(T)
F1 = "".join(F)
l =[]
M =[]
index =[]
B = copy.deepcopy(S)
for i in range(len(S)-len(T)+1):
    A = copy.deepcopy(S)
    c = A[i:len(T)+i]
    while "?" in c:
        c[c.index("?")] = T[c.index("?")]
    if c==T:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = c
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(M):
    M.sort()
    print("".join(M[0]))
else:
    print("UNRESTORABLE")

Solution (Python):
S=input()
T=input()
flag=False
for i in range(len(S)-len(T)+1):
    dif=0
    same=0
    s=S[i:i+len(T)]
    for j in range(len(T)):
        if s[j]!='?':
            if s[j]!=T[j]:
                
                dif+=1
            else:
                same+=1


        
    if dif==0:
        
        flag=True
        memo=i
    



if flag==False:
    print("UNRESTORABLE")
else:
    S=list(S)
    for i in range(len(T)):
        S[i+memo]=T[i]
    
    S=''.join(S)    
    S=S.replace('?','a')
    print(S)

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

len_Sp = len(Sp)
len_T = len(T)
restorable = False
max_i = 0
if len_Sp >= len_T:
    for i in range(len_Sp - len_T + 1):
        for j in range(len_T):
            if Sp[i + j] != '?' and Sp[i + j] != T[j]:
                break
        else:
            restorable = True
            max_i = i
if restorable:
    Sp[max_i : max_i + len_T] = T
    print(''.join(Sp).replace('?', 'a'))
else:
    print('UNRESTORABLE')

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

len_Sp = len(Sp)
len_T = len(T)
restorable = False
max_i = 0
if len_Sp >= len_T:
    for i in range(len_Sp - len_T, -1, -1):
        for j in range(len_T):
            if Sp[i + j] != '?' and Sp[i + j] != T[j]:
                break
        else:
            
            max_i = max(max_i, i)
            restorable = True
if restorable:
    Sp[max_i : max_i + len_T] = T
    print(''.join(Sp).replace('?', 'a'))
else:
    print('UNRESTORABLE')

Solution (Python):
a=input()
b=input()
la=len(a)
lb=len(b)
ans="UNRESTORABLE"
for i in range(la-lb+1):
  k=1
  for j in range(lb):
    if a[i+j]=="?":
      continue
    if a[i+j]!=b[j]:
      k=0
  if k==1:
    ans=i
if ans=="UNRESTORABLE":
  print(ans)
else:
  ans=a[:ans]+b+a[ans+lb:]
  print(ans.replace("?","a"))

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

Solution (Python):
S2 = input()
T = input()
N = len(S2)

Tplace = {i:False for i in range(N)}


for i in range(N-len(T)+1):
  counter = 0
  for j in range(len(T)):
    if S2[i+j] == T[j] or S2[i+j] == "?":     
      counter += 1

      continue
    else:

      break

  if counter == len(T):
    Tplace[i] = True


ans = []

for key, value in Tplace.items():
  if value:
    tmp = S2[:key] + T + S2[key+len(T):] 
    tmp2 = tmp.replace('?', 'a')
    ans.append(tmp2)
ans.sort()
print(ans[0] if len(ans) > 0 else "UNRESTORABLE")

Solution (Python):
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
    else:
            print((sd[:i]+t+sd[i+lt:]).replace('?','a'))
            break
else:
    print('UNRESTORABLE')

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

sl = len(s)
Tl = len(T)
res = "UNRESTORABLE"
for i in range(sl)[::-1]:
    piece = s[i:i+Tl]
    if len(piece)<Tl:
        continue
    flag = True
    for j in range(Tl): 
        if piece[j]!='?' and piece[j]!=T[j]:
            flag = False 
            break
    if flag:
        res = s[:i]+T+s[i+Tl:]
        res = res.replace("?","a")
        break
print(res)

Solution (Python):
ss=input();t=input();lens,lent=len(ss),len(t);k=[]
def sst(sss):
  global t
  for i in range(lent):
    if sss[i]!=t[i] and sss[i]!="?":return -1
  return 0
def ch(s):
  ans=""
  for i in s:ans+=(i if i!="?"else"a")
  return ans
for i in range(lens-lent+1):
  if sst(ss[i:i+lent])==0:k.append(ch(ss[:i]+t+ss[i+lent:]))
if len(k)==0:print("UNRESTORABLE");exit()
k.sort();print(k[0])

Solution (Python):
s = input()
t = input()
lis = []
for i in range(len(s) - len(t) + 1):
    count = 0
    for j in range(len(t)):
        if t[j] == s[i + j] or s[i + j] == '?':
            count += 1
        else:
            break
    if count == len(t):
        temp = s[:i] + t + s[i + len(t):]
        lis.append(temp.replace('?', 'a'))
if len(lis) == 0:
    print('UNRESTORABLE')
else:
    lis.sort()
    print(lis[0])

Solution (Python):



s=input()
t=input()
b=[]

if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)+1):
        ans=s
        for j in range(len(t)):
            flg=True
            if s[i+j]=='?' or s[i+j]==t[j]:
                
                ans=ans[:i+j]+t[j]+('' if i+j+1>len(s) else ans[i+j+1:])
            else:
                flg=False
                break
        if flg==True:
            b.append(ans.replace('?','a'))

b.sort()

print(b[0] if len(b)>0 else 'UNRESTORABLE')

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


if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t),-1,-1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      s=s[0:j]+t+s[j+len(t):]
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

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


errorword = 'UNRESTORABLE'

ls=len(s)
lt=len(t)
if ls < lt:
    print(errorword)
else:
    for i in range(ls-lt,-1,-1):
        is_matched = True
        s_slice = slice(i, i+lt)

        for s_char, t_char in zip(s[s_slice], t):
            
            if (s_char != t_char) and s_char != '?':
                is_matched = False
                break
                
        
        if is_matched:
            temp_sl1 = slice(0, i)
            temp_sl2 = slice(i+lt, ls+1)
            out_str = '{}{}{}'.format(s[temp_sl1], t, s[temp_sl2])
            print(out_str.replace('?', 'a'))
            break
    
    if not is_matched:
        print(errorword)

Solution (Python):
def solve(string):
    s, t = string.split()
    s, t = s[::-1], t[::-1]
    for i in range(len(s)):
        for j in range(min(len(t), len(s) - i)):
            if s[i + j] != t[j] and s[i + j] != "?":
                break
            if j == len(t) - 1:
                return (s[:i] + t + s[i + len(t):])[::-1].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
def solve(string):
    s, t = string.split()
    s, t = s[::-1], t[::-1]
    for i, _ in enumerate(s):
        for j, _ in enumerate(t):
            if not (i + j < len(s)) or (s[i + j] != t[j] and s[i + j] != "?"):
                break
            if j == len(t) - 1:
                return (s[:i] + t + s[i + len(t):])[::-1].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
def solve(string):
    s, t = string.split()
    s, t = s[::-1], t[::-1]
    for i, _ in enumerate(s):
        if s[i] != t[0] and s[i] != "?":
            continue
        for j, _ in enumerate(t):
            if not (i + j < len(s)) or (s[i + j] != t[j] and s[i + j] != "?"):
                break
            if j == len(t) - 1:
                return (s[:i] + t + s[i + len(t):])[::-1].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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


if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t),-1,-1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      if j==0:
        s=t+s[len(t):]
      if 0 < j < len(s)-len(t)+1:
        s=s[0:j]+t+s[j+len(t):]
      if j == len(s)-len(t)+1:
        s=s[0:j]+t      
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Solution (Python):
S = list(input())
T = list(input())
s = len(S)
t = len(T)
ans = ""

for i in reversed(range(s-t+1)):
    for j in range(t):
        if S[i+j] != T[j] and S[i+j] !="?":
            break
        if j == t-1:
            for k in range(t):
                S[i+k] = T[k]
            s = str("".join(S).replace("?","a"))
            print(s)
            exit()
print("UNRESTORABLE")

Solution (Python):
import re

S=input().replace('?','.')
T=input()

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

for i in range(len(S)-len(T)+1): 
  l = len(S)-len(T)-i
  r = len(S)-i
  if re.match(S[l:r], T):
    s = S[:l] + T + S[r:]
    print(s.replace('.','a'))
    exit()

print('UNRESTORABLE')

Solution (Python):
S=input()
T=input()
def check(i):
    flag=True
    for j in range(len(T)):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag=False
            break
    return flag
def search(S,T):
    for i in range(len(S)-len(T),-1,-1):
        if check(i):return i
    return -1
def main(S,T):
    ans=''
    if T not in S:
        idx=search(S,T)
        if idx==-1:
            return 'UNRESTORABLE'
        S=S[:idx]+T+S[idx+len(T):]
    for s in S:
        if s=='?':ans+='a'
        else:ans+=s
    return ans
print(main(S,T))

Solution (Python):
import sys
S = input()
T = input()
Slen = len(S)
Tlen = len(T)
if Tlen > Slen:
    print('UNRESTORABLE')
    sys.exit()
start = Slen + 1
for i in range(Slen - Tlen + 1):
    flg = True
    for j in range(Tlen):
        
        if flg == True:
            if (S[i+j] == T[j]) or (S[i+j] == '?'):
                if j == (Tlen -1) and flg == True:
                    start = i
            else:
                flg = False
if start == (Slen + 1):
    print('UNRESTORABLE')
else:
    S2 = S[:start] + T + S[start+Tlen:]
    S3 = S2.replace("?","a")
    print(S3)

Solution (Python):
s=input()
t=input()
ans=[]
for i in range(0,len(s)-len(t)+1):
  m=[]
  flag=True
  for p in range(i):
    if s[p]=='?':
      m.append('a')
    else:
      m.append(s[p])
  for q in range(i,len(t)+i):
    if s[q]=='?' or s[q]==t[q-i]:
      m.append(t[q-i])
    else:
      flag=False
      break
  for r in range(len(t)+i,len(s)):
    if flag==False:
      break
    if s[r]=='?':
      m.append('a')
    else:
      m.append(s[r])
  if flag:
    ans.append("".join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')

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

print("UNRESTORABLE")

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

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

print("UNRESTORABLE")

Solution (Python):
s = input()
t = input()
ans = []
for i in range(len(t),len(s)+1):
    k = 1
    for j in range(len(t)):
        if t[j]==s[i-len(t):i][j] or s[i-len(t):i][j]=='?':
            pass
        else:
            k = 0
            break
    if not k:
        continue
    m = s[:i-len(t)]+t+s[i:]
    m = m.replace('?','a')
    ans.append(m)
if ans==[]:
    print('UNRESTORABLE')
else:
    print(min(ans))

Solution (Python):
S = input()
T = input()
ns = len(S)
nt = len(T)
if ns - nt < 0:
    print('UNRESTORABLE')
    exit()
answer = []
for i in range(ns - nt + 1):
    ans = ''
    t = True
    for j in range(ns):
        if j < i:
            if S[j] == "?":
                ans = ans + 'a'
            else:
                ans = ans + S[j]
        elif j - i >= nt:
            if S[j] == "?":
                ans = ans + 'a'
            else:
                ans = ans + S[j]

        else:
            if S[j] == "?":
                ans = ans + T[j-i]
            else:
                if S[j] == T[j-i]:
                    ans = ans + T[j-i]
                else:
                    t = False
                    break
    if t:
        answer.append(ans)

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

Solution (Python):
S = input()
T = input()
ls = len(S)
lt = len(T)
flag = False
pos = None
ans = ''

for i in range(ls-lt+1):
  flag = True
  for j in range(lt):
    if S[i+j] != T[j] and S[i+j] != '?':
      flag = False
      break
  if flag:
    pos = i

if pos == None:
  print('UNRESTORABLE')
  exit()

ans = S[:pos] + T + S[pos+lt:]

print(ans.replace('?', 'a'))

Solution (Python):
S = input()
T = input()
ls = len(S)
lt = len(T)
if ls < lt:
    print('UNRESTORABLE')
    exit()

index = -1
for i in range(ls-lt+1):
    cnt = 0
    for j in range(lt):
        s = S[i+j]
        if s == '?':
            cnt +=1
        if s == T[j]:
            cnt +=1
    if cnt == lt:
        index = i
if index == -1:
    print('UNRESTORABLE')
    exit()
S = S[:index] + T + S[index+lt:]
S = S.replace('?', 'a')
print(S)

Solution (Python):
S = input()
T = input()
ls = len(S)
lt = len(T)
if ls < lt:
    print('UNRESTORABLE')
    exit()

index = -1
for i in range(ls-lt+1):
    cnt = 0
    for j in range(lt):
        s = S[i+j]
        if s == '?':
            cnt +=1
        if s == T[j]:
            cnt +=1
    if cnt == lt:
        index = i
if index == -1:
    print('UNRESTORABLE')
    exit()
S = S[:index] + T + S[index+lt:]
S = S.replace('?', 'a')
print(S)

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

Solution (Python):
""" AtCoder """

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

s = len(S)
t = len(T)
p = []

check = True
for i in range(s - t + 1):
    for j in range(t):
        if S[i + j] != T[j] and S[i + j] != '?':
            check = False
            break
    if check:
        p.append(i)
    check = True

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

ans = S[:p[0]] + T + S[p[0] + t:]
for j in range(s):
    if ans[j] == '?':
        ans[j] = 'a'

for i in range(len(p)):
    tmp = S[:p[i]] + T + S[p[i] + t:]
    for j in range(s):
        if tmp[j] == '?':
            tmp[j] = 'a'
    if tmp < ans:
        ans = tmp

print("".join(ans))

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]!='?'and s[i+j]!=t[j]:
            break
    else:
        print((s[:i]+t+s[i+len(t):]).replace('?','a'))
        break
else:
    print('UNRESTORABLE')

Solution (Python):
import re
S=input()
T=input()
position=-100
ans=''
for i in range(len(S)-len(T)+1):
	
	if i==0:
		regexp=r'%s' % S[-(len(T)):].replace('?','\w')
	else:
		regexp=r'%s' % S[-(i+len(T)):-i].replace('?','\w')
	if len(re.compile(regexp).findall(T))==1:
		position=i
		break
if position==-100:
	ans='UNRESTORABLE'
elif position==0:
	ans = S[:-(len(T))].replace('?','a') + T
else:
	ans=S[:-(position+len(T))].replace('?','a') + T + S[-(position):].replace('?','a')
print(ans)

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

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


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

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

Solution (Python):
s=input()
t=input()
ans="UNRESTORABLE"
for i in range(len(s)-len(t)+1):
  flag=True
  for j in range(len(t)):
    if s[i+j]==t[j] or s[i+j]=="?":
      continue
    else:
      flag=False
  if flag:
    ans=s[:i]+t+s[i+len(t):]
    ans=ans.replace("?","a")
print(ans)

Solution (Python):
import sys
s = list(input())
t = list(input())
for i in range(len(s) - len(t) + 1):
    cut_char = s[len(s)-len(t)-i:len(s)-i]
    for j in range(len(t)):
        if cut_char[j] == t[j] or cut_char[j] == '?':
            if j == len(t)-1:
                for k in range(len(t)):
                    s[len(s)-len(t)-i+k] = t[k]
                ans = [tmp.replace('?', 'a') for tmp in s]
                print(''.join(ans))
                sys.exit()
        else:
            break
print('UNRESTORABLE')

Solution (Python):
def equal_or_wildcard(s: str, t: str)->bool:
    for cs, ct in zip(s, t):
        if cs != '?' and cs != ct:
            return False
    return True


def dubious_document2(S: str, T: str)->str:
    ns, nt = len(S), len(T)
    for i in range(ns - nt, -1, -1):
        if equal_or_wildcard(S[i:i+nt], T):
            return (S[:i] + T + S[i+nt:]).replace('?', 'a')
    return 'UNRESTORABLE'


if __name__ == "__main__":
    S = input()
    T = input()
    ans = dubious_document2(S, T)
    print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
from operator import itemgetter

S1 = input()
T = input()

idx = 100

for i in range(len(S1)-len(T)+1):
    for j in range(len(T)):
        if S1[i+j] == T[j] or S1[i+j] == '?':
            if j == len(T)-1:
                idx = i
            continue
        else:
            break

if idx == 100:
    print("UNRESTORABLE")
    exit()
    
S1 = S1[:idx] + T + S1[idx+len(T):]
S1 = S1.replace('?', 'a')
print(S1)