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):
Sp = input()
T = input()
NSp = len(Sp)
NT = len(T)

for i in range(NSp-NT+1):
  Snow = Sp[NSp-NT-i:NSp-i]
  for j in range(NT):
    if (Snow[j]=='?') or (Snow[j]==T[j]):
      continue
    else:
      break
  else:
    ans = ''
    for k in range(NSp):
      if (NSp-NT-i<=k) and (k<=NSp-i-1):
        ans += T[k-NSp+NT+i]
      else:
        if Sp[k] == '?':
          ans += 'a'
        else:
          ans += Sp[k]
    print(ans)
    break
else:
  print('UNRESTORABLE')

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

for i in range(len(s)-len(t)+1):
    ok = 1
    memo = "".join(s[0:i])
    
    for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != "?":
            
            ok = 0
            break
        memo += t[j]

    if ok == 1:
        memo += "".join(s[i+j+1:])
        if ans == "":
            ans = memo
        if ans > memo:
            ans = memo




if ans =="":
    print("UNRESTORABLE")
else:
    print(ans.replace("?","a"))

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

Solution (Python):
Sprime = input()
T = input()
Slist = list(Sprime)
Tlist = list(T)
s = len(Sprime)
indexis = []
possibilities = set()
for i in range(s):
  if(Slist[i] != "?"):
    indexis.append(i)
    
for i in range(s- len(T)+ 1):
  key = []
  for p in range(i):
    key.append("?")
  key.extend(Tlist)
  for q in range(s- i- len(T)):
    key.append("?")
  flag = 0
  for j in indexis:
    if(Sprime[j] != key[j] and key[j] != "?"):
      flag = 1
      break
  if(flag == 0):
    for k in indexis:
      if(key[k] == "?"):
        key[k] = Sprime[k]
    for l in range(s):
      if(key[l] == "?"):
        key[l] = "a"
    ans = ""
    for r in range(s):
      ans+= key[r]
    possibilities.add(ans)
    
if(possibilities == set()):
  print("UNRESTORABLE")
else:
  
  print(min(possibilities))

Solution (Python):
s = input()
t = input()
s = s[::-1]
t = t[::-1]
s_size, t_size = len(s), len(t)
result = "UNRESTORABLE"

for i in range(s_size - t_size + 1):
    for j in range(t_size):
        if s[i + j] != t[j] and s[i + j] != '?':
            break
    else:
        break
else:
    print(result)
    exit()
s = (s[:i] + t + s[i + t_size :]).replace('?', 'a')
result = s[::-1]
print(result)

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

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

sn = len(s)
tn = len(t)

l = r = -1
for i in range(sn, -1, -1):
    if i+tn > sn:
        continue

    if all(sc == tc or sc == "?" for sc, tc in zip(s[i:i+tn], t)):
        l, r = i, i+tn
        break

if l == -1:
    print("UNRESTORABLE")
    exit()

i = 0
while i < sn:
    if l <= i < r:
        print(t[i-l], end="")
    else:
        if s[i] == "?":
            print("a", end="")
        else:
            print(s[i], end="")
    
    i += 1

print()

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate

from heapq import heapify,heappop,heappush


from functools import lru_cache


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    

    
    
    
    
    
    s=input()
    t=input()
    lt,ls=len(t),len(s)
    if lt>ls:
        print('UNRESTORABLE')
        return
    for i in range(ls-lt,-1,-1):
        sc=s[i:i+lt]
        flag=True
        for tt,ss in zip(t,sc):
            if ss!='?' and tt!=ss:
                flag=False
                break
        if flag:
            break
    if not flag:
        print('UNRESTORABLE')
        return 
    ans=""
    for k in range(ls):
        if i<=k<i+lt:
            ans+=t[k-i]
        elif s[k]=='?':
            ans+="a"
        else:
            ans+=s[k]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import re


S = input().replace('?', '.')
T = input()
ls = len(S)
lt = len(T)

for i in range(ls-lt,-1,-1):
    
    if re.match(S[i:i+lt], T):
        S = S.replace('.', 'a')
        
        S = (S[:i]+T+S[i+lt:])
        print(S)
        exit(0)
print('UNRESTORABLE')

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

 
s = list(input())
T = list(input())


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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

 
s = input()
T = input()


