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, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
pre_S = S
T = input()
s = len(S)
t = len(T)
key = []
for i in range(len(S)-len(T)+1):
    
    same = 0
    for j, y in enumerate(S[i:i+t]):
        if y == "?":
            same += 1
            continue
        else:
            if y == T[j]:
                same += 1
    if same == t:
        
        key.append(i)
    

if key:
    ans = "z" * 60
    for i in key:
        S_ = S[:i] + T + S[i+t:]
        tmp = ""
        for i in range(len(S_)):
            if S_[i] == "?":
                tmp += "a"
            else:
                tmp += S_[i]
        ans = min(ans, tmp)
    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = list(deepcopy(s))
i = len(s) - len(t)
while i >= 0:
    flag = True
    for j in range(len(t)):
        if s[i + j] != '?' and s[i + j] != t[j]:
            flag = False
    if flag:
        ans[i:i + len(t)] = list(t)
        break
    i -= 1
if ''.join(ans) == s and '?' in s:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))

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

L = [set() for _ in range(len(t))]
for i in range(len(t)):
    for j in range(len(s)):
        if s[j] == t[i] or s[j] == '?':
            L[i].add(j)


temp = set(range(len(s)))
for i in reversed(range(len(t))):
    temp = temp & L[i]
    if i != 0:
        temp = list(temp)
        temp = [p-1 for p in temp]
        temp = set(temp)


if len(temp) == 0:
    print('UNRESTORABLE')
    exit()

temp = list(temp)
temp.sort()
id = temp[-1]
s_ = list(s)
t_ = list(t)
s_[id:id+len(t)] = t_
ans = ''
for c in s_:
    if c == '?':
        ans += 'a'
    else:
        ans += c
print(ans)

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

Solution (Python):

S = input()
T = input()
Ns = len(S)
Nt = len(T)

cand = []

N = max(0, Ns - Nt + 1)
for i in range(N):
    for j in range(Nt):
        s = S[i + j]
        t = T[j]
        if s == t or s == "?":
            continue
        else:
            break
    else:
        pre = S[:i].replace("?", "a")
        suf = S[i+j+1:].replace("?", "a")
        cand.append(pre + T + suf)

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

Solution (Python):
S = input()
T = input()
if len(S) < len(T):
    print("UNRESTORABLE")
    exit(0)

def compare(s,t):
    if len(s) != len(t):
        return False
    else:
        for k in range(len(s)):
            if s[k] == "?" or t[k] == "?":
                pass
            else:
                if s[k] != t[k]:
                    return False
    return True
ans = []
for k in range(len(S)-len(T)+1):
    if compare(S[k:k+len(T)],T) == True:
        ans.append(S[:k].replace("?","a")+T+S[k+len(T):].replace("?","a"))

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

Solution (Python):
def match(i, j):
    if i == j: return True
    elif i == "?" or j == "?": return True
    else: return False

def solve():
    s = input()
    t = input()
    Ans = []
    for i in range(len(s) - len(t) + 1):
        
        l = list(s)
        for j in range(len(t)):
            if match(s[i + j], t[j]): 
                if s[i + j] == "?": l[i + j] = t[j]
            else: break
        else: 
            for k, w in enumerate(l):
                if w == "?": l[k] = "a"
            Ans.append("".join(map(str, l)))
    if len(Ans) == 0: print("UNRESTORABLE")
    else: 
        Ans.sort()
        print(Ans[0])

    return 0

if __name__ == "__main__":
    solve()

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

No = 'UNRESTORABLE'

if len(T)>len(Sd):
    print(No)
    exit()

ofs = []
for i in range(len(Sd)-len(T)+1):
    for j in range(len(T)):
        if Sd[i+j] != T[j] and Sd[i+j] != '?':
            break
    else:
        ofs.append(i)

if not ofs:
    print(No)
    exit()

ans = ''
offset = ofs[-1]
for i in range(len(Sd)):
    if offset <= i < offset+len(T):
        ans += T[i-offset]
    else:
        if Sd[i] == '?': ans += 'a'
        else: ans += Sd[i]
print(ans)

