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

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

for i in range(ls - lt, -1, -1):
    isok = True
    for j in range(lt):
        if S[i + j] == "?":
            continue
        if S[i + j] != T[j]:
            isok = False
            break
    if isok:
        S[i:i+lt] = T
        ans = ""
        for s in S:
            if s == "?":
                ans += "a"
            else:
                ans += s
        print(ans)
        exit()

print("UNRESTORABLE")

Solution (Python):
S = list(input())
T = list(input())
NS,NT = len(S),len(T)
outs = []
if NS>=NT:
    for i in range(NS-NT+1):
        flag = 0
        for j in range(NT):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                flag = 1
                break
        if flag==0:
            out = ["a"]*NS
            for j in range(NT):
                out[i+j]=T[j]
            for j in range(NS):
                if S[j]!="?":
                    out[j]=S[j]
            outs.append("".join(out))

if len(outs) == 0:
    print("UNRESTORABLE")
else:
    print(outs[-1])

Solution (Python):
S = list(input())
T = list(input())
NS,NT = len(S),len(T)
outs = []
if NS>=NT:
    for i in range(NS-NT+1):
        flag = 0
        for j in range(NT):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                flag = 1
                break
        if flag==0:
            out = ["a"]*NS
            for j in range(NT):
                out[i+j]=T[j]
            for j in range(NS):
                if S[j]!="?":
                    out[j]=S[j]
            outs.append("".join(out))

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

Solution (Python):
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array







sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    T = iss()

    ret = set()
    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s == t or s == '?': continue
            else: break
        else:
            tmp = ''
            if i != 0: tmp += S[:i]
            tmp += T
            if i+len(T) < len(S): tmp += S[i+len(T):]
            ret.add(tmp.replace('?', 'a'))

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


if __name__ == '__main__':
    main()

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

Solution (Python):

"""
Created on Mon Sep 28 02:20:36 2020

@author: liang
"""
S = input()
T = input()

S = S[::-1]
T = T[::-1]

res = list()

for i in range(len(S)-len(T)+1):
    flag = True
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            continue
        else:
            flag = False
    if flag == True:
        ans = ""
        for k in range(len(S)):
            if i <= k <= i + len(T)-1:
                
                ans += T[k-i]
            elif S[k] != "?":
                
                ans += S[k]
            else:
                
                ans += "a"
        ans = ans[::-1]
        print(ans)
        break
        
else:
    print("UNRESTORABLE")
"""
if res:
    res.sort()
    print(res[0])
else:
    print("UNRESTORABLE")
"""

Solution (Python):

"""
Created on Mon Sep 28 02:20:36 2020

@author: liang
"""
S = input()
T = input()

S = S[::-1]
T = T[::-1]

res = list()

for i in range(len(S)-len(T)+1):
    flag = True
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            continue
        else:
            flag = False
    if flag == True:
        ans = ""
        for k in range(len(S)):
            if i <= k <= i + len(T)-1:
                
                ans += T[k-i]
            elif S[k] != "?":
                
                ans += S[k]
            else:
                
                ans += "a"
        ans = ans[::-1]
        res.append(ans)

if res:
    res.sort()
    print(res[0])
else:
    print("UNRESTORABLE")

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False
ans = []

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-len_t+1]+T+aaa[i+1:])
    elif S[i] in T:
        cnt = 0
        place = T.index(S[i])
        if len_s<len_t+i-place:
            break
        for j in range(i-place,len_t+i-place):
            if T[j-(i-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                break
        if check:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-place]+T+aaa[len_t+i-place:])
    else:
        cnt = 0

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

Solution (Python):
s=list(input())
t=list(input())
num=len(s)-len(t)
ans1=-1
for i in range(num+1):
    num1=0
    num2=num-i
    for j in range(len(t)):
        if s[num2+j]!=t[j] and s[num2+j]!="?":
            num1=1
            break
    if num1==0:
        ans1=num2
        break
if ans1==-1:
    print("UNRESTORABLE")
else:
    ans=""
    for i in range(len(t)):
        s[ans1+i]=t[i]
    for i in range(len(s)):
        if s[i]=="?":
            s[i]="a"
        ans+=s[i]
    print(ans)

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

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

ind = None
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]:
            continue
        else:
            break
    else:
        ind = i

if ind == None:
    print('UNRESTORABLE')
else:
    ans = list(S)
    for i in range(ind,ind+len(T)):
        ans[i] = T[i-ind]
    for i in range(len(ans)):
        if ans[i] == "?":
            ans[i] = "a"
    print("".join(ans))

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


