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()
ans = []

for left in range(len(S)):
    subS = S[left: left + len(T)]
    if len(subS) < len(T):
        break
    for s, t in zip(subS, T):
        if s == '?':
            continue
        if s != t:
            break
    else:
        U = S[:left] + T + S[left + len(T):]
        ans.append(U.replace('?', 'a'))

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

Solution (Python):
from sys import stdin

s, t = stdin.read().split()
s = list(s)

possible_indexes = []
for i in range(len(s) - len(t) + 1):
    substring = s[i: i+len(t)]
    for j in range(len(t)):
        if substring[j] == t[j] or substring[j] == '?': continue
        else: break
    else:
        possible_indexes.append(i)

if not possible_indexes: print('UNRESTORABLE'); exit()

ma = max(possible_indexes)
for j in range(len(t)):
    s[ma+j] = t[j]

s = ''.join(s)

s = s.replace('?', 'a')
print(s)

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

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

Sd = input().strip()
T = input().strip()

def same(s, t):
    s = re.sub('\?', '.', s)
    return re.match(s, t)

flag = False
for i in range(len(T), len(Sd) + 1):
    if same(Sd[len(Sd) - i:len(Sd) - i + len(T)], T):
        Sd = Sd[:len(Sd) - i] + T + Sd[len(Sd) - i + len(T):]
        flag = True
        break

if flag:
    Sd = re.sub('\?', 'a', Sd)
else:
    Sd = 'UNRESTORABLE'

print(Sd)

Solution (Python):
S=input()
T=input()
if len(S)<len(T):
    print('UNRESTORABLE')
else:
    cand=[]
    for i in range(len(S)-len(T)+1):
        if all(s=='?' or s==t for s,t in zip(S[i:i+len(T)],T)):
            cand.append(S[:i].replace('?','a')+T+S[i+len(T):].replace('?','a'))
    print('UNRESTORABLE' if len(cand)==0 else min(cand))

Solution (Python):
def main():
    s=list(input())
    t=list(input())
    key=0
    index=0
    if len(s)<len(t):
        print("UNRESTORABLE")
        return
    key2=0
    for i in range(len(s)-len(t)+1):
        for j in range(len(t)):
            if s[i+j]!="?" and s[i+j]!=t[j]:
                key2=1
                break
        if key2==0:
            index=i
            key=1
        key2=0
    if key==0:
        print("UNRESTORABLE")
        return
    for i in range(len(t)):
        s[index+i]=t[i]
    for i in range(len(s)):
        if s[i]=="?":
            s[i]="a"
    print(''.join(s))
if __name__ == "__main__":
    main()

Solution (Python):
S,T=input(),input()
l,m=len(S),len(T)

for i in range(l-m+1):
  if all(c in"?"+d for c,d in zip(S[-i-m:],T)):
    S=S.replace("?","a")
    print(S[:-i-m]+T+S[l-i:])
    quit()

print("UNRESTORABLE")

Solution (Python):
s=input()
n=len(s)
t=input()
m=len(t)
data=[]
for i in range(n-m+1):
    ans=""
    for j in range(i):
        if s[j]=="?":
            ans+="a"
        else:
            ans+=s[j]
    for j in range(m):
        if s[i+j]=="?":
            ans+=t[j]
        elif s[i+j]==t[j]:
            ans+=t[j]
        else:
            break
    else:
        for j in range(n-i-m):
            if s[m+i+j]=="?":
                ans+="a"
            else:
                ans+=s[m+i+j]
        data.append(ans)
data.sort()
if data:
    print(data[0])
else:
    print("UNRESTORABLE")

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

length_1 = len(s)
length_2 = len(t)


def check_word(num1, length):
    a = s[num1:num1+length]
    b = t[:]
    flag = True
    for i in range(length):
        if a[i] == '?':
            continue
        elif a[i] == b[i]:
            continue
        else:
            flag = False
            break
    if flag is True:
        c = s.copy()
        c[num1:num1+length] = t[:]
        c = fill_a(c)
        return c
    elif flag is False:
        return []


