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

s = s[::-1]
t = t[::-1]

for i in range(len(s) - len(t) + 1):
    for j, v in enumerate(t):
        if s[j+i] == v or s[j+i] == "?":
            continue
        else:
            break
    else:
        l = len(t)
        s = s[0:i] + t + s[i+l:]
        break
else:
    print("UNRESTORABLE")
    exit()

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

print(s[::-1])

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

ans = 'UNRESTORABLE' 

def match(k):
    for i in range(len(T)):
        if T[i] != S[i+k] and S[i+k] != '?':
            return False
    return True

def construct(k):
    ans = []
    for i in range(len(S)): ans.append(S[i])
    for i in range(len(T)): ans[i+k] = T[i]
    for i in range(len(S)):
        if ans[i] == '?':
            ans[i] = 'a'
    return ans

for i in range(len(S)-len(T)+1):
    if match(i):
        ans=construct(i)

for i in range(len(ans)):
    print(ans[i], end='')
print()

Solution (Python):
from collections import Counter
from collections import deque
import math
import bisect
import sys
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
t=input()
ls=len(s)
lt=len(t)
l=[]
ans=[]
for i in range(ls-lt+1):
    ch=True
    for k in range(lt):
        if s[i+k]!=t[k] and s[i+k]!="?":
            ch=False
    if ch:
        l.append(list(s[:i]+t+s[i+lt:]))
if len(l)==0:
    print("UNRESTORABLE")
    exit()
for i in range(len(l)):
    for k in range(ls):
        if l[i][k]=="?":
            l[i][k]="a"
ans=sorted(l)
print(*ans[0],sep="")

Solution (Python):
import re
s=str(input())
s = s.replace('?', '.')
t=str(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()
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):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(input())[::-1]
t = list(input())[::-1]
n = len(s)
m = len(t)
res = []
for i in range(n-m+1):
    for j in range(m):
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        for k in range(n):
            if i <= k < i+m:
                res.append(t[k-i])
            else:
                if s[k] == '?':
                    res.append('a')
                else:
                    res.append(s[k])
        print(''.join(res[::-1]))
        break
else:
    print('UNRESTORABLE')

Solution (Python):
s=list(input())
t=list(input())
flag=False
ata=0
for i in range(len(s)-len(t)+1):
  if flag==True:
    break
  for j in range(len(t)):
    if s[len(s)-1-(i+j)]!="?" and s[len(s)-1-(i+j)]!=t[len(t)-1-j]:
      break
    if j==(len(t)-1):
      flag=True
      ata=i
if flag==True:
  for i in range(len(t)):
    s[len(s)-1-(ata+i)]=t[len(t)-1-i]
  for i in range(len(s)):
    if s[i]=="?":
      s[i]="a"
  print("".join(s))
else:
  print("UNRESTORABLE")

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

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

for i in range(n - m, -1, -1):
    a = sd[i:i + m]
    ok = True
    for j in range(m):
        if a[j] != "?" and a[j] != t[j]:
            ok = False
            break

    if ok:
        print(sd[:i].replace("?", "a") + t + sd[i + m:].replace("?", "a"))
        exit()

print("UNRESTORABLE")

Solution (Python):
S1 = list(input().strip())
T = list(input().strip())
n = len(S1)
k = len(T)
G = []
for i in range(n-k+1):
    flag = 0
    for j in range(i,i+k):
        if S1[j]!="?" and S1[j]!=T[j-i]:
            flag = 1
            break
    if flag==0:
        A = S1[:]
        A[i:i+k] = T[:]
        for j in range(n):
            if A[j]=="?":
                A[j] = "a"
        G.append(A)
G = sorted(G)
if len(G)>0:
    print("".join(G[0]))
else:
    print("UNRESTORABLE")

Solution (Python):
import sys
S = str(input())
ls = len(S)
T = str(input())
lt = len(T)

if lt > ls:
  print("UNRESTORABLE")
  sys.exit()

ans = ""
for i in range(ls-lt+1):
  Flag = True
  for j in range(lt):
    
    if S[-1-i-j] == T[-1-j] or S[-1-i-j] == "?":
      continue
    else:
      Flag = False
  if Flag:
    now = i 
    break
if not Flag:
  print("UNRESTORABLE")
  sys.exit()  
now = ls - now -lt