Solution (Python):
def main():
    S = input()
    T = input()
    N = len(S)
    M = len(T)
    for i in range(N-M+1)[::-1]:
        for s, t in zip(S[i:i+M], T):
            if s != t and s != "?":
                break
        else:
            return print(S[:i].replace("?", "a") + T + S[i+M:].replace("?", "a"))
    print("UNRESTORABLE")


if __name__ == '__main__':
    main()

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

def canMake(left):
    for s, t in zip(S[left:], T):
        if s == '?':
            continue
        if s != t:
            return False
    return True

ans = []
for left in range(len(S) - len(T) + 1):
    if canMake(left):
        Z = S[: left] + T + S[left + len(T):]
        ans.append(Z.replace('?', 'a'))

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

Solution (Python):
s=input()

t=input()

s=list(s)

t=list(t)

memo = -1

for i in range(len(s)-len(t)+1):
    count = 0
    for k, j in enumerate(range(i, i+len(t))):
        if s[j] == t[k] or '?' == s[j]:
            count += 1
    if count == len(t):
        memo = i

if memo == -1:
    print('UNRESTORABLE')
else:
    for k,l in enumerate(range(memo,memo+len(t))):
        s[l] = t[k]
    for g in range(len(s)):
        if s[g] == '?':
            s[g] = 'a'
    print(''.join(map(str,s)))

Solution (Python):
S = list(input())
T = list(input())
lenS = len(S)
lenT = len(T)
if lenS < lenT:
    print("UNRESTORABLE")
else:
    end = False
    for i in range(lenS - lenT, -1, -1):
        cnt = 0
        for j in range(lenT):
            if S[i + j] == T[j] or S[i + j] == "?":
                cnt += 1
            else:
                break
            if cnt == lenT:
                for k in range(lenT):
                    S[i + k] = T[k]
                end = True
        if end:
            ans = ""
            for k in range(lenS):
                if S[k] == "?":
                    S[k] = "a"
                ans = ans + S[k]
            print(ans)
            break
        if i == 0 and not end:
            print("UNRESTORABLE")

Solution (Python):
S0 = input()
S0_n = len(S0)
T = input()
T_n = len(T)

T_kouho = []

for i in range(S0_n-T_n, -1, -1):
  for j,k in enumerate(range(i,i+T_n)):
    if T[j] != S0[k] and S0[k] != '?':
      break
  else:
    T_kouho.append(i)
    break

if len(T_kouho) == 0:
  print('UNRESTORABLE')
else:
  i = 0
  for _ in range(S0_n):
    if i >= S0_n:
      break
    if i == T_kouho[0]:
      print(T, end='')
      i += T_n
    elif S0[i] == '?':
      print('a', end='')
      i+=1
    else:
      print(S0[i], end='')
      i+=1

Solution (Python):
s=input()
t=input()
def ga(i,t):
    turn=0
    for k in range(len(t)):
        if s[-(i+k)]!=t[-(k+1)] and s[-(i+k)]!='?':
            break
    else:
        turn+=1
    return turn
li=list(s)
li2=list(t)
for i in range(1,len(s)-len(t)+2):
    if ga(i,t)==1:
        for k in range(len(t)):
            li[-(i+k)]=li2[-(k+1)]
        n=''.join(li)
        break
else:
    print('UNRESTORABLE')
    exit()
print(n.replace('?','a'))

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

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

ans = ""
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:
        ans = s[:i] + t + s[i+j+1:]
        ans = ans[::-1]
        print(ans.replace("?", "a"))
        exit()
        
print("UNRESTORABLE")

Solution (Python):

s_ = list(input())
t = list(input())
ans = []
for i in range(len(s_) - len(t) + 1):
    s = s_.copy()
    flg = True
    for j in range(len(t)):
        if s_[i+j] == '?':
            s[i+j] = t[j]
        elif s_[i+j] == t[j]:
            continue
        else:
            flg = False
    if flg:
        s = ''.join(s).replace('?', 'a')
        ans.append(s)
        
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

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

len_S, len_T = len(S), len(T)



def judge(start):
    
    for j in range(len_T):
        if S[start+j] == '?':
            continue

        elif S[start+j] == T[j]:
            continue

        else:
            return False

    return True