for i in range(len(s)-len(t), -1, -1):
    st = s[i:i+len(t)]
    cnt = 0
    for si, ti in zip(st, t):
        if si == '?' or si == ti:
            cnt += 1
        
    if cnt == len(t):
        ans = s[:i] + t + s[i+len(t):]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()
else:
    print('UNRESTORABLE')

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

ans_list=[]
for i in range(len(S)-len(T)+1):
    X=S[i:i+len(T)]
    isOK=True
    for j in range(len(T)):
        if X[j]=="?" or X[j]==T[j]:
            pass
        else:
            isOK=False
            break
    
    if isOK:
        ans=S[:i]+T+S[i+len(T):]
        
        ans=ans.replace('?','a')
        ans_list.append(ans)

if len(ans_list)<1:
    print("UNRESTORABLE")
else:
    ans_list.sort()
    print(ans_list[0])

Solution (Python):
s = input()
n = len(s)
t = input()
m = len(t)
ans = []

for i in range(n-m+1):
    for j in range(m):
        if s[i+j] not in [t[j] , "?"]:
            break
        elif j == m-1:
            res = s[:i]+t+s[i+m:]
            ans.append(res.replace("?","a"))

if not ans:
    ans.append("UNRESTORABLE")

print(min(ans))

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

N = len(_S)
M = len(T)

candidates = []

for i in range(N - M + 1):
    if _S[i] == '?' or _S[i] == T[0]:
        S = _S.copy()
        flg = True
        for j in range(M):
            if S[i + j] == '?':
                S[i + j] = T[j]
            elif S[i + j] != T[j]:
                flg = False
                break
        if flg:
            for k in range(N):
                if S[k] == '?':
                    S[k] = 'a'
            candidates.append(''.join(S))

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

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

ls = len(ss)
lt = len(t)

before = []
after = []

for i in range(ls-lt+1):
    for j in range(lt):
        if ss[i+j]!="?":
            if ss[i+j]!=t[j]:
                break
    else:
        before += [ss[:i]+t+ss[i+lt:]]
  
for k in before:
    after += [k.replace("?","a")]

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

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

ans = True
for i in range(len(S)):
    flag = True
    for j in range(len(T)):
        if i + j >= len(S):
            flag = False
            break
        if S[i+j] == '?' or S[i+j] == T[j]:
            pass
        else:
            flag = False
            break
    if flag:
        candidate.append(i)
        ans = False

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

i = candidate[-1]
for tmp in range(i, i + len(T)):
    S[tmp] = T[tmp-i]


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

print(''.join(S))

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

indexes = []
for i in range(len(Sd)):
    if Sd[i] != "?":
        indexes.append(i)

t0 = 0
S_list = []
while t0 <= (len(Sd)-len(T)):
    flg = 0
    tmp_S = Sd[:t0] + T + Sd[t0+len(T):]

    
    for index in indexes:
        if Sd[index] != tmp_S[index]:
            flg = 1
    if flg:
        t0 += 1
        continue

    
    tmp_S = tmp_S.replace('?', 'a')
    S_list.append(tmp_S)
    t0 += 1

if not S_list:
    print("UNRESTORABLE")
    exit()

S_list.sort()
print(S_list[0])

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

ans=0
for i in range(ls-lt+1):
  x=s[:i]+t+s[i+lt:ls]
  f=1
  for j in range(ls):
    if s[j]=='?':
      continue
    if s[j]!=x[j]:
      f=0
      break
  if f:
    p=''
    for k in range(ls):
      if x[k]=='?':
        p+='a'
      else:
        p+=x[k]
    ans=p
    
if ans:
  print(p)
else:
  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()
 
ls = len(S)
lt = len(T)
left = -1
 
for i in range(ls-lt+1):
    for j in range(lt):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
       left = i
if left == -1:
    ans = "UNRESTORABLE"
else:
    ans = S[:left]+T+S[left+lt:]
    ans = ans.replace("?", "a")
print(ans)

Solution (Python):
import sys












stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    s = str(stdin.readline().rstrip())
    t = str(stdin.readline().rstrip())
    
    
    
    
    
    
    anss = []
    for i in range(len(s)-len(t)+1):
        test = s[i:len(t)+i]
        flag = True
        for j in range(len(t)):
            if test[j] != "?" and test[j] != t[j]:
                flag = False
        if flag==True:
            ans = s[0:i] + t + s[i+len(t):]
            ans = ans.replace("?","a")
            anss.append(ans)
    if len(anss) == 0:
        print("UNRESTORABLE")
        exit()
    anss.sort()
    print(anss[0])