ans = S[:now]+T+S[now+lt:]
for i in range(len(ans)):
  if ans[i] == "?":
    ans = ans[:i]+"a"+ans[i+1:]
print(ans)

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

N=len(S)
TN=len(T)
ans="z"*51
if N<TN:
    print("UNRESTORABLE")
    exit()
for i in range(N-TN+1):
    
    ok=True
    for j in range(TN):
        if S[i+j]==T[j] or S[i+j]=="?":
            continue
        else:
            ok=False
            break
    if ok:
        now=S[:i].replace("?", "a")+T+S[i+TN:].replace("?", "a")
        ans=min(now, ans)

if ans=="z"*51:
    ans="UNRESTORABLE"
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  





S = input()
T = input()
for i in range(len(S) - len(T), -1, -1):  
    sub = S[i:i + len(T)]
    is_ok = True
    for s, t in zip(sub, T):
        if s == '?':
            continue
        if s == t:
            continue
        else:
            is_ok = False
            break
    if is_ok:
        break
else:
    print('UNRESTORABLE')
    exit()

ans = S[:i] + T + S[i + len(T):]
ans = ans.replace('?', 'a')
print(ans)

Solution (Python):
from copy import deepcopy

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

NS = len(S)
NT = len(T)

lst = []

for i in range(NS - NT + 1): 
    
    tmp = deepcopy(S)
    flag = True
    for j in range(i):
        if tmp[j] == '?':
            tmp[j] = 'a'
    for j in range(NT):
        if tmp[i + j] == '?':
            tmp[i + j] = T[j]
        elif tmp[i + j] == T[j]:
            continue
        else:
            flag = False
            break
    for j in range(i + NT, NS):
        if tmp[j] == '?':
            tmp[j] = 'a'
    if flag:
        lst.append(''.join(tmp))

lst.sort()

if lst:
    print (lst[0])
else:
    print ('UNRESTORABLE')

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    t = input()
    n = len(s)

    res = []
    for i in range(n):
        ss = list(s)
        if (s[i] == t[0] or s[i] == "?") and i + len(t) <= n:
            pos = 0
            for j in range(i, i + len(t)):
                if s[j] != "?" and s[j] != t[pos]:
                    break
                pos += 1
            else:
                pos = 0
                for j in range(i, i + len(t)):
                    ss[j] = t[pos]
                    pos += 1
                ss = "".join(ss).replace("?", "a")
                res.append(ss)

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


if __name__ == '__main__':
    resolve()

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

for i in range(len(SP)-len(T),-1,-1):
  cnt = 0
  for j in range(len(T)):
    if SP[i+j] == T[j] or SP[i+j] == "?":
      cnt = cnt +1
  if cnt == len(T):
    S = (SP[:i] + T + SP[i+len(T):]).replace("?","a")
    break

if S == "":
  print("UNRESTORABLE")
else:
  print(S)

Solution (Python):
def main():
    s = input()
    t = input()
    
    s = s.replace('?','.')
    import re
    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):])
            return 0
    print('UNRESTORABLE')
 
if __name__ == '__main__':
    main()

Solution (Python):
s = input()
n = len(s)
t = input()
nagasa = len(t)
ans = ""
okflag = 0
for i in range(n - nagasa + 1):
    temp = True
    for j in range(nagasa):
        if s[i + j] == "?":
            continue
        else:
            if s[i + j] == t[j]:
                temp = True
            else:
                temp = False
        if temp is False:
            break
    if temp is True:
        okflag = 1
        start = i
if okflag:
    for i in range(n):
        if i >= start and i < start + nagasa:
            ans += t[i - start]
        else:
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
else:
    ans = "UNRESTORABLE"
print(ans)

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

ans = []
for l in range(len(S) - len(T) + 1):
    U = S[l: l + len(T)]
    for u, t in zip(U, T):
        if u == '?':
            continue
        if u != t:
            break
    else:
        ans.append((S[:l] + T + S[l + len(T):]).replace('?', 'a'))

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

Solution (Python):



