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):
import sys, re
INPUT = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 9)


def main():
    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")


if __name__ == '__main__':
    main()

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

flag = False
for i in range(len(S) - len(T), -1, -1):
  flag = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      flag = False
      break
  if flag:
    break
if flag:
  U = S[:i] + T + S[i+len(T):]
  U = U.replace('?', 'a')
  print(U)
else:
  print('UNRESTORABLE')

Solution (Python):
S=input()
T=input()
S=list(S)
T=list(T)
flag=0
k=0
p=100
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]!='?':
            k=1
    if k==0:
        flag=1
        p=i
    k=0
if flag==0:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if i==p:
            for j in range(len(T)):
                S[i+j]=T[j]
            i+=len(T)
        else:
            if S[i]=='?':
                S[i]='a'
    S="".join(S)
    print(S)

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

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

res = "UNRESTORABLE"
for i in range(len(Sp)-len(T), -1, -1):
    
    if matchFound(Sp[i:], T):
        Sp = Sp[:i] + T + Sp[i+len(T):]
        res = Sp.replace("?", "a")
        break;
        
print(res)

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

lens = len(s)
lent = len(t)
if lens < lent:
  print("UNRESTORABLE")
else:
  for i in reversed(range(lens - lent + 1)):
    isallmatch = True
    for j in range(lent):
      if not s[i + j] in [t[j], "?"]:
        isallmatch = False
    if isallmatch == True:
      for j in range(lent):
        s[i + j] = t[j]
      ss = "".join(s).replace("?", "a")
      print(ss)
      exit()
  print("UNRESTORABLE")

Solution (Python):


if __name__ == '__main__':
    S_ = input()
    T = input()
    save = []

    for i in range(len(S_)-len(T)+1):
        target = S_[i:i+len(T)]

        flag = True
        for j in range(len(T)):
            if target[j]=='?':
                continue
            elif target[j]==T[j]:
                continue
            else:
                flag = False
                break

        if flag:
            S = S_[:i] + T + S_[i+len(T):]
            S = S.replace('?', 'a')
            save.append(S)

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