for i in range(len_S - len_T, -1, -1):
    if judge(i):
        S = S[:i] + T + S[i+len_T:]
        S = S.replace('?', 'a')
        print(S)
        exit()

print('UNRESTORABLE')

Solution (Python):
sdash=input()
t=input()
rsdash=sdash[::-1]
rt=t[::-1]
anslist=[]
for i in range(len(sdash)-len(t)+1):
    count=0
    ans=rsdash
    if rsdash[i]==rt[0] or rsdash[i]=="?":
        for j in range(1,len(t)):
            if rsdash[i+j]==rt[j] or rsdash[i+j]=="?":
                count+=1
        if count==len(t)-1:
            ans=rsdash[:i]+rt+rsdash[i+len(t):]
            ans=ans.replace("?","a")
            anslist.append(ans[::-1])
anslist.sort()
if not anslist:
    print("UNRESTORABLE")
else:
    print(anslist[0])

Solution (Python):



'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
cnt = 0

for i in range(len(s)-len(t)+1)[::-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):
        cnt = i
        flg = True
        
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?", "a"))
    
    for j in range(len(t))[::-1]:
        
        li[cnt+j] = t[j]
    print("".join(li))

Solution (Python):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False

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):
        temp=i
        flg = True
        
 
if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    
    for j in range(len(t)):
        
        li[temp+j] = t[j]
    print("".join(li))

Solution (Python):
sp = list(input())
t = list(input())
flag = False
cnt = -1
l = len(t)
for i in range(len(sp) - l+1):
    for j in range(l):
        if sp[i+j]  == t[j] or sp[i+j]  == "?":
            pass
        else:
            break
    else:
        cnt = i
if cnt == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(sp)):
        if sp[i] == "?" :
            if not cnt<= i <cnt+l:
                sp[i] ="a"
            else :
                sp[i] = t[i-cnt]
    print("".join(sp))

Solution (Python):
import sys

def hantei(s,t):
  for i in range(len(s)):
    if s[i] == t[i] or s[i] == '?':
      pass
    else:
      return False
    
  return True

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

for i in reversed(range(len(s)-len(t)+1)):
  if hantei(s[i:i+len(t)], t):
    for j in range(len(t)):
      s[i+j] = t[j]
        
    print(''.join(s).replace('?', 'a'))
    sys.exit(0)
    
print("UNRESTORABLE")

Solution (Python):
import re
s, t = input().replace('?', '.'), input()
l, m = len(s), len(t)

if l < m:
    print("UNRESTORABLE")
    exit()

can = []  
for i in range(l - m + 1):
    if re.match(s[i:i + m], t):
        can.append((s[:i] + t + s[i + m:]).replace('.', 'a'))
print(min(can) if can else "UNRESTORABLE")

Solution (Python):
s = input()
t = list(input())
import sys
ans = []
for i in range(len(s)):
  S = list(s)
  if S[len(s)-len(t)-i] == t[0] or '?':
    m = int(len(s)-len(t)-i)
    
    if m >= 0:
      for j in range(len(t)):
        if S[m+j] == t[j] or S[m+j] == '?':
          S[m+j] = t[j]
          if j == len(t)-1:
            
            for i in range(len(S)):
              if S[i] == '?':
                S[i] = 'a'
            ans.append(''.join(S))
            break
        else:
          S = list(s)
          break
if ans == []:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(ans[0])

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

Solution (Python):

s = input()
t = input()
flag = 0
left = 0
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(1+len(s)-len(t)):
    for j in range(len(t)):
        
        if s[-i-j-1] == "?" or s[-i-j-1] == t[-j-1]:
            if j == len(t) -1 :
                flag = 1
                break
        else: break
    if flag == 1: 
        left = i
        break
    if i == len(s)-len(t):
        print("UNRESTORABLE")
        exit()

for i in range(len(s)):
    if i < len(s) - left - len(t) or i >= len(s) - left:
        if s[i] == "?":
            print("a",end = "") 
        else: print(s[i],end="")
    elif i < len(s) - left:
        print(t[i-(len(s) - left-len(t))],end="")