def fill_a(li):
    for i in range(len(li)):
        if li[i] == '?':
            li[i] = 'a'
    return li


word_list = []
for i in range(length_1 - length_2 + 1):
    x = check_word(i, length_2)
    if x != []:
        word_list.append(x)

if word_list == []:
    print('UNRESTORABLE')
else:
    word_list.sort()
    while word_list[0] == []:
        x.pop(0)
    for i in word_list[0]:
        print(i, end='')

Solution (Python):
s=input()
T=input()
k=[]
for i in range(len(s)-len(T)+1):
    k.append(s[i:i+len(T)])


z=-1
for i in range(len(k)):
    f=1
    for j in range(len(T)):
        if k[i][j]!=T[j] and k[i][j]!='?':
            f=0
            break
    if f==1:
        z=i

if z==-1:
    print('UNRESTORABLE')
else:
    s+=' '*z
    S=s[:z]+T+s[len(T)+z:]
    S=list(S)
    for i in range(len(S)):
        if S[i]=='?':
            S[i]='a'
    print(''.join(S))

Solution (Python):
s = input()
t = input()
n = len(s)
m = len(t)
ans = []
for i in 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:
        tmp = (s[:i] + t + s[(i+m):])
        a = []
        for j in range(n):
            if tmp[j]=="?":
                a.append("a")
            else:
                a.append(tmp[j])
        tmp = "".join(a)
        ans.append(tmp)

ans.sort()

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

Solution (Python):

s = list(input())
t = list(input())
x = 0
ans = []
gotk = False




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

def construct(k,s):
  for i in range(len(t)):
    s[i + k] = t[i]
  for i in range(len(s)):
    if s[i] == "?":
      s[i] = "a"
  return s


for i in range(len(s) - len(t),-1,-1):
  if match(i):
    x = i
    gotk = True
    break

if gotk == True:
  ans = construct(x,s)
  print("".join(ans))
else:
  print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
sr = len(s)
tr = len(t)
cand = []
for i in range(sr-tr+1):
    flag = True
    for j in range(tr):
        if s[i+j] != '?' and s[i+j] != t[j]:
            flag = False
            break
    if flag:
        tmp = (s[:i] + t + s[(i+tr):]).replace("?", "a")
        cand.append(tmp)
        
cand.sort()

if cand:
    print(cand[0])
else:
    print("UNRESTORABLE")

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

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
import bisect
import sys
import logging
import heapq



input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	s = input()[:-1]
	t = input()[:-1]
	for i in reversed(range(len(s) - len(t) + 1)):
		flag = True
		for j in range(len(t)):
			if(s[i+j]  != '?' and s[i+j] != t[j]):
				flag = False
				break
		if flag:
			ans = []
			for j in s:
				ans.append(j)
			for j in range(i, i+len(t)):
				ans[j] = t[j-i]
			a = ''
			for i in ans:
				a += i
			print(a.replace('?','a'))
			return
	print('UNRESTORABLE')


def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = list(str(input().rstrip('\n')))
    t = list(str(input().rstrip('\n')))
    for i in range(len(s)-len(t), -1, -1):
        b = True
        for j in range(len(t)):
            if s[i+j] != "?" and s[i+j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(t)):
                if s[i+j] == "?":
                    s[i+j] = t[j]
            for j in range(len(s)):
                if s[j] == "?":
                    s[j] = "a"
            print("".join(s))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    solve()

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

check = False
place = len_s - len_t
while place >= 0:
  temp_s = s[place:(place + len_t)]
  sub_s = [char if char != "?" else t[i] for i, char in enumerate(temp_s)]
  if t == "".join(sub_s):
    check = True
    break
  place -= 1

if check:
  result = [char if char != "?" else "a" for char in s]
  result[place:(place+len_t)] = list(t)
  print("".join(result))
else:
  print("UNRESTORABLE")