def main():
    Sd = input()
    T = input()
    rp = len(Sd)-len(T)
    ret = []
    for i in range(rp+1):
        Td = ('?'*i) + T + ('?' * (rp-i))
        Tr = ''
        for i, c in enumerate(Sd):
            d = Td[i]
            if c == '?' and d=='?':
                Tr+='a'
            elif c == '?' and d!='?':
                Tr+=d
            elif c != '?' and d=='?':
                Tr+=c
            elif c == d:
                Tr+=d
            else:
                break
        if len(Tr)==len(Sd):
            ret.append(Tr)
    if len(ret)==0:
        print('UNRESTORABLE')
    else:
        ret.sort()
        print(ret[0])

if __name__ == '__main__':
    main()

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

match = True

for i in range(len(s)):
    match = True
    if len(s) < len(t) + i:
        match = False
        break

    if s[i] == t[0] or s[i] == '?':

        for j in range(len(t)):
            if not (s[i + j] == t[j] or s[i + j] == '?'):
                match = False

        if match:
            for j in range(len(t)):
                s[i + j] = t[j]
            break

if match:
    print(''.join(reversed(s)).replace('?', 'a'))
else:
    print('UNRESTORABLE')

Solution (Python):

import sys


def input(): return sys.stdin.readline()[:-1] 



def solve():
    s = [x for x in input()]
    t = [x for x in input()]
    n = len(s)
    m = len(t)
    l = -1
    for i in range(n - m + 1):
        ok = 1
        for j in range(m):
            if s[i+j] != t[j] and s[i+j] != '?':
                ok = 0
        if ok:
            l = i
    if l == -1:
        print("UNRESTORABLE")
    else:
        for j in range(m):
            s[j+l] = t[j]
        for i in range(n):
            if s[i] == '?':
                s[i] = 'a'
        
        print(''.join(s))



t = 1

for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)