for i in range(len(s)-len(T), -1, -1):
	for j in range(len(T)):
		if s[i+j] != T[j] and s[i+j] != "?":
			break
	else:
		p = s[:i] + T +  s[i+len(T):]
		ans = ""
		for i in range(len(p)):
			if p[i] == "?":
				ans += "a"
			else:
				ans += p[i]
		print(ans)
		break
else:
	print("UNRESTORABLE")

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

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

Sdl = len(Sd)
Tl = len(T)

ans_str = ''


for i in reversed(range(Sdl - Tl + 1)):
  
  if Sd[i] == T[0] or Sd[i] == '?':
    is_match = True
    
    for j in range(Tl):
      
      if Sd[i + j] != T[j] and Sd[i + j] != '?':
        is_match = False
        break
    
    if is_match:
      ans_str = Sd[:i] + T + Sd[i + Tl:]
      break

if ans_str:
  print(ans_str.replace('?', 'a'))
else:
  print('UNRESTORABLE')

Solution (Python):
s = input()
t = input()
ans = 'UNRESTORABLE'
r = []

for i in range(len(s)):
    cnt = 0
    idx = i
    for j in range(len(t)):
        if s[idx] == t[j] or s[idx] == "?":
            cnt += 1
        else:
            break
        if cnt == len(t):
            r.append((s[:i]+t+s[idx+1:]).replace('?','a'))
        if idx+1 <= len(s)-1:
            idx += 1
        else:
            break

if len(r) == 0:
    print(ans)
else:
    print(sorted(r)[0])

Solution (Python):
ret = 'UNRESTORABLE'
sd = input()
t = input()
idxs = []
for i in range(len(sd)-len(t)+1):
    ext_s = sd[i:len(t)+i]
    mach_flag = True
    for j in range(len(t)):
        if( ext_s[j] != t[j] and  ext_s[j] != '?' ):
            mach_flag = False
            break
    if mach_flag :
        idxs.append(i)

            
if len(idxs) == 0:
    print('UNRESTORABLE')
else:
    sList = []
    for idx in idxs:
        s = sd[:idx] + t + sd[idx+len(t):]
        s = s.replace('?', 'a')
        sList.append(s)
    sList.sort()
    print(sList[0])

Solution (Python):
SS = list(input())
T = list(input())
list = []

for i in range(len(SS)):
    target = SS[:]
    flg = False
    for j in range(len(T)):
        if i + j == len(SS):
            break
        if i + j == len(SS) or (
            target[i + j] != "?" and target[i + j] != T[j]
        ):
            break
        target[i + j] = T[j]
        if j == len(T) - 1:
            flg = True
    if flg is True:
        list.append("".join(target).replace("?", "a"))

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

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

x = "UNRESTORABLE"

sl = len(s)
tl = len(t)


if sl < tl:
    print(x)
    exit()

flag =0

for i in range(sl-tl,-1,-1):
    temp = s[i:i+tl]
    for j in range(tl):
        if temp[j] == t[j] or temp[j] =="?":
            if j == tl-1:
                x = s[:i] + t + s[i+tl:]
                flag = 1
                break            
        else:
            break

    if flag ==1:
        break

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

print(x)

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

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

print("UNRESTORABLE")

Solution (Python):
s = str(input())
t = str(input())
L = []
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:
        ns = s[:i] + t + s[i+len(t):]
        ns = ns.replace('?', 'a')
        L.append(ns)
L.sort()
if L:
    print(L[0])
else:
    print('UNRESTORABLE')

Solution (Python):
Sp = input()
Sp_list = list(Sp)
N = len(Sp)
T = input()
n = len(T)

def check(s, t):
  for si, ti in zip(s, t):
    if si == '?':
      continue
    if si != ti:
      return False
  return True

ans = []
for i in range(N-n+1):
  if check(Sp[i:i+n], T):
    ans.append(''.join(Sp_list[:i] + list(T) + Sp_list[i+n:]).replace('?', 'a'))
    
if ans:
  ans.sort()
  print(ans[0])
else:
  print('UNRESTORABLE')

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


def check_match(a, b):
  m = len(a)
  for i in range(m):
    if not (a[i] == '?' or a[i] == b[i]):
      return False
  return True