Solution (Python):
S = input()
T = input()
candidates = []
for i in range(0,len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
    if cnt == len(T):
        candidate = S[:i] + T + S[i+len(T):]
        candidates.append(candidate)


if len(candidates) == 0:
    ans = "UNRESTORABLE"
else:
    candidates.sort()
    ans = candidates[0].replace("?","a")
print(ans)

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

Solution (Python):
import re

_S = input()
T = input()

lenS = len(_S)
lenT = len(T)

if lenT > lenS:
	print("UNRESTORABLE")
else:
	S = re.split("([?" + "][?".join(T[::-1]) + "])", _S[::-1])
	if len(S) == 1:
		print("UNRESTORABLE")
	else:
		S[1] = T[::-1]
		S = "".join(S)
		print(S[::-1].replace("?", "a"))

Solution (Python):
import sys
input=sys.stdin.readline

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

for i in range(len(s)-len(t),-1,-1):
    for j in range(len(t)):
        if s[i+j] == "?" or s[i+j] == t[j]:
            if j == len(t)-1:
                s = "" + s[:i] + t + s[i+len(t):]
                print(s.replace("?","a"))
                exit()
        else:
            break
print("UNRESTORABLE")

Solution (Python):
import sys
s = input()
t = input()
if len(t) > len(s):
    print('UNRESTORABLE')
    sys.exit()
elif len(t) == len(s):
    print(t)
    sys.exit()
diff = len(s)-len(t)
for i in range(diff,-1,-1):
    target = s[i:len(t)+i]
    for ta,te in zip(target,t):
        if ta != '?' and ta != te:
            break
    else:
        tmp = list(s)
        tmp[i:len(t)+i] = t
        print(''.join(tmp).replace('?','a'))
        sys.exit()
print('UNRESTORABLE')

Solution (Python):
s = input()
t = input()
if len(s) >= len(t):
  temp = -1
  for i in range(len(s) - len(t) + 1)[: : -1]:
    temp = i
    for j in range(len(t)):
  	  
  	  if (s[i + j] == "?") or (s[i + j] == t[j]):
  	    continue
  	  else: 
  	  	temp = -1
    if temp != -1:
      
      break
  if temp == -1: print("UNRESTORABLE"); exit(0)
  r = (s[: temp] + t + s[temp + len(t): ]).replace("?", "a")
  print(r)
else: print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
key=t[0]
l=[]
for k,v in enumerate(s):
    f=0
    x=s[k:k+len(t)]
    if len(x)==len(t):
        for ke,j in enumerate(x):
            if j=="?":
                continue
            else:
                if x[ke]!=t[ke]:
                    f=1
                    break
        if not f:
            y=(s[:k]+t+s[k+len(t):]).replace("?","a")
            l.append(y)
    else:
        break
if l:
    print(min(l))
else:
    print("UNRESTORABLE")

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

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

if match == -1:
    print("UNRESTORABLE")
else:
    s = s[0:match] + t + s[match + len(t):]
    for i in range(len(s)):
        if s[i] == "?":
            s = s[0:i] + "a" + s[i + 1:]
    print(s)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

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

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()


def check(i):
    s = list(S)
    for j in range(len(T)):
        if s[i + j] == '?':
            s[i + j] = T[j]
    return ''.join(s).startswith(T, i)


def restore(i):
    s = list(S)
    for j in range(len(T)):
        s[i + j] = T[j]
    for i in range(len(S)):
        s[i] = 'a' if s[i] == '?' else s[i]
    return ''.join(s)


i = 0
ans = []
while i + len(T) <= len(S):
    if check(i):
        ans.append(restore(i))
    i += 1

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

Solution (Python):
s = input()
t = input()
cnt = 0
for i in range(len(s) - len(t), -1, -1):
    cnt = 0
    for j in range(len(t)):
        if s[j + i] == "?" or s[j + i] == t[j]:
            cnt += 1
        else:
            break
    if cnt == len(t):
        for j in range(len(s)):
            if i <= j < i + len(t):
                print(t[j - i], end = "")
            elif s[j] == "?":
                print("a", end = "")
            else:
                print(s[j], end = "")
        print()
        break
if cnt != len(t):
    print("UNRESTORABLE")

Solution (Python):

s = input()
t = input()

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

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

len_S = len(S_dash)
len_T = len(T)

candidate = []


for i in range(len_S - len_T + 1):
  
  tmp = S_dash[i:i+len_T]
  
  count = 0
  for s, t in zip(tmp, T):
    if s == t or s == '?':
      count += 1
  if count == len_T:
    candidate.append(S_dash[:i] + T + S_dash[i+len_T:])
    
if candidate != []:       
  replaced_candidate = [item.replace("?", "a") for item in candidate]
  replaced_candidate.sort()
  print(replaced_candidate[0])
else:
  print("UNRESTORABLE")

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

Solution (Python):
import copy
Sd = list(input())
T = list(input())
S = copy.deepcopy(Sd)
ans = []
for i in range(len(Sd)-len(T)+1):
    for j in range(len(T)):
        if Sd[i+j] != '?' and Sd[i+j] != T[j]:
            Sd = copy.deepcopy(S)
            break
        elif Sd[i+j] == '?':
            Sd[i+j] = T[j]
        if j == len(T)-1:
            l = ['a' if i =='?' else i for i in Sd]
            ans.append(''.join(l))
            Sd = copy.deepcopy(S)
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(min(ans))

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

ret = -1


t_len = len(t)


for i in range(len(s)-t_len+1):
    cut_seq = s[i:i+t_len]
    for j in range(t_len):
        if cut_seq[j] != t[j] and cut_seq[j] != '?':
            break
    else:
        ret = max(ret, i)


if ret == -1:
    print('UNRESTORABLE')
else:
    print((s[:ret] + t + s[ret + t_len:]).replace('?', 'a'))

Solution (Python):

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

Solution (Python):

s_d = list(str(input()))
t = list(str(input()))

def check(s, t):
    flag = True
    for j in range(len(t)):
        if s[j] == t[j] or s[j] == "?":
            continue
        else:
            flag = False
    return flag

flag = False
for i in range(len(s_d) - len(t)+1):
    flag = check(s_d[len(s_d) - i - len(t):len(s_d) - i], t)
    if flag:
        for idx, j in enumerate(range(len(s_d) - i - len(t), len(s_d)-i)):
            s_d[j] = t[idx]
        break
for i in range(len(s_d)):
    if s_d[i] == "?":
        s_d[i] = "a"
if flag:
    print("".join(s_d))
else:
    print("UNRESTORABLE")

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

ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    if len(S[i:i + len(T)]) == len(T):
        same = True
        for j, s in enumerate(S[i:i + len(T)]):
            if not (s == T[j] or s == '?'):
                same = False
        if same:
            rep = (S[:i] + T + S[i + len(T):]).replace('?', 'a')
            ans = rep if ans == "UNRESTORABLE" else min(ans, rep)

print(ans)

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

def no():
    print("UNRESTORABLE")

les = len(s)-len(t)
kouho = []
if les < 0:
    no()
else:
    for i in range(les+1):
        flag =True
        for j in range(len(t)):
            if s[i+j] == "?":
                continue
            elif s[i+j] == t[j]:
                continue
            else:
                flag = False
                break
        if flag:
            kouho.append(i)
    if len(kouho) == 0:
        no()
    else:
        temp = []
        for i in range(len(kouho)):
            txt =""
            for j in range(len(s)):
                if s[j] == "?":
                    if j >= kouho[i] and j <= kouho[i]+len(t)-1:
                        txt+=t[j-kouho[i]]
                    else:
                        txt+="a"
                else:
                    txt += s[j]
            temp.append(txt)
        temp.sort()
        print(temp[0])

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

check =1
ans = -1
if t > s:
    check = -1


else:
    for i in range(s-t+1):
        c = 1
        for j in range(t):
            if S[i+j] == '?':
                pass
            elif S[i+j] == T[j]:
                pass
            else:
                c = -1
        if c == 1:
            ans = i



if check == 1:
    if ans != -1:
        S = S[:ans] + T + S[ans+t:]
        
        for i in range(s):
            if S[i] == '?':
                S[i] = 'a'
        print(''.join(S))
    else:
        print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

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

ans = ["UNRESTORABLE"]
for i in range(len(S)-len(T)+1):
	count = 0
	for j in range(len(T)):
		if (S[i+j] == T[j] or S[i+j] == "?"):
			count += 1
	if count == len(T):
		Sa = S[:i]+T+S[i+len(T):]
		pl = Sa.replace("?","a")
		ans.append(pl)

print(ans[-1])

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

Solution (Python):
s = input()
t = input()
lens = len(s)
lent = len(t)

check = 0
ansindex = []
for i in range(lens-lent+1):
  for j in range(lent):
    if not((s[i+j]==t[j]) or (s[i+j]=='?')):
      break
    if j ==lent -1:
      ansindex.append(i)
      check +=1
 
 
if check == 0:
  print('UNRESTORABLE')
  exit()
ans =s.replace('?','a')
ans = ans[:ansindex[-1]]+t+ans[ansindex[-1]+lent:]
print(ans)

Solution (Python):
s = input()
ls = len(s)
t = input()
lt = len(t)
for i in range( ls - lt + 1 ):
  start = ls - lt - i
  for j in range(lt):
    if s[start + j] != t[j] and s[start + j] != '?':
      break
  else:
    ss = ''
    for k in range(start):
      if s[k] == '?':
        ss += 'a'
      else:
        ss += s[k]
    
    ss += t
    for k in range(start+lt,ls):
      if s[k] == '?':
        ss += 'a'
      else:
        ss += s[k]
    print(ss)
    break
else:
  print('UNRESTORABLE')

Solution (Python):



s = input()
t = input()

lens = len(s)
lent = len(t)
check = 0
ansindex = []
for i in range(lens-lent+1):
    for j in range(lent):
        
        if not((s[i+j]==t[j]) or (s[i+j]=='?')):
            break
        if j ==lent -1:
            ansindex.append(i)
            check +=1


if check == 0:
    print('UNRESTORABLE')
    exit()
ans =s.replace('?','a')
ans = ans[:ansindex[-1]]+t+ans[ansindex[-1]+lent:]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


def solve(S, T):
    def appliable_at(pos):
        for i, c in enumerate(S[pos:len(T) + pos]):
            if c != T[i] and c != '?':
                return False
        return True

    for i in range(len(S) - len(T), -1, -1):
        if appliable_at(i):
            ans = S[:i] + T + S[i + len(T):]
            return ans.replace('?', 'a')
    return 'UNRESTORABLE'


def main():
    S = input().strip()
    T = input().strip()
    print(solve(S, T))


if __name__ == "__main__":
    main()

Solution (Python):
s_dash = input()
t = input()
len_s = len(s_dash)
len_t = len(t)
candidates = set()

for i in range(len_s - len_t + 1):
    part_s = s_dash[i:i+len_t+1]
    flag = True
    for j,k in zip(part_s,t):
        if j=='?' or j==k:
            continue
        else:
            flag = False
            break
    if flag:
        candidates.add(s_dash[0:i].replace("?","a")+t+s_dash[i+len_t::].replace("?","a"))

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

Solution (Python):
I=input;s,t=I()[::-1],I()[::-1]
l=len(t)
for i in range(len(s)-l+1):
	f=1;j=-1
	for k in s[i:i+l]:
		j+=1
		if "?"!=k!=t[j]:
			f=0
	if f:
		s=s[:i]+t+s[i+l:]
		print(s.replace("?","a")[::-1])
		exit()
print("UNRESTORABLE")

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

Solution (Python):

s_dash = input()
t = input()
len_s = len(s_dash)
len_t = len(t)

candidates = set()

for i in range(len_s-len_t+1):
    part_s = s_dash[i:i+len_t+1]
    flag = True
    for j,k in zip(part_s,t):
        if j == "?" or j==k:
            continue
        else:
            flag = False
            break
    if flag:
        candidates.add(s_dash[0:i].replace("?","a")+t+s_dash[i+len_t::].replace("?","a"))
ret = "UNRESTORABLE"
if len(candidates)>0:
    ret = min(candidates)
print(ret)

Solution (Python):





def main():
    S = input()
    T = input()
    n = len(S)
    l = len(T)
    K = []
    for i in range(n-l+1):
        s = S[i:i+l]
        candidate = True
        for c1, c2 in zip(s, T):
            if c1 != '?' and c1 != c2:
                candidate = False
        if candidate:
            K.append(i)
    if len(K) == 0:
        print('UNRESTORABLE')
        return
    top = K[-1]
    f = S[:top].replace('?', 'a')
    t = S[top+l:].replace('?', 'a')
    print(f + T + t)
    pass

if __name__ == '__main__':
    main()

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

res = []
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
    if flag:
        U = S.replace("?", "a")
        U = U[:i] + T + U[i + len(T) :]
        res.append(U)

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

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

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

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

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

match = -1
for s in range(len(S)-len(T)+1):
    ok = True
    for t in range(len(T)):
        if S[s+t] == '?':
            continue
        if S[s+t] == T[t]:
            continue
        ok = False
        break
    if ok:
        
        
        
        match = s

if match == -1:
    print("UNRESTORABLE")
else:
    S = list(S)
    A = []
    for i in range(len(S)):
        if match <= i < match+len(T):
            A.append(T[i-match])
        else:
            if S[i] == '?':
                A.append('a')
            else:
                A.append(S[i])
    print("".join(A))

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

    print("UNRESTORABLE")
main()

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

ans_list=[]
for i in range(len(S)-len(T)+1):
    S_temp=S.copy()
    serch_S=S_temp[i:i+len(T)]
    count=0
    for t in range(len(T)):
        if serch_S[t] in [T[t],'?']:
            count+=1
        else:
            break
        
        if count==len(T):
            S_temp[i:i+len(T)]=T

            for s in range(len(S_temp)):
                if S_temp[s]=='?':
                    S_temp[s]='a'
                    
            S_temp_str=''
            for s_t in S_temp:
                S_temp_str+=s_t

            ans_list.append(S_temp_str)

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

Solution (Python):
S = input()
T = input()
len_t = len(T)
len_s = len(S)
ans = [''] * (len_s)
for i in range(len_s)[::-1]:
  if len_t-1 > i:
    break
  hasT = True
  for j in range(len_t):
    if T[j] != S[i-len_t+1+j] and S[i-len_t+1+j] != '?':
      hasT = False
      break
  if hasT:
    for j in range(len_t):
      if S[i-len_t+1+j] == '?':
        ans[i-len_t+1+j] = T[j]
    for k in range(len_s):
      if S[k] == '?' and ans[k] == '':
        ans[k] = 'a'
      elif ans[k] == '':
        ans[k] = S[k]
    print(''.join(ans))
    exit()
print('UNRESTORABLE')

Solution (Python):
S=input()
T=input()
t=len(T)
for i in range(len(S)-t+1):
    a=c=0
    for j in range(t):
        k=S[-t-i+j]
        if k ==T[j] or k=="?" :c+=1
    if c==t:
        bef=S[:len(S)-t-i].replace("?","a")
        aft=""
        if i!=0:aft=S[-i:].replace("?","a")
        print(bef+T+aft)
        exit()
print("UNRESTORABLE")

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

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

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

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

def mch(x,y):
    l=[False]*len(x)
    for i in range(len(x)):
        if x[i]=='?':l[i]=True
        elif x[i]==y[i]:l[i]=True
    return True if all(l) else False

l=[]
for i in range(len(s)-len(t)+1):
    if mch(s[i:i+len(t)],t):l.append((s[:i]+t+s[i+len(t):]).replace('?','a'))
print('UNRESTORABLE' if len(l)==0 else sorted(l)[0])

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math






def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = list(input())
    T = list(input())
    
    ind = []
    isOk = False
    
    for i, val in enumerate(S):
        if val == "?" or val == T[0]:
            flg = True
            if len(S)-i < len(T):
                
                
                break
            for j, vol in enumerate(T):
                if S[i+j] != T[j] and S[i+j] != "?":
                    flg = False
                    break
            if flg == True:
                ind.append(i)
                isOk = True
                
    if isOk == False:
        print("UNRESTORABLE")
    else:
        ind.sort()
        tmp = ind[-1]
        for i, val in enumerate(S):
            if i == tmp:
                for j, vol in enumerate(T):
                    S[i+j] = T[j]
            else:
                if val == "?":
                    S[i] = "a"
        print("".join(S))
    
            	
if __name__ == "__main__":
	main()

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

    if len(S) < len(T):
        print("UNRESTORABLE")
        return 0

    answers = []

    for i in range(0, len(S)-len(T)+1):
        is_ok = True
        for j in range(len(T)):
            
            
            
            if S[i+j] != "?" and S[i+j] != T[j]:
                is_ok = False
        if is_ok:
            answers.append((S[0:i:] + T + S[i+len(T)::]).replace("?","a"))

    if len(answers) == 0:
        print("UNRESTORABLE")
        return 0
    else:
        answer = sorted(answers)[0]
        print(answer)
        return 0


if __name__ == '__main__':
    main()

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

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

import sys
INF = float("inf")


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

    candidate = []

    for i in range(len(s)-T+1):
        buf = s[i:i+T]
        flag = True
        for b, tc in zip(buf, t):
            if b == "?" or b == tc:
                continue
            else:
                flag = False
                break
        if flag == True:
            candidate.append(i)

    if len(candidate) == 0:
        print("UNRESTORABLE")
    else:
        print((s[:candidate[-1]] + t + s[candidate[-1]+T:]).replace("?", "a"))

    pass


if __name__ == '__main__':
    main()

Solution (Python):



blank_s = input().split()[0]
t = input().split()[0]

matched_index_list = []

for i in range(len(blank_s) - len(t) + 1):
    is_match = True
    for s_char, t_char in zip(blank_s[i:i+len(t)], t):
        if s_char != '?' and s_char != t_char:
            is_match = False
            break

    if is_match:
        matched_index_list.append(i)

if not matched_index_list:
    answer = 'UNRESTORABLE'
else:
    replaced_s_list = []
    for index in matched_index_list:
        replaced_s = list(blank_s)
        replaced_s[index:index+len(t)] = t
        replaced_s = ''.join(replaced_s)
        replaced_s = replaced_s.replace('?', 'a')
        replaced_s_list.append(replaced_s)

    answer = min(replaced_s_list)

print(answer)

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


ans = 0
for j in range(len(S)-len(T)+1):
    can = True
    SS = S[:]
    for i, t in enumerate(T):
        s = S[j+i]
        if s != '?' and s != t:
            can = False
            break
        elif s == '?':
            SS[j+i] = t
    if can:
        ans = SS

if ans == 0:
    print('UNRESTORABLE')
else:
    Ans = ans[:]
    for i, a in enumerate(ans):
        if a == '?':
            Ans[i] = 'a'
    print(''.join(Ans))

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

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

Solution (Python):



def checkstr(sd,t,i):
	

	for j in range(0,len(t)):
		if(sd[j+i]!=t[j])and(sd[j+i]!='?'):
			return -1
	return i

sd = input()
t = input()

j=-1
for i in range(0,len(sd)-len(t)+1):



	ret = checkstr(sd,t,len(sd)-len(t)-i)
	if(ret>=0):
		j=len(sd)-len(t)-i
		break

str_list = list(sd)
for i in range(0,len(sd)):
	if(str_list[i]=='?'):
		str_list[i]='a'
if(j!=-1):
	for i in range(0,len(t)):
		str_list[j+i]=t[i]

	sd_res = "".join(str_list)
	print(sd_res)
else:
	print("UNRESTORABLE")

Solution (Python):

import sys
sys.setrecursionlimit(10**7)
import math
from collections import defaultdict


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))



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