"""

Solution (Python):
def resolve():
    '''
    code here
    '''
    S_dash = input()[::-1]
    T = input()[::-1]

    is_flag = False

    res = ''

    for i in range(len(S_dash)):
        res = S_dash[:i]
        
        if len(S_dash) - len(res) >= len(T):
            for j in range(len(T)):
                if S_dash[i+j] == T[j] or S_dash[i+j] == '?':
                    res += T[j]
                else:
                    
                    break
            else:
                is_flag = True
                break

        

    
    
    res = res + S_dash[len(T)+i:]
    res = res.replace('?','a')

    print(res[::-1]) if is_flag else print('UNRESTORABLE')     

if __name__ == "__main__":
    resolve()

Solution (Python):
def resolve():
    '''
    code here
    '''
    S_dash = input()
    T = input()

    is_flag = False

    res = ''
    res_list = ['zzzzz']
    for i in range(len(S_dash) - len(T) +1):
        res = S_dash[:i]
        
        if len(S_dash) - len(res) >= len(T):
            for j in range(len(T)):
                if S_dash[i+j] == T[j] or S_dash[i+j] == '?':
                    res += T[j]
                else:
                    
                    break
            else:
                is_flag = True
                res += S_dash[i+len(T):]
                res_list.append(res)


    

    res2_list = []
    for res in res_list:
        res = res.replace('?','a')
        res2_list.append(res)

    res2_list.sort()
    res = res2_list[0]

    print(res) if is_flag else print('UNRESTORABLE')     

if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import deque
import re
s = input()
t = input()

d = deque()
for i, ch in enumerate(s[::-1]):
    d.appendleft('.' if ch == '?' else ch)
    if len(d) < len(t):
        continue
    if re.match(''.join(list(d)[:len(t)]), t):
        ans = s[:len(s) - i - 1] + t + s[len(s) - i - 1 + len(t):]
        print(ans.replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Solution (Python):
import re
import sys


def main():
    s = sys.stdin.readline().rstrip().replace("?", ".")
    t = sys.stdin.readline().rstrip()

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

    for i in range(n - m + 1):
        if i == 0:
            tmp1 = ""
        else:
            tmp1 = s[:i]
        tmp2 = s[i : i + m]
        if i + m == n:
            tmp3 = ""
        else:
            tmp3 = s[i + m :]
        if re.fullmatch(tmp2, t):
            tmp2 = t
            tmp = tmp1 + tmp2 + tmp3
            ans.append(tmp)
    ans.sort()

    if ans:
        print(ans[0].replace(".", "a"))
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import deque, Counter, defaultdict
from itertools import permutations
import heapq


def resolve():
    S = list(sys.stdin.readline().strip())
    T = list(sys.stdin.readline().strip())
    left = len(S) - len(T)
    right = len(S) - 1
    restorable = True
    while left >= 0:
        for cur in range(left, right + 1):
            if S[cur] != T[cur-left] and S[cur] != '?':
                break
        else:
            
            for cur in range(left, right + 1):
                if S[cur] == '?':
                    S[cur] = T[cur-left]
            break
        left -= 1
        right -= 1
    else:
        
        restorable = False

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


if __name__ == "__main__":
    resolve()

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

    for i in range(len(s)-len(t), -1, -1):
        flag = 1
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == "?":
                flag = flag * 1
            else:
                flag = 0
        if flag:
            ans = ["a" if x == "?" else x for x in s]
            for k in range(len(t)):
                ans[i+k] = t[k]
            print("".join(ans))
            exit()
    print("UNRESTORABLE")

if __name__ == "__main__":
    main()

Solution (Python):
s,t=input(),input()
n=len(s)
m=len(t)
ans="z"*(n+1)
for i in range(n-m+1):
    p=s[:i].replace("?","a")

    for j in range(m):
        if s[i+j]in("?",t[j]):
            p+=t[j]
        else:break
    else:

        p+=s[len(p):].replace("?","a")
        ans=min(ans,p)
print("UNRESTORABLE" if len(ans)==n+1 else ans)

Solution (Python):
s = input()
t = input()
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(s) - len(t), -1, -1):
        ok = True
        for j in range(len(t)):
            if s[i + j] != t[j] and s[i + j] != "?":
                ok = False
        if ok:
            print((s[:i] + t + s[i + len(t):]).replace("?", "a"))
            exit()
    print("UNRESTORABLE")

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

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

Solution (Python):
import copy
import sys

s = input()
t = input()
li = list('abcdefghijklmnopqrstuvwxyz')
r = []
for i in range(len(s)-len(t)+1):
    ss = list(s)

    lo = [1 if ((s[i + j] == t[j]) or (s[i + j] == '?')) else 0 for j in range(len(t))]

    if all(lo):
        ss[i:i+ len(t)] = t
        rs = ''.join(ss)
        rs = rs.replace('?','a')
        r += [rs]

if len(r) == 0:
    print('UNRESTORABLE')
    sys.exit()
r = sorted(r)
print(r[0])

Solution (Python):
import os

s = list(map(str,input()))
t = list(map(str,input()))

m = len(s)
n = len(t)
ans = 0

if m<n:
    print("UNRESTORABLE")
    exit()
for i in range(m-n+1):
    s2 = s.copy()
    s1 = s2[i:i+n]
    flag = True
    for j in range(n):
        if s1[j]!="?" and s1[j]!=t[j]:
            flag = False
            break
        else:
            s1[j] = t[j]
    if flag:
        s2[i:i+n] = s1
        s2 = "".join(s2)
        a = s2.replace("?","a")
        if ans==0:
            ans = a
        elif ans > a:
            ans = a
if ans==0:
    print("UNRESTORABLE")
else:
    print(ans)

Solution (Python):
sn = list(input())
t = list(input())
ls = len(sn)
lt = len(t)
Flag = False  
reali = 0 
if lt > ls:
  print("UNRESTORABLE")
  exit()
for i in range(ls-lt+1): 
  ss = sn[i:i+lt]
  count = 0
  for j in range(lt):
    if ss[j] == "?" or ss[j] == t[j]:
      count += 1
  if count == lt:
    reali = i
    Flag = True
for i in range(ls): 
  if i == reali:
    for j in range(lt):
      sn[i+j] = t[j]
  if sn[i] == "?":
    sn[i] = "a"
if Flag:
  for i in sn:
    print(i,end="")
else:
  print("UNRESTORABLE")

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

for i in range(len(s)-len(t)+1):
    flag=0
    i=len(s)-len(t)-i
    
    for j in range(len(t)):
        if t[j]!=s[i+j] and s[i+j]!="?":
            flag=1
            
    if flag==0:
        for j in range(len(t)):
            s[i+j]=t[j]
        result=""
        for item in s:
            result=result+str(item)
        result=result.replace("?","a")
        print(result)
        exit()
print("UNRESTORABLE")

Solution (Python):



def main():
    Sd = input()
    N = len(Sd)
    T  = input()
    ans = []
    for i in range(N-len(T)+1):
        flag = True
        tmp = list(Sd)
        for j in range(len(T)):
            if Sd[i+j] == '?':
                tmp[i+j] = T[j]
            elif Sd[i+j] != T[j]:
                flag = False
                break
        if flag:
            ans.append(''.join(tmp).replace('?','a'))
    if ans == []:
        print('UNRESTORABLE')
    else:
        print(sorted(ans)[0])


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import collections

sys.setrecursionlimit(10 ** 7)


S = input().rstrip()


T = input().rstrip()

if len(S) < len(T):
    print("UNRESTORABLE")
    sys.exit()

array = []
for i in range(len(S) - len(T) + 1):
    for t in range(len(T)):
        if S[i + t] not in ("?", T[t]):
            break
    else:
        
        
        
        
        
        memo = S[:i] + T + S[i + len(T):]
        array.append(memo.replace('?', 'a'))

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

Solution (Python):

import sys
import collections

sys.setrecursionlimit(10 ** 7)


S = input().rstrip()


T = input().rstrip()

if len(S) < len(T):
    print("UNRESTORABLE")
    sys.exit()

array = []
for i in range(len(S) - len(T) + 1):
    for t in range(len(T)):
        if S[i + t] not in ("?", T[t]):
            break
    else:
        
        
        
        
        
        memo = S[:i] + T + S[i + len(T):]
        array.append(memo.replace('?', 'a'))

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

Solution (Python):


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

print("UNRESTORABLE")

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

ans_list = []

for i in range(len(S)-len(T)+1):
    flg = 0
    temp = copy.deepcopy(S)

    
    for j in range(len(T)):
        if T[j]==S[i+j]:
            continue
        elif S[i+j]=="?":
            temp[i+j] = T[j]
            continue
        else:
            flg = 1
    if flg==0:
        for i in range(len(temp)):
            if temp[i]=="?":
                temp[i]="a"
        ans_list.append("".join(temp))

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

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

n = len(s)
m = len(t)

if t in s:
    print(s.replace('?', 'a'))
else:
    ans = []
    for i in range(n - m + 1):
        bubun = s[i:i + m]
        flag = True
        for j in range(m):
            x = bubun[j]
            y = t[j]
            if x == y:
                continue
            elif x == '?':
                continue
            else:
                flag = False
                break

        if flag:
            ans.append((s[:i] + t + s[i + m:]).replace('?', 'a'))

    print(sorted(ans)[0]) if ans else print('UNRESTORABLE')

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

S_length = len(S)
T_length = len(T)

if S_length < T_length:
    print("UNRESTORABLE")
    
elif S_length == T_length:
    for i in range(T_length):
        if S[i] != "?" and S[i] != T[i]:
            print("UNRESTORABLE")
            break
    else:
        print(T)
    
else:
    flag = 0
    for i in range(S_length - T_length):
        for j in range(T_length):
            if S[S_length - T_length - i + j] != "?" and S[S_length - T_length - i + j] != T[j]:
                break
        else:
            flag = 1
            S = S[:S_length - T_length - i] + T + S[S_length - i:]
            break
            
    if flag == 1:
        ans = S.replace("?", "a")
        print(ans)
        
    elif flag == 0:
        print("UNRESTORABLE")

Solution (Python):
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,-1,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] + T + ans[i+lt:]
        break
print(ans)

Solution (Python):
s = input()
t = input()
m = len(s)
n = len(t)
res = float('inf')

for i in range(m-n+1):
  S = s[i:i+n:]
  judge = True
  for j in range(n):
    if not(S[j] == t[j] or S[j] == "?"):
      judge = False
      break
  if judge:
    res = i
    
if res == float('inf'):
  print("UNRESTORABLE")
  exit()

ans = ""
for i in range(m):
  if s[i] != "?":
    ans += s[i]
  else:
    if res <= i and i < res + n:
      ans += t[i-res]
    else:
      ans += "a"
print(ans)

Solution (Python):
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
if ls < lt:
    print("UNRESTORABLE")
else:
    res = []
    for i in range(ls-lt+1):
        res.append(s[i:i+lt])
    tmp = []
    for i in range(len(res)):
        flag = True
        for j in range(lt):
            if res[i][j] == t[j] or res[i][j] == '?':
                pass
            else:
                flag = False
                break
        if flag:
            tmp.append(i)
    ans = []
    for i in tmp:
        q = []
        for j in range(0, i):
            q.append(s[j])
        for j in range(0, lt):
            q.append(t[j])
        for j in range(i+lt, ls):
            q.append(s[j])
        for j in range(ls):
            if q[j] == '?':
                q[j] = 'a'
        ans.append(''.join(q))
    if ans:
        print(min(ans))
    else:
        print("UNRESTORABLE")

Solution (Python):
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in reversed(range(len(sp)-len(t)+1)):
        for j in reversed(range(len(t))):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in reversed(range(len(t))):
                sp[i+j] = t[j]
            
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Solution (Python):
def resolve():
	ss = list(input())
	t = list(input())
	candidates = []
	for i in range(len(ss) - len(t) + 1):
		s = ss[:]
		ok = True
		for j in range(len(t)):
			if s[i+j] != t[j] and s[i+j] != '?':
				ok = False
				break
		if ok:
			for j in range(len(t)):
				s[i + j] = t[j]
			for j in range(len(s)):
				if s[j] == '?':
					s[j] = 'a'
			candidates.append("".join(s))
	if len(candidates):
		print(min(candidates))
	else:
		print('UNRESTORABLE')
resolve()

Solution (Python):
S = input()
T = input()
lenS = len(S)
lenT = len(T)
ans = "UNRESTORABLE"
for i in range(lenS-lenT,-1,-1):
    subS = S[i:i+lenT]
    for j in range(lenT):
        if subS[j] != T[j] and subS[j] != "?":
            break
    else:
        ans = S[:i]+T+S[i+lenT:]
        ans = ans.replace("?","a")
        break

print(ans)

Solution (Python):
s = input()[::-1]
t = input()[::-1]
 
def check(c,t):
    if len(c) < len(t):
        return False
    for i in range(len(t)):
        if c[i] != "?" and c[i] != t[i]:
            return False
 
    return True
        
 
i = 0 
Has = False
ans = ""
while i < len(s):
    if (s[i] == "?" or s[i] == t[0]) and not Has:
        if check(s[i:],t):
            Has = True
            ans += t
            i += len(t)
        else:
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
            i += 1
 
    elif s[i] == "?":
        i += 1
        ans += "a"
    else:
        ans += s[i]
        i += 1
 
if Has:
    print(ans[::-1])
else:
    print('UNRESTORABLE')

Solution (Python):

import sys
import re
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=input().replace('?','.')
    T=input()
    ans='z'*100
    for i in range(len(S)-len(T)+1):
        if re.match(S[i:i+len(T)],T):
            tmp=(S[:i]+T+S[i+len(T):]).replace('.','a')
            ans=min(ans,tmp)
    print(ans if ans!='z'*100 else 'UNRESTORABLE')
    

if __name__ == '__main__':
    main()

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

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

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

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1):
        flag = True
        for j in range(i , i + len(t)):
            if s[j] == t[j - i] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp[:i] + t + tmp[i + len(t):]
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])

Solution (Python):
def main():
  s = str(input())
  ans = s.replace('?', 'z')
  flag = False
  t = str(input())
  for i in range(len(s)-len(t)+1):
    temp_flag = True
    temp_ans = list(s)
    for j in range(len(t)):
      if s[i + j] == '?':
        temp_ans[i + j] = t[j]
        continue
      elif s[i+j] != t[j]:
        temp_flag = False
    if temp_flag:
      flag = True
      temp_ans = "".join(temp_ans)
      temp_ans = temp_ans.replace('?', 'a')
      ans = min(ans, temp_ans)
  if flag:
    print(ans)
  else:
    print("UNRESTORABLE")
    
if __name__ == "__main__":
  main()

Solution (Python):
import sys
a=input()
b=input()
for i in reversed(range(len(a)-len(b)+1)):
  t=True
  for j in range(len(b)):
    if not(a[i+j]=="?") and not(a[i+j]==b[j]):
      t=False
      break
  if t:
    for p in range(i):
      if a[p]=="?":
        print("a",end="")
      else:
        print(a[p],end="")
    print(b,end="")
    for w in range(i+len(b),len(a)):
      if a[w]=="?":
        print("a",end="")
      else:
        print(a[w],end="")
    sys.exit()
print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

if res:
    print(min(res))
else:
    print("UNRESTORABLE")