def calc_possible_s(s, t):
  """
  Args:
    s, t (str)
  Returns:
    list[str]
  """
  buf = []
  n, m = len(s), len(t)
  assert n >= m
  for i in range(n-m+1):
    
    if check_match(s[i:i+m], t):
      buf.append(s[:i].replace('?', 'a') + t + s[i+m:].replace('?', 'a'))
  return buf


if len(t) > len(s):
  print('UNRESTORABLE')
else:
  possible_s = calc_possible_s(s, t)
  if possible_s:
    print(min(possible_s))
  else:
    print('UNRESTORABLE')

Solution (Python):
from copy import deepcopy

S = input()
T = input()

candidate = []
ln = len(S) - len(T) + 1
for i in range(ln):
    if S[i] == T[0] or S[i] == '?':
        for s, t in zip(S[i:i+len(T)], T):
            if not(s == t or s == '?'):
                break
        else:
            candidate.append(i)

if candidate == []:
    print('UNRESTORABLE')
    exit()

ans = []
for i in candidate:
    tmp_s = list(deepcopy(S))
    tmp_s[i:i+len(T)] = list(T)
    tmp_s = ['a' if c == '?' else c for c in tmp_s]
    ans.append(''.join(tmp_s))

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

Solution (Python):

"""
Created on Sun May 31 14:28:43 2020

@author: NEC-PCuser
"""

S = input()
T = input()

start = -1

i = 0
for i in range(0, len(S) - len(T) + 1):
    k = 0
    for b in T:
        if S[i + k] != b and S[i + k] != '?':
            break
        k += 1
    else:
        start = i

if start == -1:
    print("UNRESTORABLE")
else:
    s = list(S)
    s[start:start + len(T)] = T
    S = "".join(s)
    
    print(S.replace('?', 'a'))

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

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

flag = False
for k in reversed(range(len(S)-len(T)+1)):
    
    if match(k):
        S = S[:k] + T + S[k+len(T):]
        flag = True
        break
    
if flag:
    ans = S.replace("?","a")

if not flag:
    ans = "UNRESTORABLE"

print(ans)

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

Solution (Python):
S1 = input()
T = input()
N = len(S1)
M = len(T)


ans = ""

for i in range(N-M+1):
    jdg = True
    for k in range(M):
        if not (T[k] == S1[i+k] or S1[i+k] == "?"):
            jdg = False
    if jdg:
        ans = S1[:i] + T + S1[i+M:]
        
if ans == "":
    print("UNRESTORABLE")
else:
    print(ans.translate(str.maketrans({'?': 'a'})))

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





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

    flg = False
    for i in range(len(s) - len(t), -1, -1):
        tmp_flg = True
        for j in range(len(t)):
            if not (s[i + j] == t[j] or s[i + j] == "?"):
                tmp_flg = False
                break
        if tmp_flg:
            s = s[:i] + t + s[i + len(t):]
            flg = True
            break

    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"

    if flg:
        print(*s, sep="")
    else:
        print("UNRESTORABLE")


if __name__ == '__main__':
    main()

Solution (Python):
Sp = str(input())
T = str(input())
n = len(T)
a = [] 
b = [] 
for i in range(len(Sp)-n+1):
  X = Sp[i:i+n]
  cnt = 0
  for j in range(n):
    if X[j] != '?':
      if X[j] != T[j]:
        break
      else:
        cnt += 1
    else:
      cnt += 1
  if cnt == n:
    a.append(i)
if a == []:
  print('UNRESTORABLE')
  exit()
for i in a:
  S1 = Sp[:i]
  S2 = Sp[i+n:]
  S3 = S1.replace('?', 'a')
  S4 = S2.replace('?', 'a')
  b.append(S3 + T + S4)
b.sort()
print(b[0])

Solution (Python):
import sys
input = sys.stdin.readline
S = input().rstrip()
T = input().rstrip()
S_len = len(S)
T_len = len(T)
index = -1
if S_len < T_len:
  print('UNRESTORABLE')
  sys.exit()
for i in range(S_len-T_len+1):
  for j in range(T_len):
    if not(S[i+j] == T[j] or S[i+j] == '?'):
      break
    if j == T_len-1:
      index = max(index,i+j)