Solution (Python):
s_d = input()
t = input()
s_d = s_d[::-1]
t = t[::-1]
t_r = ''

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

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)
    start = None

    for si, s in enumerate(S):
        if tn > (sn - si):
            break
        if s == T[0] or s == '?':
            sj = start_tmp = si
            for t in T:
                sj_c = S[sj]
                if not (t == sj_c or sj_c == '?'):
                    start_tmp = None
                    break
                sj += 1
            start = start_tmp if start_tmp is not None else start

    if start is None:
        return "UNRESTORABLE"

    ret = []
    ti = 0
    for si, s in enumerate(S):
        if si >= start and si < len(T) + start:
            ret.append(T[ti])
            ti += 1
        else:
            if s == '?':
                ret.append('a')
            else:
                ret.append(s)
    return ''.join(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Solution (Python):
s = input()
t = input()
index = 0
s = ''.join(list(reversed(s)))
t = ''.join(list(reversed(t)))


exit_flag = True
for i in range(len(s)):
    
    if s[i] == t[0] or s[i] == '?':
        if i + len(t) > len(s):
            break
        for j in range(len(t)):
            if not (s[i + j] == t[j] or s[i + j] == '?'):
                break
            if j == len(t) - 1:
                start_index = i
                exit_flag = False
        if not exit_flag:
            break


if exit_flag:
    print("UNRESTORABLE")
    exit()
ans = s[:start_index] + t + s[start_index + len(t):]
ans = ''.join(list(reversed(ans)))
ans = ans.replace("?", "a")
print(ans)

Solution (Python):

s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if len(s_dash) < len(t):
    pass
else:
    for i in range(len(s_dash)-len(t)+1):
        for j, k in zip(s_dash[i:i+len(t)], t):
            if j != '?' and j != k:
                break
        else:
            answer = s_dash[:i] + t + s_dash[i+len(t):]
            answer = answer.replace('?', 'a')
print(answer)

Solution (Python):
def equ(s,t):
    for i in range(len(t)):
        if t[i]!=s[i]!='?':
            return False
    return True

S1=input()
T=input()

l=len(S1)
m=len(T)

S=''
for i in range(l-m,-1,-1):
    if equ(S1[i:i+m],T):
        S=(S1[:i]+T+S1[i+m:]).replace('?','a')
        break

print(S if S!='' else 'UNRESTORABLE')

Solution (Python):
import sys

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

if len(s) < len(t):
    print("UNRESTORABLE")
    sys.exit()

ans = False
con = True

for i in range(len(s)):
    for j in range(len(t)):
        if i+j>len(s)-1:
            con = False
            break
        if s[i+j] == t[j] or s[i+j] =='?':
            if j == len(t)-1:
                ans = True
                memo1 = i
                
        else:
            break
        

    if not(con):
        break

if not(ans):
    print("UNRESTORABLE")
else:
    for i in range(len(t)):
        s[memo1+i] = t[i]
    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"

    
    for i in range(len(s)):
        print(s[i],end = "")

print()

Solution (Python):
s=input()
s=list(s)
t=input()
n=len(s)
m=len(t)
ind=-1 
def ok(a,b):
    for i in range(len(a)):
        if a[i]=='?':
            pass 
        else:
            if a[i]!=b[i]:
                return 0 
    return  1 
for i in range(n-m+1): 
    if ok(s[i:i+m],t):
        ind=i 
if ind==-1:
    print('UNRESTORABLE')
else: 
    s[ind:ind+m]=t  
    for i in range(len(s)):
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

Solution (Python):

import re
No = "UNRESTORABLE"

def main():
    S = input()
    T = input()
    T_LEN = len(T)
    match_index = []

    for i in range(len(S) - T_LEN + 1):
        for idx in range(T_LEN):
            if S[i:i+T_LEN][idx] == T[idx] or S[i:i+T_LEN][idx] == "?":
                continue
            else:
                break
        else:
            match_index.append(i)
    
    if not match_index:
        print(No)
    
    else:
        answer = list(S)
        answer[match_index[0]:match_index[0] + T_LEN] = list(T)
        answer = "".join(answer)
        answer = answer.replace("?","a")

        if len(match_index) == 1:
            print(answer)

        else:
            for i in match_index[1:]:
                tmp_ans = list(S)
                tmp_ans[i:i + T_LEN] = list(T)
                tmp_ans = "".join(tmp_ans)
                tmp_ans = tmp_ans.replace("?","a")
                answer = min(tmp_ans,answer)

            print(answer)

if __name__ == '__main__':
    main()

Solution (Python):


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

    permit_index = []
    for i in range(len(S)-LENT+1):
        for si in range(LENT):
            if S[i:i+LENT][si] == T[si] or S[i:i+LENT][si]=="?":
                continue
            else:
                break
        else:
            permit_index.append(i)

    if not permit_index:
        print("UNRESTORABLE")
        return

    answer = S.replace("?","z")
    S = S.replace("?","a")
    for i in permit_index:
        s = S[:i]+T+S[i+LENT:]
        answer = min(answer,s)
    
    print(answer)
    return

if __name__ == '__main__':
    main()

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

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[i]!=t[i] and s[i]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Solution (Python):
s=input()
t=input()
m=len(s)
n=len(t)
check=False
for i in range(m-n,-1,-1):
  check2=True
  for j in range(i,i+n):
    if s[j]=='?' or s[j]==t[j-i]:
      continue
    else:
      check2=False
  if check2:
    check=True
    s=s[:i]+t+s[i+n:]
    s=s.replace('?','a')
    break
print(s if check else 'UNRESTORABLE')

Solution (Python):
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

tmp = True
anss = -1
anse = -1
for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        anss = i
        anse = i + len(T)

if anss == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:anss] + T + ans[anse:]
    print(ans)