Solution (Python):
def main():
    s = input()
    s_list = list(s)
    t = input()
    for i in range(len(s) - len(t), -1, -1):
        sub_str = s[i:i+len(t)]
        for j in range(len(t) + 1):
            if j == len(t):
                print((s[:i] + t + s[i+len(t):]).replace("?", "a"))
                exit()
            if sub_str[j] == "?":
                continue
            elif sub_str[j] != t[j]:
                break
    print("UNRESTORABLE")


if __name__ == '__main__':
    main()

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

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

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

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


s_prime = input()
t = input()
ans_list = []
for i in range(len(s_prime) - len(t) + 1):
    if check(s_prime[i:i+len(t)], t):
        s = s_prime[:i] + t + s_prime[i+len(t):]
        ans = s.replace('?', 'a')
        ans_list.append(ans)
ans_list.sort()
if not ans_list:
    print('UNRESTORABLE')
else:
    print(ans_list[0])

Solution (Python):
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
numbers=[]
suuji=0
if n<0:
    print('UNRESTORABLE')
else:
    for c in range(n + 1):
        number = 0
        e=0
        for d in range(TN):
            if listSS[c + d] == listT[d] or listSS[c + d] == '?':
                number += 1


        if number == TN:
            e += c
            suuji += number
            numbers.append(e)
    if suuji ==0:
        print('UNRESTORABLE')
    else:
        mojiretu = []
        a=numbers[-1]
        A = int(a)
        moji = ''
        for b in range(TN):
            B = int(b)
            listSS[A + B] = listT[B]
        for z in listSS:
            moji += z

        answer = moji.replace('?', 'a')
        print(answer)

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

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

if sl < tl:
    print('UNRESTORABLE')
else:
    for i in range(sl-tl+1)[::-1]:
        flag = True
        for j in range(tl):
            if s[i+j] != '?' and s[i+j] != t[j]:
                flag = False
                break
        if flag:
            for j in range(sl):
                if i <= j < i + tl:
                    s[j] = t[j-i]
                    continue
                if s[j] == '?':
                    s[j] = 'a'
                    continue
            print(''.join(s))
            break
    if not flag:print('UNRESTORABLE')

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

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


for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

Solution (Python):

def main():
    import sys
    
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

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

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

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

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

ans = []

for i in range(len(S)-len(T)+1):
    for j, k in enumerate(S[i:i+len(T)]):
        if k == T[j] or k == "?":
            continue
        else: break
    else:
        box = S.copy()
        count = 0
        for x in range(len(S)):
            if i <= x < i + len(T):
                box[x] = T[count]
                count += 1
            elif box[x] != "?":
                continue
            else:
                box[x] = "a"
        ans.append(box)
ans = sorted(ans)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    print("".join(ans[0]))

Solution (Python):
s = input()
t = input()
sl = int(len(s))
tl = int(len(t))

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

print("UNRESTORABLE")

Solution (Python):
s = list(input())
t = list(input())
for i in range(len(s)-len(t)+1)[::-1]:
    for j in range(len(t)):
        if not s[i+j] == "?":
            if not s[i+j] == t[j]:
                break
    else:
        for j in range(len(t)):
            s[i+j] = t[j]
        for j in range(len(s)):
            if s[j] == "?":
                s[j] = "a"
        print("".join(s))
        break
else:
    print("UNRESTORABLE")

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

def match(s, t, lt, offset):
    for i in range(lt):
        if t[i] != s[offset+i] and s[offset+i] != '?':
            return False
    return True

def main():
    S = input()
    T = input()
    len_S = len(S)
    len_T = len(T)
    ans = list(S.replace('?','a'))
    for i in range(len_S-len_T+1):
        offset = len_S-len_T-i
        if match(S, T, len_T, offset):
            for j in range(len_T):
                ans[offset+j] = T[j]
            break
    else:
        print('UNRESTORABLE')
        exit()
    print(''.join(ans))

if __name__ == "__main__":
    main()

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

res=-1
ind=-1
for i in range(len(S_)-len(T)+1):
    flag=1
    for j in range(len(T)):
        if S_[i+j]=='?' or S_[i+j]==T[j]:
            continue
        else:
            flag=0
            break
    if flag:
        ind=i