if index == -1:
  print('UNRESTORABLE')
  sys.exit()
else:
  ans = ''
  for i in range(S_len):
    if S[i]=='?':
      if index-T_len+1 <= i <= index:
        ans += T[i-index+T_len-1]
      else:
        ans += 'a'
    else:
      ans += S[i]
print(ans)

Solution (Python):
s = list(map(str, input().rstrip()))
t = list(map(str, input().rstrip()))

ans = []
for i in range(len(s) - len(t) + 1):
    tmp = []
    for j in range(len(t)):
        if s[i:][j] == t[j] or s[i + j] == "?":
            tmp.append(True)
        else:
            tmp.append(False)
    if all(tmp):
        tmp_l = [x.replace("?", "a") for x in s[:i]]
        tmp_r = [x.replace("?", "a") for x in s[i + j + 1:]]
        ans.append(tmp_l + t + tmp_r)

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

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):
def main():
    UNRESTORABLE = 'UNRESTORABLE'
    INIT = 'z' * 51

    S = input()
    N = len(S)

    T = input()
    M = len(T)

    ans = INIT
    for i in range(N):
        if (N - i) < M: break
        *B, = S
        for j in range(M):
            if (B[i + j] != '?') and (B[i + j] != T[j]): break
            B[i + j] = T[j]
        else:
            ans = min(ans, (''.join(B)).replace('?', 'a'))

    if ans == INIT:
        print(UNRESTORABLE)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
import string

def main():
    S = list(input())
    T = list(input())
    accept = False
    for i in reversed(range(len(S)-len(T)+1)):
        match = True
        for j,s in enumerate(S[i:i+len(T)]):
            if s != T[j] and s != '?':
                match = False
                break
        if match:
            S[i:i+len(T)] = T
            accept = True
            break
    if accept:
        print(''.join(S).replace('?','a'))
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

S = input()
st = len(S)
T = input()
nt = len(T)
ans = []
for i in range(st - nt + 1):
    judge = S[i:i + nt]
    flag = True
    for j in range(nt):
        if judge[j] != '?' and judge[j] != T[j]:
            flag = False
    if flag:
        ans.append(i)
alta = list(S)
for i in range(st):
    if alta[i] == "?":
        alta[i] = "a"
strlist = []
if len(ans) > 0:
    for i in ans:
        base = copy.deepcopy(alta)
        for j in range(nt):
            base[i + j] = T[j]
        strlist.append(''.join(base))
    strlist.sort()
    print(strlist[0])
else:
    print('UNRESTORABLE')

Solution (Python):
def printans(n):
    S = Sd[:len(Sd)-n] + T + Sd[len(Sd)-n+len(T):]
    print(S.replace('?','a'))

Sd = input()
T = input()
searching = 1
wilds_seq = 0
for i in range(1,len(Sd)+1):
    if Sd[-i] == T[-searching] or Sd[-i] == '?':
        if searching == len(T):
            printans(i)
            break
        else:
            searching += 1
            if Sd[-i] == '?':
                wilds_seq += 1
            else:
                wilds_seq = 0
    else:
        while wilds_seq > 0:
            wilds_seq -= 1
            searching -= 1
            if Sd[-i] == T[-searching]:
                searching += 1
                wilds_seq = 0
                break
        else:
            searching = 1
            wilds_seq = 0
            if len(T) >= 1:
                if Sd[-i] == T[-1]:
                    searching += 1
else:
    print('UNRESTORABLE')

Solution (Python):
import copy

sd = str(input())
t = str(input())
s = copy.deepcopy(sd)

flg = False
pin = -1
for i in reversed(range(len(sd)-len(t)+1)):
    for j in range(len(t)):
        if sd[i+j] != t[j] and sd[i+j] != '?':
            break
        elif j == len(t)-1:
            flg = True
            pin = i
            break
    if flg:
        break
if flg:
    s = s[0:pin] + t + s[pin+(len(t)):]
    s = s.replace('?', 'a')
    print(s)
else:
    print('UNRESTORABLE')

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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 make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





s = S()
t = S()

Ns = len(s)
Nt = len(t)

if Nt>Ns:
  print("UNRESTORABLE")
  exit()
  