Solution (Python):
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

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

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

tmp = True
anss = -1
anse = -1
for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        anss = i
        anse = i + len(T)

if anss == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:anss] + T + ans[anse:]
    print(ans)

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

n = len(S)
m = len(T)

for i in range(n-m,-1,-1):
    K = []
    K = S[i:i+m]
    
    for j in range(m):
        if K[j] == "?":
            K[j] = T[j]
    if K == T:
        print("".join((S[:i]+T+S[i+m:])).replace("?","a"))
        sys.exit()

print("UNRESTORABLE")

Solution (Python):
S0 = list(input())
T = list(input())
m = len(S0)
n = len(T)

def f(s,c):
    for i in range(len(s)):
        if s[i] == '?':
            s[i] = c
    return s

res = ['{']

for i in range(m-n+1):
    tmp = S0[:]
    for j in range(n):
        if tmp[i+j] == '?':
            tmp[i+j] = T[j]
        elif tmp[i+j] != T[j]:
            break
        if j == n-1:
            tmp = f(tmp,'a')
            res = min(res,tmp)

if res == ['{']:
    print('UNRESTORABLE')
else:
    print(''.join(res))

Solution (Python):
"""
出典:https://atcoder.jp/contests/abc076/tasks/abc076_c
"""

def main():
  S, T = input(), input()
  if len(S)<len(T):
    print("UNRESTORABLE")
    return

  p_flg=False

  for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
      if S[len(S)-len(T)-i:len(S)-i][j] == T[j]:
        continue
      else:
        if S[len(S)-len(T)-i:len(S)-i][j] == '?':
          continue
        else: 
          break
    else:
      S2 = S[:len(S)-len(T)-i] + T + S[len(S)-i:]
      p_flg=True
      break
  if p_flg:
    print(S2.replace('?','a'))
    return
  else:
    print("UNRESTORABLE")
    return

if __name__ == "__main__":
  main()

Solution (Python):
from itertools import permutations
import re


def main():
    s = input().replace('?', '.')
    t = input()

    for i in reversed(range(len(s) - len(t) + 1)):
        
        if re.search(s[i:i + len(t)], t):
            result = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
            print(result)
            return

    print('UNRESTORABLE')

main()

Solution (Python):
w=input()
w1=input()
num=len(w)
num1=len(w1)
start=-1
if num<num1:
  b1=False