if __name__ == '__main__':
    solve()

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

s=''.join([x if x!='?' else '1' for x in list(s)])

start=[]
for i in range(len(s)-len(T)+1):
    tmp=0
    for j in range(len(T)):
        if s[i+j]==T[j] or s[i+j]=='1': tmp+=1
    if tmp==len(T): start.append(i)

candidates=[]
t=len(T)
ans=''
if len(start):
    for st in start:
        tmp=s[:st]+T+s[st+t:]
        candidates.append(tmp)
    candidates.sort()
    ans=candidates[0].replace('1','a')
else:
    ans='UNRESTORABLE'

print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S_ = SS()
    T = SS()

    len_S = len(S_)
    len_T = len(T)

    
    idx = -1
    for i in range(len_S - len_T, -1, -1):
        exists = True
        for j in range(len_T):
            if S_[i+j] != '?' and S_[i+j] != T[j]:
                exists = False
                break
        if exists:
            idx = i
            break

    if idx == -1:
        print('UNRESTORABLE')
    else:
        ans = list(S_)
        for i in range(len_S):
            if S_[i] == '?':
                if idx <= i < idx + len_T:
                    ans[i] = T[i-idx]
                else:
                    ans[i] = 'a'

        print(''.join(ans))

if __name__ == '__main__':
    resolve()

Solution (Python):
s=input()
t=input()
ls=len(s)
lt=len(t)
f=False
for i in range(ls-lt,-1,-1):
  f=True
  for j in range(lt):
    if not(s[i+j]=="?" or s[i+j]==t[j]):
      f=False
      break
  if f:
    ns=s[:i]+t+s[i+lt:]
    print("".join(map(lambda x:"a" if x=="?" else x,list(ns))))
    break
if not f:
  print("UNRESTORABLE")

Solution (Python):
S=input()
T=input()
N=len(S)
n=len(T)
ans=[]
for i in range(N-n+1):
    for j in range(n):
        if S[i+j]!=T[j] and S[i+j]!='?':
            break
    else:
        s=[]
        for j in range(i):
            if S[j]=='?':
                s.append('a')
            else:
                s.append(S[j])
        for j in range(i,i+n):
            s.append(T[j-i])
        for j in range(i+n,N):
            if S[j]=='?':
                s.append('a')
            else:
                s.append(S[j])
        ans.append(''.join(s))

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

Solution (Python):
import sys

def accept_input():
    S = input()
    T = input()
    return S,T

S,T = accept_input()
fromhere = -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]:
            continue
        elif S[i+j] != T[j]:
            break
    else:
        fromhere = i
if fromhere == -1:
    print("UNRESTORABLE")
    sys.exit()
sd = ""
for i in range(len(S)):
    if i < fromhere:
        if S[i] == "?":
            sd += "a"
        else:
            sd += S[i]
    elif i >= fromhere+len(T):
        if S[i] == "?":
            sd += "a"
        else:
            sd += S[i]
    else:
        sd += T[i-fromhere]
print(sd)

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

ls = len(S)
lt = len(T)
left = -1

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

Solution (Python):

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

lens=len(s)
lent=len(t)

for i in reversed(range(lens-lent+1)):
  x=s[i:i+lent]
  ans=s
  flag=True
  
  for j in range(lent):
    if x[j]!=t[j] and x[j]!="?":
      flag=False
      break
    
    
    
    
  if flag:
    
    
    
    
    
    ans=["a" if a=="?" else a for a in ans[:i]]+\
    	t+["a" if a=="?" else a for a in ans[i+lent:]]
    print("".join(ans))
    exit()
print("UNRESTORABLE")

Solution (Python):
S = input()
Sa = S.replace("?", "a")
T = input()
nt = len(T)
ans = list()
for i in range(len(S) - nt + 1):
    X = S[i: i + nt]
    for x, t in zip(X, T):
        if x == "?":
            continue
        if x != t:
            break
    else:
        ans.append(Sa[:i] + T + Sa[i + nt:])
ans.sort()
print(ans[0] if ans else "UNRESTORABLE")

Solution (Python):
S = input()
T = input()
def solve(i):
  flag = True
  for j in range(len(T)):
    if i+j < len(S) and (S[i+j] == "?" or S[i+j] == T[j]):
      continue
    else:
      flag = False
      break
  return flag