bag = set()
for i in range(Ns-Nt+1):
  flag = 1
  cut = s[i:i+Nt]
  now = ""
  for j in range(Nt):
    if cut[j] == "?":
      now += t[j]
    else:
      if cut[j] != t[j]:
        flag = 0
      else:
        now += t[j]
  if flag:
    bag.add((s[:i] + now + s[i+Nt:]).replace("?","a"))

bag = list(bag)
if not bag:
  print("UNRESTORABLE")
else:
  bag.sort()
  print(bag[0])

Solution (Python):
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = []

for i in range(N-M+1):
    tmp_S = S[:]
    if S[i] == "?" or S[i] == T[0]:
        tmp_S[i] = T[0]
        tmp = 1
        for j in range(i+1, i+M):
            if S[j] == "?" or S[j] == T[tmp]:
                tmp_S[i+tmp] = T[tmp]
                tmp += 1
            else:
                break
        tmp_S = "".join(tmp_S)
        if T in tmp_S:
            tmp_S = tmp_S.replace("?", "a")
            ans.append(tmp_S)

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

Solution (Python):
s=[x for x in input()]
t=[x for x in input()]
ans=[]
for i in range(len(s)):
  cnt=0
  nowi=i
  fi=i
  for j in range(len(t)):
    if s[nowi]==t[j] or s[nowi]=="?":
      cnt+=1
    else:
      break
    if cnt==len(t):
      ans.append((s[:fi]+t+s[nowi+1:]))
    if nowi+1<=len(s)-1:
      nowi+=1
    else:
      break

A=[]
if len(ans)==0:
  print("UNRESTORABLE")
else:   
  for i in ans:
    moji=""
    for m in i:
      if m=="?":
        moji+="a"
      else:
        moji+=m
    A.append(moji)
  A.sort()
  print(A[0])

Solution (Python):
import re
S = str(input())
T = str(input())
S = S.replace("?",".")

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
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
t=SI()
n=len(s)
u=len(t)
mx=-1
for i in range(n-u+1):
    count=0
    for j in range(u):
        
        if s[i+j]==t[j] or s[i+j]=="?":
            count+=1
    if count==u:
        mx=i

if mx<0:
    print("UNRESTORABLE")
else:
    for i in range(mx):
        if s[i]=="?":
            print("a",end="")
        else:
            print(s[i],end="")
    print(t,end="")
    for i in range(mx+u,n):
        if s[i]=="?":
            print("a",end="")
        else:
            print(s[i],end="")

Solution (Python):

import  sys


def main():
    s = sys.stdin.readline().strip()
    t = sys.stdin.readline().strip()
    words = list()

    for i in range(len(s)-len(t)+1):
        u = s[i:i+len(t)]
        u = "".join([ p if q is "?" else q for p,q in zip(t,u) ]).strip()

        if t == u:
            v = s[0:i] + t + s[i+len(t):]
            words.append( v.replace("?", "a") )

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

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
S = input()
T = input()
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')
    sys.exit()

for i in range(s - t, -1, -1):
    OK = True
    for j in range(t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
    if OK:
        for j in range(t):
            SS = S[:i] + T + S[i + j + 1:]
            SS = SS.replace('?', 'a')
        print(SS)
        sys.exit()

print('UNRESTORABLE')

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

l0 = len(s)
l = len(t)


def chk(n):
    x = s[n:n+l]
    flg = True
    for j in range(l):
        if x[j] != t[j] and x[j] != "?":
            flg = False
    return flg


res = []
for i in range(l0 - l + 1):
    if chk(i):
        res.append(i)

ans = []
if not res:
    print("UNRESTORABLE")
else:
    p = res[-1]
    y = s[:p] + t + s[p+l:]
    z = y.replace("?", "a")
    print(z)

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

ans = 'UNRESTORABLE'

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

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

ans = 'UNRESTORABLE'

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

    if flag:
        ans = []
        for j in range(len(S)): ans.append(S[j])
        for j in range(len(T)): ans[i+j] = T[j]
        for j in range(len(S)):
            if ans[j] == '?': ans[j] = 'a'
            
for i in range(len(ans)):
    print(ans[i], end='')
print()

Solution (Python):
import re
S = str(input())
T = str(input())
S = S.replace("?",".")

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