for i in range(num-num1+1):
  b=True
  for j in range(num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
if start==-1:
  print("UNRESTORABLE")
else:
  word=""
  for i in range(num):
    if i<start:
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
    elif start<=i and i<=start+num1-1:
      word+=w1[i-start]
    else:
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
  print(word)

Solution (Python):
def Compare(Ca,Ta):
    if all(Ca[i]==Ta[i] or Ca[i] == "?" for i in range(len(Ca))):
        return 1
    else: return 0
           
S = input()
T = input()
ans = "UNRESTORABLE"
for i in range(1+len(S)-len(T)):
    Comp = S[len(S)-len(T)-i:len(S)-i]
    if Compare(Comp,T):
        ans = S[:len(S)-len(T)-i]+T+S[len(S)-i:]
        ans = ans.replace("?","a")
        break
print(ans)

Solution (Python):
sd = input()
t = input()
li_answer = list()
c_loop = len(sd) - len(t) + 1

for i in range(c_loop):
    if all((w_sd == "?" or w_sd == w_t) for w_sd, w_t in zip(sd[i:i + len(t) + 1], t)):
        s_tmp = str(sd[0:i] + t + sd[i + len(t):]).replace("?", "a")
        li_answer.append(s_tmp)

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

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

Solution (Python):
s_prime=str(input())
t=str(input())
def solve(s_prime,t):
  ls=len(s_prime)
  lt=len(t)
  for i in range(ls-lt+1):
    temp='?'*(ls-lt-i)+t+'?'*i
    
    f=True
    for j in range(ls):
      if s_prime[j]=='?':
        continue
      elif temp[j] in ['?',s_prime[j]]:
        continue
      f=False
    if f==True:
      ans=''
      for j in range(ls):
        if temp[j]=='?':
          if s_prime[j]=='?':
            ans+='a'
          else:
            ans+=s_prime[j]
        else:
          ans+=temp[j]
      return ans
  return 'UNRESTORABLE'
  
print(solve(s_prime,t))

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

for i in reversed(range(len(S)-len(T)+1)):
  c=0
  for j in range(len(T)):
    if S[i+j]==T[j] or S[i+j]=="?":
      c+=1
    else:
      break
  if c==len(T):
    for j in range(len(T)):
      S[i+j]=T[j]
    for k in range(len(S)):
      if S[k]=="?":
        S[k]="a"
    print("".join(S))
    exit()

print("UNRESTORABLE")

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


S_list = []
for T_first_idx in range(len(S_prime) - len(T) + 1):
    ok_flg = 1
    for i in range(len(T)):
        if S_prime[T_first_idx+i] != "?" and S_prime[T_first_idx+i] != T[i]:
            ok_flg = 0
    if ok_flg == 1:
        S_list.append(S_prime[:T_first_idx] + T + S_prime[T_first_idx+len(T):])
        
if len(S_list) == 0:
    print("UNRESTORABLE")
else:
    print(min(S_list).replace("?", "a"))

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

rs = list(S[::-1])
rt = list(T[::-1])

idx = None
for i in range(len(rs)-len(rt)+1):
  flg = True
  for j in range(len(rt)):
    si = i + j
    if rs[si] != rt[j] and rs[si] != '?':
      flg = False
  if flg:
    idx = i
    break

if idx is None:
  print('UNRESTORABLE')
else:
  for i in range(idx, idx+len(rt)):
    rs[i] = rt[i-idx]
  for i in range(len(rs)):
    if rs[i] == '?':
      rs[i] = 'a'
  print("".join(rs[::-1]))

Solution (Python):

S = input()
T = input()

if len(T)>len(S):
    ans = "UNRESTORABLE"
else:
    Slr = list(S[::-1])
    Tlr = list(T[::-1])
    for i in range(len(S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
                pass
            else:
                flag = False
                break
        if flag:
            for j in range(len(T)):
                Slr[i+j] = Tlr[j]
            for j in range(len(S)):
                if Slr[j]=="?":
                    Slr[j] = "a"
            ans = ("".join(Slr[::-1]))
            break
        else:
            if i==len(S)-len(T):
                ans = "UNRESTORABLE"
print(ans)

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

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

def check(in_str,out_str):
  for i,j in zip(in_str,out_str):
    if j == "?" or i==j:
      continue
    else:
      return False
  else:
    return True
  
for i in range(len(S)-len(T),-1,-1):
  if check(T, S[i:i+len(T)]):
    print((S[:i]+T+S[i+len(T):]).replace("?","a"))
    break
else:
  print("UNRESTORABLE")

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



index = None
for i in range(len(S)):
    if S[i] == T[0] or S[i] == '?':
        
        start = i
        cnt = 0
        for j in range(i, min(len(T)+i, len(S))):
            if S[j] == T[j-i] or S[j] == '?':
                cnt += 1
            else:
                break

        if cnt == len(T):
            index = start  

if index != None:
    i = 0
    ans = ""
    while len(S) > i:
        if i != index:
            if S[i] == '?':
                ans += 'a'
            else:
                ans += S[i]
            i += 1
        elif i == index:
            ans += T
            i += len(T)

    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):

def is_match(s1,s2):
  if len(s1)!=len(s2):
    return False
  count=0
  for i in range(len(s1)):
    if s1[i] == s2[i] or s1[i]=='?' or s2[i]=='?':
      count+=1
  if count==len(s1):
    return True
  else:
    return False        

rs = list(reversed(input()))
rt = list(reversed(input()))  
  
si = 0
while si <len(rs):  
  tmp = rs[si:si+len(rt)]
  
  if is_match(tmp,rt):  
    rs[si:si+len(rt)] = rt
    break
  else:
    si+=1

if si==len(rs):
  print('UNRESTORABLE')
else:
  print(''.join(rs).replace('?','a')[::-1])

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

Solution (Python):
Sprime = input() 
T = input() 
S = [] 
if len(Sprime) < len(T): 
    print("UNRESTORABLE")
    exit()
for i in range(len(Sprime) - len(T) + 1): 
    flag = 0 
    if Sprime[i] == T[0] or Sprime[i] == "?":
        for j in range(len(T)):
            if Sprime[i + j] != T[j] and Sprime[i + j] != "?": 
                flag += 1
                break
        if flag != 1:
            S.append(Sprime[0 : i].replace("?", "a") + T + Sprime[i + len(T) :].replace("?", "a")) 
S.sort() 
if S == []: 
    print("UNRESTORABLE")
else: 
    print(S[0])

Solution (Python):

Sdash = list(str(input()))
T = list(str(input()))










presence_flag = 0

for i in range(len(Sdash)-len(T),-1,-1):
    pickuped = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if T[j] != pickuped[j] and pickuped[j] != "?":
            break
    else:
        presence_flag = 1
        if Sdash[i:i+len(T)] != T: 
            Sdash[i:i+len(T)]=T
            break
        
if presence_flag == 1:
    for i in range(len(Sdash)):
        if Sdash[i]=="?":
            Sdash[i]="a"
    print(''.join(map(str, Sdash)))
else:
    print("UNRESTORABLE")

Solution (Python):
s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[j]=='?' or k[j]==t[j]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNRESTORABLE')

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

for i in range(len(S)-len(T),-1,-1):
  flag = True
  j = 0
  while (j<len(T)):
    if S[i+j] == '?' or S[i+j] == T[j]:
      j += 1
    else:
      flag = False
      break
  if flag:
    S = list(S)
    for j in range(len(T)):
      S[i+j] = T[j]
    print(''.join(S).replace('?','a'))
    exit()
print('UNRESTORABLE')

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

ans=''
for i in range(len(S)-len(T)+1):
  for j in range(i,i+len(T)):
    if S[j]!=T[j-i] and S[j]!='?':
      break
  else:
    ans=S[:i]+T+S[i+len(T):]
if ans=='':
  print('UNRESTORABLE')
else:
  for i in range(len(ans)):
    if ans[i]=='?':
      ans[i]='a'
  print(*ans,sep='')