if ind==-1:
    print('UNRESTORABLE')
    exit()

for t in T:
    S_[ind]=t
    ind+=1

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

print(''.join(S_))

Solution (Python):
import copy
s = list(input())
t = list(input())
ans_list = []
n = len(s)
m = len(t)
for i in range(n-m+1):
  s_copy = copy.copy(s)
  judgement = True
  for j in range(m):
    if s_copy[i+j] != "?" and s_copy[i+j] != t[j]:
      judgement = False
      break
    else:
      s_copy[i+j] = t[j]
  if judgement:
    ans_list.append(s_copy)
x = len(ans_list)
if ans_list != []:
  for l in range(x):
    for k in range(n):
      if ans_list[l][k] == "?":
        ans_list[l][k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")

Solution (Python):
s_ = input()
t = input()
flag = False
ans = 'z' * 51
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]:
            break
    else:
        flag = True
        s = list(s_[:i] + t + s_[i + len(t):])
        for i in range(len(s)):
            if s[i] == '?':
                s[i] = 'a'
        x = ''.join(s)
        ans = min(ans, x)
if flag:
    print(ans)
else:
    print('UNRESTORABLE')

Solution (Python):
import copy
s=list(map(str,input()))
t=list(map(str,input()))
def converta(s):
  for i in range(len(s)):
    if s[i]=='?':
      s[i]='a'
  return s
res=[]
for i in range(len(s)-len(t)+1):
    c=copy.copy(s)
    ok=True
    for j in range(len(t)):
        if t[j]!=s[i+j] and s[i+j]!='?':
            ok=False
            break
        else:
            c[i+j]=t[j]
    if ok:
        res.append(''.join(converta(c)))
if res==[]:
  print('UNRESTORABLE')
else:
  print(sorted(res)[0])

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


S = input()
T = input()
 
for i in reversed(range(len(S)-len(T)+1)):
    flag = 1
    for j in range(len(T)) :
        if S[i+j] != T[j] and S[i+j] != "?":
            flag = 0
    if flag:
        ans = S[:i] + T + S[i+len(T):]
        print(ans.replace("?", "a"))
        exit()
 
print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
if len(s)<len(t):
  print("UNRESTORABLE")
  exit()
n=len(s)
m=len(t)
for i in range(n-m,-1,-1):
  x=s[i:i+m]
  for j in range(m+1): 
    if j==m:
      print((s[:i]+t+s[i+m:]).replace("?","a"))
      exit()
    if x[j]=="?":
      continue
    elif x[j]!=t[j]:
      break
print("UNRESTORABLE")

Solution (Python):
def main():
    S = [s for s in input()]
    T = [t for t in input()]
    L = len(S)
    M = len(T)
    flag = 0
    ans = []
    for i in range(L-M+1):
        P = list(S)
        tmp = list(S[i:i+M])
        cnt = 0
        num = tmp.count('?')
        for j in range(M):
            if tmp[j] != '?' and tmp[j] != T[j]:continue
            elif tmp[j] == T[j]:
                cnt += 1
        if cnt == M-num:
            flag = 1
            for k in range(M):
                P[i+k] = T[k]
            ans.append(P)
            
    if flag:
        pnt = []
        while ans:
            X = ans.pop()
            for i in range(L):
                if X[i] == '?':
                    X[i] = 'a'
            pnt.append(X)
        pnt.sort()
        print(''.join(pnt[0]))
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    main()

Solution (Python):
import re
def end():
    print('UNRESTORABLE')
    exit()

s = input()
t = input()

l_s = len(s)
l_t = len(t)

if l_t > l_s:
    end()

for i in range(l_s - l_t +1):
    target = s[l_s-i-l_t:l_s-i]
    count = 0
    for s1, s2 in zip(target, t):
        if s1 == s2 or s1 == '?':
            count += 1
            if count == l_t:
                ans = re.sub('\?','a',s)
                print(ans[:l_s-i-l_t]+t+ans[l_s-i:])
                exit()
        else:
            break
end()