anslist = []
for i in range(len(S)):
  if solve(i):
    anstmp = S[:i] + T + S[i+len(T):]
    anstmp = anstmp.replace("?", "a")
    anslist.append(anstmp)
if len(anslist) > 0:
  anslist.sort()
  ans = anslist[0]
else:
  ans = "UNRESTORABLE"
print(ans)

Solution (Python):

def main():
    with open(0) as f:
        S, T = f.read().split()
    for i in reversed(range(len(S)-len(T)+1)):
        for j in reversed(range(len(T))):
            if S[i+j] == T[j] or S[i+j] == '?':
                continue
            else:
                break
        else:
            S = S[:i] + T + S[i+len(T):]
            S = S.replace('?', 'a')
            print(S)
            break
    else:
        print('UNRESTORABLE')

main()

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

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

Solution (Python):
s=list(input())
ls=len(s)
t=list(input())
lt=len(t)
can=[]
for i in range(ls-lt,-1,-1):
    ok=0
    for j in range(lt):
        if s[i+j]==t[j] or s[i+j]=='?':
            ok+=1
    if ok==lt:
        c=[0]*ls
        for k in range(ls):
            if s[k]=='?':
                if k<i or k>=i+lt:
                    c[k]='a'
                else:
                    c[k]=t[k-i]
            else:
                c[k]=s[k]
        can.append(''.join(c))
if len(can)==0:
    print('UNRESTORABLE')
else:
    print(sorted(list(can))[0])

Solution (Python):
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    S: str = input().strip()
    T: str = input().strip()
    last_i = -1
    for i in range(len(S)-len(T)+1):
        matches = True
        for t in range(len(T)):
            s = i+t
            if S[s] == '?':
                continue
            elif S[s] != T[t]:
                matches = False
                break
        if matches:
            last_i = i
    if last_i == -1:
        return 'UNRESTORABLE'
    answer = list(S)
    for i in range(last_i, last_i+len(T)):
        answer[i] = T[i-last_i]
    for i in range(len(S)):
        if answer[i] == '?':
            answer[i] = 'a'
    return ''.join(answer)


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

Solution (Python):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def can_replace(S, T):
    cnt = 0
    for s, t in zip(S, T):
        if s == t or s == '?':
            cnt += 1
    if cnt == len(S):
        return True
    else:
        return False


def main():
    S = list(ns()[::-1])
    T = list(ns()[::-1])
    for i in range(len(S) - len(T) + 1):
        if can_replace(S[i:i + len(T)], T):
            S[i:i + len(T)] = T
            S = ''.join(S)
            print(S.replace('?', 'a')[::-1])
            return
    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

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

Solution (Python):