if len(T)>len(S):
  print('UNRESTORABLE')
  sys.exit()

flag = False
for i in range(len(S)-len(T)+1)[::-1]:
  counter = 0
  for j in range(len(T)):
    if (S[i+j]!='?') and (S[i+j]!=T[j]):
      break
    counter += 1
  if counter == len(T):
    flag = True
    break
  
if flag==False:
  print('UNRESTORABLE')
else:
  S = S[0:i] + T + S[i+len(T):]
  S = S.replace('?', 'a')
  print(S)

Solution (Python):


s, t = input(), input()
for si in range(len(s) - len(t), -1, -1):
    flag = True
    for ti in range(len(t)):
        if s[si + ti] != t[ti] and s[si + ti] != "?":
            flag = False
            break
    if flag:
        ans = ""
        for i in range(si):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        ans += t
        for i in range(si + len(t), len(s)):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        print(ans)
        exit()
print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
u=''
v=[]
count=0

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]==s[i+j] or s[i+j]=='?':
            count+=1
    if count==len(t):
        for k in range(len(s)):
            if i<=k<=i+len(t)-1:
                u+=t[k-i]
            elif s[k]=='?':
                u+='a'
            else:
                u+=s[k]
                    
                    
        v.append(u)
        u=''
    count=0
if v==[]:
    print('UNRESTORABLE')
else:
    print(min(v))