Solution (Python):
sd=input()
t=input()
n=len(sd)
m=len(t)
if n<m:
    print("UNRESTORABLE")
    exit(0)
for i in range(n-m,-1,-1):
    t_kana=sd[i:i+m]
    for j in range(m+1):
        if j==m :
            print((sd[:i]+t+sd[i+len(t):]).replace("?","a"))
            exit(0)
        if t_kana[j]=="?":
            continue
        elif t_kana[j]!=t[j]:
            break
print("UNRESTORABLE")

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

l = len(T)

ind = 51
for i in range(len(S)-l+1):
    flag = 0
    for j in range(l):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag = 1
    if flag==0:
        ind = i

if ind == 51:
    print('UNRESTORABLE')
    exit()

print(S[:ind].replace('?','a')+T+S[ind+l:].replace('?','a'))

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

s_reversed = list(reversed(S))
T_reversed = list(reversed(T))
F = 0

for i in range(len(S)-len(T)+1):
    s = s_reversed[i:i+len(T)]
    flag = 0
    for j in range(len(T)):
        if s[j] == T_reversed[j] or s[j] == '?':
            continue
        else:
            flag += 1
            break
    if flag ==0:
        F += 1
        for j in range(len(T)):
            s_reversed[i+j] = T_reversed[j]
        break

if F ==0:
    print('UNRESTORABLE')
else:
    R = ''.join(list(reversed(s_reversed)))
    print(R.replace('?','a'))

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


def is_valid(start, end):
    for t_i, s_i in enumerate(range(start, end)):
        if S[s_i] == "?" or S[s_i] == T[t_i]:
            continue
        else:
            return False
    return True


def assign(start, end):
    for t_i, s_i in enumerate(range(start, end)):
        S[s_i] = T[t_i]
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"


ok = False
for i in range(len_t-1, len(S))[::-1]:
    if S[i] == "?" or S[i] == T[-1]:
        start = i - len_t + 1
        end = i + 1
        if is_valid(start, end):
            ok = True
            assign(start, end)
            break

if ok:
    print("".join(S))
else:
    print("UNRESTORABLE")

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

key = [str(t[i]) for i in range(len(t))]
count = 0
sub = []

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]:
      break
    if j == len(t)-1:
      sub.append(i)


ans = [0]*len(s)
if sub:
  k = 0
  change = sub[-1]
  for i in range(len(s)):
    if i == change:
      for j in range(len(t)):
        ans[i+j] = t[j]
      k = len(t)-1
    elif k:
      k -= 1
    else:
      if s[i] == "?":
        ans[i] = "a"
      else:
        ans[i] = s[i]
  print("".join(ans))  
else:
  print("UNRESTORABLE")

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

lens = len(S) - len(T) + 1

for i in reversed(range(lens)) :
    flag = True
    for j in range(len(T)) :
        if S[i+j] != T[j] and S[i+j] != "?":
            flag = False
    if flag == True :
        ans = S[:i] + T + S[i+len(T):]
        print(ans.replace("?", "a"))
        exit()

print("UNRESTORABLE")

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def is_ok(sd, st, t):
	if len(sd) < st+len(t):
		return False
	for i, c in enumerate(sd[st:st+len(t)]):
		if c != '?' and t[i] != c:
			return False
	return True
	
def to_aaa(a_str):
	rr=list(a_str)
	for i, c in enumerate(rr):
		rr[i] = 'a' if c == '?' else c
	ret = ''.join(rr)
	return ret

def mk_s(a_s_dash, i, t):
	front = to_aaa(a_s_dash[:i])
	back = to_aaa(a_s_dash[i+len(t):])
	ret = front+t+back
	
	return ret
			
def main():
	s_dash = input()
	t=input()
	dd='UNRESTORABLE'
	qq='?'
	
	aa=[]
	for i, _ in enumerate(s_dash[:len(s_dash)+1]):
		
		if is_ok(s_dash,i,t):
			aa.append(mk_s(s_dash, i, t))
			
			
	if len(aa)>0:
		aa.sort()
		ret = aa[0]
		print(ret)
		return
		
	print(dd)
	return
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)