S = input()
T = input()
candidates = list()
for i in range(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
            break
    if flag:
        s = S[:i] + T + S[i+j+1:]
        candidates.append(s.replace("?", "a"))
if candidates:
    candidates.sort()
    print(candidates[0])
else:
    print("UNRESTORABLE")

Solution (Python):

from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


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





def LI(): return list(map(int, sys.stdin.buffer.readline().split()))




def I(): return int(sys.stdin.buffer.readline())





def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()




def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')







def IR(n): return [I() for i in range(n)]







def LIR(n): return [LI() for i in range(n)]







def SR(n): return [S() for i in range(n)]







def LSR(n): return [LS() for i in range(n)]







def SRL(n): return [list(S()) for i in range(n)]


def main():
    s = S()
    t = S()
    ans = ""
    flg = 1

    if len(t) > len(s):
        print("UNRESTORABLE")
        return

    for i in range(len(s) - len(t), -1, -1):
        flg = 1
        clipped = s[i:i+len(t)]
        for j in range(len(t)):
            if clipped[j] != t[j] and clipped[j] != "?":
                flg = 0
                break
        if flg:
            ans = s[:i].replace("?", "a") + t + \
                s[i + len(t):].replace("?", "a")
            break

    if not flg:
        print("UNRESTORABLE")
        return
    print(str(ans))


if __name__ == "__main__":
    main()

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

n = len(S)
l = len(T)

for i in range(n-l+1)[::-1]:
  cnt = 0
  for j in range(l):
    if S[i+j] == "?" or S[i+j] == T[j]:
      cnt += 1
  
  if cnt == l:
    S = list(S[:i] + T + S[i+l:])
    for k in range(n):
      if S[k] == "?":
        S[k] = "a"
    print("".join(S))
    break
    
else:
  print("UNRESTORABLE")

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

for i in range(len(s) - len(t) + 1)[::-1]:
    cnt = 0
    q = 0
    for j in range(len(t))[::-1]:
        if s[i + j] == '?':
            q += 1
        elif s[i + j] == t[j]:
            cnt += 1
    
    if cnt == len(t) - q:
        idx = i
        s = s[:idx] + t + s[idx + len(t):]
        for k in range(len(s)):
            if s[k] == '?':
                s = s[:k] + 'a' + s[k + 1:]
        print(s)
        break
else:
    print('UNRESTORABLE')

Solution (Python):
s = list(input())
t = list(input())
s.reverse()
t.reverse()
l = len(t)
ld = len(s)-len(t)+1
for i in range(ld):
    cnt = 0
    for j in range(l):
        if s[j+i] == "?" or s[j+i] == t[j]:
            cnt += 1
    if cnt == l:
        ans = []
        for p in range(i):
            if s[p] == "?":
                ans.append("a")
            else:
               ans.append(s[p])
        for p in t:
            ans.append(p)
        for p in range(ld-i-1):
            if s[l+p+i] == "?":
                ans.append("a")
            else:
                ans.append(s[l+i+p])
        ans.reverse()
        for p in ans:
            print(p,end = "")
        break
            
else:
    print("UNRESTORABLE")

Solution (Python):
s = input()
n = len(s)
t = input()
m = len(t)

if n < m:
    print("UNRESTORABLE")
    exit()
p = False
for i in reversed(range(n-m+1)):
    flag = True
    for j in range(m):
        if s[i+j] != "?" and s[i+j] != t[j]:
            flag = False
            break
    if flag:
        s = s[:i] + t + s[i+m:]
        p = True
        break

if not p:
    print("UNRESTORABLE")
    exit()
elif p:
    for i in range(n):
        if s[i] == "?":
            s = s[:i] + "a" + s[i+1:]
print(s)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


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

    s_len = len(s)
    t_len = len(t)
    flg = False

    for i in range(s_len - t_len,-1,-1):
        flg = True
        for j in range(t_len):
            if s[i+j] != t[j] and s[i+j] != "?":
                flg = False
                break
        if flg == True:
            trial = i
            break

    if flg == False:
        print("UNRESTORABLE")
        exit()

    ans = ""
    for i in s[:trial]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i
    ans = ans + t

    for i in s[(trial+t_len):]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i

    print(ans)














if __name__=="__main__":
    main()

Solution (Python):
S = input()
T = input()
len_S, len_T = len(S), len(T)
ans = []
for i in range(len_S-len_T+1):
	f = True
	for j in range(len_T):
		if S[i+j] != T[j] and S[i+j] != '?':
			f = False
			break
	if f:
		s = S[:i] + T + S[i+j+1:]
		ans.append(s.replace('?', 'a'))
if len(ans) == 0:
	print('UNRESTORABLE')
else:
	ans.sort()
	print(ans[0])

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

S=input()
s=len(S)
T=input()
t=len(T)
ans='UNRESTORABLE'
if s<t:
    print(ans)
    exit()
for i in range(s-t,-1,-1):
    for j in range(t):
        tmp=True
        if S[i+j] not in ['?',T[j]]:
            tmp=False
            break
    if tmp:
        print(S[:i].replace('?','a'),end='')
        print(T,end='')
        print(S[i+t:].replace('?','a'))
        exit()
print(ans)

Solution (Python):
a = input()
b = input()

length = len(a) - len(b) + 1

ans = []
for i in range(length):
    A = list('?'*i+b+'?'*(length-i-1))
    flag = True
    for j in range(len(a)):
        if a[j] == '?' or a[j] == A[j]:
            pass
        elif a[j] != '?' and A[j] == '?':
            A[j] = a[j]
        else:
            flag = False
    if flag:
        ans.append(''.join(A).replace('?','a'))

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

Solution (Python):
S=input()
T=input()
L,M=len(S),len(T)
a=-1
for i in range(L-M,-1,-1):
    if sum([1 for j in range(M) if S[i+j]=='?' or S[i+j]==T[j]])==M:
        a=i
        break
print('UNRESTORABLE' if a<0 else ''.join([T[i-a] if a<=i<a+M else 'a' if S[i]=='?' else S[i] for i in range(L)]))