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_sub= input()
t = input()
ans = []
for i in range(len(s_sub) - len(t) + 1):
    for j, c in enumerate(t):
        if s_sub[i + j] != c and s_sub[i + j] != '?':
            break
    else:
        s = s_sub[:i] + t + s_sub[i + len(t):]
        sample = ''
        for c in s:
            if c == '?':
                sample += 'a'
            else:
                sample += c
        ans.append(sample)
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(min(ans))

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

if t > s:
	print("UNRESTORABLE")
else:
	ans = []
	for i in range(s - t + 1):
		ju = "YES"
		for j in range(t):
			if S[i + j] != "?" and S[i + j] != T[j]:
				ju = "NO"
				break
		if ju == "YES":
			x = S[:i] + T + S[i + t:]
			ans.append(x.replace("?", "a"))
	if ans == []:
		print("UNRESTORABLE")
	else:
		ans = sorted(ans)
		print(ans[0])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  t=S()

  for i in range(len(s)-len(t)+1)[::-1]:
    x=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
      if x[j]==t[j] or x[j]=='?':
        pass
      else:
        f=False

    if f:
      
      
      print(str(s[:i]+t+s[i+len(t):]).replace('?','a'))
      exit()

  print('UNRESTORABLE')

main()

Solution (Python):

import re
def solve(s,t):
    sc = s.replace("?",".")
    if lt > ls:
        return "UNRESTORABLE"
    ans = []
    s = s.replace("?","a")    
    for i in range(ls-lt+1):
        if re.match(sc[i:i+lt], t) is None:
            continue
        ans.append(s[:i]+ t + s[i+lt:])
    if not ans:
        return "UNRESTORABLE"
    return min(ans) 

S = input()
T = input()
ls = len(S)
lt = len(T)

print(solve(S,T))

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

is_ok = False
li = []
ans = '{'
for i in range(len(S)-len(T)+1):
    flag = True
    for ind,j in enumerate(T):
        if(S[i+ind]=='?' or S[i+ind]==j):
            pass
        else:
            flag = False
    if(flag):
        is_ok=True
        li.append(i)

if(is_ok):
    for i in li:
        s = S[:i]+T+S[i+len(T):]
        ans = min(ans,s.replace('?','a'))

    print(ans)
else:
    print('UNRESTORABLE')

Solution (Python):



S = input()
T = input()

candidates = []
for i in range(len(S) - len(T) + 1):
    yn = all(S[i + k] == "?" or S[i + k] == T[k] for k in range(len(T)))
    if yn:
        s = S[:i] + T + S[i + len(T) :]
        candidates.append(s)

if candidates:
    candidates = ["".join("a" if c == "?" else c for c in s) for s in candidates]
    print(min(candidates))
else:
    print("UNRESTORABLE")

Solution (Python):
S, T = input(), input()
if len(T) > len(S):
    print('UNRESTORABLE')
    exit()

able_list = []

for i in range(len(S) - len(T) + 1):
    S_part = S[i:len(T) + i]
    for j in range(len(T)):
        if S_part[j] == T[j] or S_part[j] == '?':
            if j == len(T) - 1:
                able_list.append(S[0:i] + T + S[len(T) + i:])
            continue
        else:
            break

if not able_list:
    print('UNRESTORABLE')
    exit()

for i in range(len(able_list)):
    able_list[i] = able_list[i].replace('?', 'a')

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

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

def hantei(a):
    for i in range(t):
        if S[a + i] != "?" and S[a + i] != T[i]:
            return(False)
    return(True)

def solve():
    p = s - t
    while p >= 0:
        if hantei(p):
            ans = ""
            for i in range(s):
                if i >= p and i < p + t:
                    ans += T[i - p]
                else:
                    if S[i] == "?":
                        ans += "a"
                    else:
                        ans += S[i]
            return(ans)
        else:
            p -= 1
    return("UNRESTORABLE")
print(solve())

Solution (Python):


import math
import sys


def main():
  Sn = list(str(input()))
  Tn = list(str(input()))
  ls = len(Sn)
  lt = len(Tn)

  if ls < lt:
    return 'UNRESTORABLE'

  ret = []
  for i in range(ls-lt+1):
    chk = True
    for j in range(lt):
      if Sn[i+j]!=Tn[j] and Sn[i+j]!='?':
        chk = False
    if chk:
      ret.append(''.join(Sn[:i]+Tn+Sn[i+lt:]).replace('?','a'))
  if len(ret)==0:
    return 'UNRESTORABLE'
  else:
    return min(ret)


if __name__ == "__main__":
  print(main())

Solution (Python):




s = input()
t = input()
aidx = -1


for i in range(len(s)-1, len(t)-2, -1):
    if s[i] == "?" or s[i] == t[len(t)-1]:
        aflg = True
        for j in range(len(t)-2, -1, -1):
            if s[i-(len(t)-j)+1] == "?":
                continue
            elif s[i-(len(t)-j)+1] == t[j]:
                continue
            else:
                aflg = False
                break
        if aflg == True:
            aidx = i
            break

if aidx == -1:
    ans = "UNRESTORABLE"
else:
    
    ans = ""
    i = len(s)-1
    while(i >= 0):
        if i != aidx:
            if s[i] == "?":
                ans = "a" + ans
            else:
                ans = s[i] + ans
            i -= 1
        else:
            ans = t + ans
            i -= len(t)

print(ans)

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

ans = "UNRESTORABLE"
for i in range(len(ss) - len(t), -1, -1):
  flag = True
  for j in range(i, i + len(t)):
    if ss[j] != t[j-i] and ss[j] != "?":
      flag = False
      break
  if flag:
    ss[i:i+len(t)] = t
    ans = "".join(ss).replace("?", "a")
    break
    
print(ans)

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

S_all = []
for i in range(len(S2) - len(T) + 1):
    tmp = S2[i: i+len(T)]

    flag = True
    for j in range(len(tmp)):
        if tmp[j] != '?' and tmp[j] != T[j]:
            flag = False
            break

    if flag:
        S_tmp = S2[:i] + T + S2[i+len(T):]
        S = ''

        for k in range(len(S_tmp)):
            if S_tmp[k] == '?':
                S += 'a'
            else:
                S += S_tmp[k]

        S_all.append(S)

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

Solution (Python):
s=[x for x in input()]
t=[x for x in input()]
ls=len(s)
lt=len(t)
ret=False
for i in range(ls-lt,-1,-1):
  flag=True
  for j in range(lt):
    if s[i+j]!='?' and s[i+j]!=t[j]:
      flag=False
  if flag==True:
    for j in range(lt):
      s[i+j]=t[j]
    ret=True
    break
for i in range(ls):
  if s[i]=='?':
    s[i]='a'
if ret==True:
  print(''.join(map(str,s)))
else:
  print('UNRESTORABLE')

Solution (Python):

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

def solve():
    global S, T
    if len(S) < len(T):
        print("UNRESTORABLE")
        return

    inds = []
    for i in reversed(range(len(S) - len(T) + 1)):
        s = S[i:i+len(T)]


        yes = True
        for j in range(len(s)):

            if s[j] == '?' or s[j] == T[j]:
                continue
            else:
                yes = False
                break
        if yes:
            inds.append(i)

    if len(inds) == 0:
        print("UNRESTORABLE")
        return
    
    ans = []
    for ind in inds:
        ss = S[:]
        for i in range(len(S)):
            if ind<= i < ind+len(T):
                ss[i] = T[i-ind]
            elif  ss[i] == '?':
                ss[i] = 'a'
        ans.append(ss)

    ans = list(map(lambda x: ''.join(x), ans))
    print(min(ans))
        
solve()

Solution (Python):

import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]



def solve(S, T):
    res = []
    for i in range(len(S) - len(T) + 1):
        cc = S[:i] + T + S[i+len(T):]
        q = set([s for s,c in zip(S, cc) if s != c])
        if q == set(['?']) or q == set():
            res.append(cc.replace('?', 'a'))

    res.sort()
    if 0 < len(res):
        return res[0]

    return 'UNRESTORABLE'


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

if __name__ == '__main__':
    main()

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

t_pattern = []

for i in range(len(S)+1 - len(T)):
    tmp = ""
    for j in range(i):
        tmp += " "
    tmp += T
    tmp_len = len(tmp)
    for j in range(len(S) - tmp_len):
        tmp += " "
    t_pattern.append(tmp)

candidate = []

for i in t_pattern:
    count = 0
    for j in range(len(S)):
        if i[j] == " ":
            continue
        elif i[j] == S[j] or S[j] == "?":
            count += 1
            if count == len(T):
                candidate.append(i)
            continue
        else:
            break

if not candidate:
    print("UNRESTORABLE")
    exit()

ans = ""
for i in range(len(S)):
    if S[i] == "?" and candidate[-1][i] == " ":
        ans += "a"
    elif S[i] != "?":
        ans += S[i]
    else:
        ans += candidate[-1][i]


print(ans)

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

S = list(input().strip())
T = list(input().strip())
s = set()

for i in range(len(S) - len(T) + 1):
    p = S[i:i+len(T)]
    f = True
    for j in range(len(T)):
        if p[j] != T[j] and p[j] != "?":
            f = False
        
    if f:
        s.add("".join(S[0:i] + T + S[i+len(T):]))

    if p == ["?"] * len(T):
        s.add("".join(S[0:i] + T + S[i+len(T):]))
        
if len(s) == 0:
    print("UNRESTORABLE")
else:
    l = list(s)
    for i in range(len(s)):
        l[i] = l[i].replace("?", "a")
        
    l.sort()
    print(l[0])

Solution (Python):
S,T=[list(input()) for _ in range(2)]
k = -1
for i in range(len(S)-len(T)+1):
	ok = True
	for j in range(len(T)):
		if S[i+j] != "?" and S[i+j] != T[j]:
			ok = False
			break
	if ok:
		k = i
if k == -1:
	print("UNRESTORABLE")
else:
	for i in range(len(T)):
		S[i+k] = T[i]
	print("".join(S).replace("?", "a"))

Solution (Python):

S = input()
T = input()
Tlen = len(T)
Slen = len(S)




for i in range(Slen-Tlen, -1, -1):
    
    for s, t in zip(S[i:i + Tlen], T):
        flg = True
        if s != t and s != '?':
            flg = False
            break
    if flg:
        insertidx = i
        break
else:
    print('UNRESTORABLE')
    
    exit()

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

Solution (Python):

S = input()
T = input()
Tlen = len(T)
Slen = len(S)




for i in range(Slen-Tlen, -1, -1):
    
    for s, t in zip(S[i:i + Tlen], T):
        flg = True
        if s != t and s != '?':
            flg = False
            break
    if flg:
        insertidx = i
        break
else:
    print('UNRESTORABLE')
    import sys
    sys.exit()

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

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

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

for i in range(len(sr)-len(tr)+1):
    srp = sr[i:i+len(tr)]
    for j in range(len(srp)):
        if srp[j] != '?' and srp[j] != tr[j]:
            break
    else:
        ans = sr.replace('?', 'a')
        ans = ans[0:i] + tr + ans[i+len(tr):]
        print(ans[::-1])
        exit()
else:
    print('UNRESTORABLE')

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

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

for i in range(len(sr)-len(tr)+1):
  srp = sr[i:i+len(tr)]
  for j in range(len(srp)):
    if srp[j] != '?' and srp[j] != tr[j]:
      break
  else:
    ans = sr.replace('?', 'a')
    ans = ans[0:i] + tr + ans[i+len(tr):]
    print(ans[::-1])
    exit()
else:
  print('UNRESTORABLE')

Solution (Python):
s=input()
t=input()
 
if len(s) < len(t):
  print("UNRESTORABLE")
  exit()
 
c=len(s)-len(t)
 
flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
  c-=1

 
 
 
if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")

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

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

c=len(s)-len(t)

flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
  c-=1




if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")

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


s = 0 
for i in range(len(S)-len(T)+1)[::-1]:
    flag = 1
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            flag = 0
            break
    if flag:
        s = i
        break

if len(S) < len(T) or not flag:
    print("UNRESTORABLE")
else: 
    S = S[:s] + T + S[s+len(T):]
    
    S = S.replace("?", "a")
    print(S)

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

ls = len(S)
lt = len(T)
ret = 'UNRESTORABLE'
for i in range(ls-lt+1):
    judge = True
    for t in range(lt):
        if S[i+t] != T[t] and S[i+t] != "?":
            judge = False
            break
    if judge:
        ret = S[:i] + T + S[i+lt:]
ret = ret.replace("?", "a")
print(ret)

Solution (Python):


S = input()
T = input()

s_rev = "".join(reversed(S))
t_rev = "".join(reversed(T))

found = False
for i in range(len(S) - len(T) + 1):
    yn = all(s_rev[i + k] == "?" or s_rev[i + k] == t_rev[k] for k in range(len(T)))
    if yn:
        s_rev = s_rev[:i] + t_rev + s_rev[i + len(T) :]
        found = True
        break

if found:
    s = "".join("a" if c == "?" else c for c in reversed(s_rev))
    print(s)
else:
    print("UNRESTORABLE")

Solution (Python):
Sd = list(input())
A = list(input()) 


def check(Sd, A):
    ans = -1
    for i in range(len(Sd)-1, -1, -1): 
        count = 0

        for j in range(len(A)): 


            if Sd[i - j] == A[len(A)-1 - j] or Sd[i - j] == '?':
                count += 1
                if count == len(A):
                    ans = i-j 
                    return ans
    return ans

a = check(Sd, A)

if a == -1:
    print ('UNRESTORABLE')
else:
    i = a
    while i < a + len(A):
        Sd[i] = A[i-a]
        i += 1
    for j in range(len(Sd)):
        if Sd[j] == '?':
            Sd[j] = 'a'
    print (''.join(Sd))

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

flag = False
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
        if j == len(T) - 1:
            flag = True
            index = i

if flag:
    s = ''
    k = 0
    for i in range(len(S)):
        if index <= i <= index + len(T) - 1:
            s += T[k]
            k += 1
            continue
        if S[i] == '?':
            s += 'a'
        else:
            s += S[i]
else:
    s = 'UNRESTORABLE'

print(s)

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

index = []
ss = []
flag = False

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
        if j == len(T) - 1:
            flag = True
            index.append(i)

if flag:
    for v in index:
        s = ''
        k = 0
        for i in range(len(S)):
            if v <= i <= v + len(T) - 1:
                s += T[k]
                k += 1
                continue
            if S[i] == '?':
                s += 'a'
            else:
                s += S[i]
        ss.append(s)
    ss.sort()
    s = ss[0]
else:
    s = 'UNRESTORABLE'

print(s)

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

s = [x for x in s]
t = [x for x in t]


def check_match(s, t):
    result = ['?' for _ in range(len(s))]
    for i in range(len(s)):
        s_ = s[i]
        t_ = t[i]
        if s_ == '?':
            result[i] = t_
        elif t_ == '?':
            result[i] = s_
        elif s_ == t_:
            result[i] = t_
        else:
            return None

        output = ''
        for x in result:
            output += x if x != '?' else 'a'
    return output
  
diff = len(s) - len(t)
results = []

for i in range(diff+1):
    t_new = ['?'] * i + t + ['?'] * (diff - i) 
    result = check_match(s, t_new)
    
    if result:
        results.append(result)
        
if len(results):
    print(sorted(results)[0])
else:
    print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
ls = len(S)
lt = len(T)
for i in range(ls-lt,-1,-1):
    for j in range(lt):
        if S[i+j] != "?" and S[i+j] != T[j] :
            break
    else:
        
        S = [c if c != "?" else "a" for c in S]
        S[i:i+lt] = list(T)
        S = "".join(S)
        break
else:
    S = "UNRESTORABLE"
print(S)

Solution (Python):
from functools import reduce
import math
import copy
def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    S_dash = list(_ for _ in input())
    T = list(_ for _ in input())
    S_dash = S_dash[::-1]
    T = T[::-1]
    for i in range(len(S_dash)-len(T)+1):
        flag = False
        for j in range(i,i+len(T)):
            if S_dash[j] == T[j-i] or S_dash[j] == '?':
                flag = True
            else:
                flag = False
                break
        if flag:
            for j in range(i,i+len(T)):
                S_dash[j] = T[j-i]
            break

    S = ''.join(S_dash[::-1]).replace('?','a')

    if S.count(''.join(T[::-1])) == 0:
        print('UNRESTORABLE')
        return
    print(S)
    
if __name__ == '__main__':
    main()

Solution (Python):

def read_input():
    s = input()
    t = input()

    return s, t



def make_pattern(n, t):
    m = len(t)

    patterns = []
    for i in range(n - m + 1):
        patterns.append(['?'] * i + t + ['?'] * (n - i - m))

    return patterns



def check_match(a, b):
    def convert(x, y):
        if x == '?' and y == '?':
            return 'a'
        if x == y:
            return x
        if x == '?':
            return y
        if y == '?':
            return x
        return None

    result = []
    for i in range(len(a)):
        result.append(convert(a[i], b[i]))

    return result

def submit():
    s, t = read_input()

    s = [c for c in s]
    t = [c for c in t]

    patterns = make_pattern(len(s), t)

    candidates = [check_match(s, p) for p in patterns]
    candidates = [''.join(c) for c in candidates if None not in c]
    candidates.sort()

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

if __name__ == '__main__':
    submit()

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    t = input()

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

    if t in s:
        for i in range(sl):
            if s[i]=='?':
                print('a', end='')
            else:
                print(s[i], end='')
        print()
        return

    for i in range(sl-1, -1, -1):
        if i+tl-1>=sl:
            continue
        ok = 1
        for j in range(tl):
            if s[i+j] not in ['?', t[j]]:
                ok = 0
                break
        if ok:
            s = s[:i] + t + s[i+tl:]
            for i in range(sl):
                if s[i]=='?':
                    print('a', end='')
                else:
                    print(s[i], end='')
            
            print()
            return

    print('UNRESTORABLE')
            

solve()

Solution (Python):
import re


def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + lt:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)


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

print(solve(s, t))

Solution (Python):
s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(nd+1):
  judge=True
  for j in range(nt):
    ss=s[i+j]
    tt=t[j]
    if ss!="?" and ss!=tt:
      judge=False
  if judge:
    Key=s[:i]+t+s[i+nt:]
    ans=min(ans,Key.replace("?","a"))
    flag=1
print(ans if flag==1 else "UNRESTORABLE")

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

sl = len(S)
tl = len(T)

for i in range(sl-tl,-1,-1):
    flag = True
    for j in range(tl):
        s = S[i+j]
        t = T[j]
        if (s != '?')and(s != t):
            flag = False
            break
    if flag == True:
        for j in range(tl):
            S[i+j] = T[j]
        for k in range(sl):
            if S[k] == '?':
                S[k] = 'a'
        print("".join(S))
        exit()

print("UNRESTORABLE")

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

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

flag = False
pos = 51
ans = ""
for i in range(len(S)-N+1):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

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

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

c=len(s)-len(t)
flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
  c-=1
if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")

Solution (Python):
import copy

S = input()
T = input()
if len(S) < len(T):
  print("UNRESTORABLE")
  exit()
flg = True
Sarray = []
for i in range(len(S)-len(T)+1):
  flg=True
  Stmp = copy.copy(S)
  for idx, c in enumerate(T):
    if Stmp[i+idx]!=c and Stmp[i+idx]!='?':
      flg=False
      break
  if flg:
    Stmp = Stmp[:i] + T + Stmp[len(T)+i:]
    Stmp = Stmp.replace('?', 'a')
    Sarray.append(Stmp)
if len(Sarray)==0:
  print("UNRESTORABLE")
  exit()
else:
  Sarray.sort()
  print(Sarray[0])

Solution (Python):
import sys
S=input()
T=input()
if len(S)<len(T):
    print('UNRESTORABLE')
    sys.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):
S = input()
T = input()

s = len(S)
t = len(T)


for i in range(s-t, -1, -1):
    n = 0
    for j in range(t-1, -1, -1):
        if S[j+i] != '?' and S[j+i] != T[j]:
            break
        n += 1

    if n == t:
        for x in range(s):
            if i <= x < i+t:
                print(T[x-i], end='')
            else:
                if S[x] == '?':
                    print('a', end='')
                else:
                    print(S[x], end='')
        exit()

print('UNRESTORABLE')

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

temp = ""
is_restorable = False
for i in range(len(S) - len(T) + 1):
    cand = S[i:i + len(T)]
    for ci, ti in zip(cand, T):
        if ci not in ["?", ti]:
            break
    else:
        temp = S[:i] + T + S[i + len(T):]
        is_restorable = True

if is_restorable:
    print(temp.replace("?", "a"))
else:
    print("UNRESTORABLE")

Solution (Python):
def is_match(i, Sd, T):
    for j in range(len(T)):
        if Sd[i + j] != T[j] and Sd[i + j] != '?':
            return False
    return True


Sd = input()
T = input()
diff = len(Sd) - len(T)
len_t = len(T)
matches = []
for i in range(diff + 1):
    if Sd[i] == T[0] or Sd[i] == '?':
        
        if is_match(i, Sd, T):
            matches.append(Sd[:i] + T + Sd[i + len_t:])


tmps = []
for m in matches:
    s = []
    for i in range(len(m)):
        if m[i] == '?':
            s.append('a')
        else:
            s.append(m[i])
    tmps.append(''.join(s))
print(min(tmps, default='UNRESTORABLE'))

Solution (Python):
source = input()
target = input()
t_len = len(target)
answer = "z" * 51
for i in range(len(source) - t_len + 1):
    for j in range(i, i + t_len):
        
        if source[j] == target[j - i] or source[j] == "?":
            pass
        else:
            break
    else:
        temp_s = source[:i] + target + source[i + t_len:]
        temp_s = temp_s.replace("?", "a")
        answer = min(answer, temp_s)

if answer == "z" * 51:
    print("UNRESTORABLE")
else:
    print(answer)

Solution (Python):
if __name__ == '__main__':
	S = input()
	T = input()

	T_length = len(T)
	head = -1
	for i in range(len(S)-T_length+1):
		counter = 0
		for j in range(T_length):
			if(S[i+j]==T[j] or S[i+j]=='?'):
				counter += 1
		if(counter == T_length):
			head = i
				
	ans = ''
	i=0
	if(head == -1):
		print("UNRESTORABLE")
	else :
		while i < len(S):
			if(i!=head and S[i]=='?'):
				ans += 'a'
				i += 1
			elif(i==head):
				ans += T
				i += T_length
			else :
				ans += S[i]
				i+=1

		print(ans)

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

Solution (Python):
S = [i for i in input()]
T = input()
tmp = S.copy()

key = len(T)

SS = []
for i in range(len(S)-key+1):
    idx, flg = 0, 0
    for j in range(i, i+key):
        if S[j] != T[idx] and S[j] != '?':
            flg = 1
            break
        idx += 1
    if flg == 0:
        idx = 0
        for j in range(i, i+key):
            S[j] = T[idx]
            idx += 1
        SS.append(S)
        S = tmp.copy()

if SS:
    idx = 0
    for i in SS:
        idx_2 = 0
        for j in i:
            if j == '?':
                SS[idx][idx_2] = 'a'
            idx_2 += 1
        idx += 1
    print(''.join(min(SS)))
else:
    print('UNRESTORABLE')

Solution (Python):
s = input()
t = input()
ns = len(s)
nt = len(t)

ans = "UNRESTORABLE"
for i in range(ns - nt + 1):
    if all([s[i + j] == "?" or s[i + j] == t[j] for j in range(nt)]):
        ans = s[:i] + t + s[i + nt:]
        ans = ans.replace("?", "a")
print(ans)

Solution (Python):
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)

s = "UNRESTORABLE"
cnt = 0
for i in range(n - m + 1):
    cnt = 0
    for j in range(m):
      if s_dash[i+j] == t[j] or s_dash[i+j] == "?":
        cnt += 1
      else:
        break
    if cnt == m:
      s = s_dash[:i] + t + s_dash[i+m:]
      s = s.replace("?", "a")

      
print(s)

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

Solution (Python):

import sys


def parse(file):
    s = file.readline().strip()
    t = file.readline().strip()
    return s, t


def main(s, t):
    end = len(s) - len(t)
    for start in reversed(range(end + 1)):
        found = True
        for i in range(len(t)):
            if s[start + i] == t[i] or s[start + i] == '?':
                continue
            else:
                found = False
                break
        if not found:
            continue

        if found:
            ans = s[:start] + t + s[start+len(t):]
            return ans.replace('?', 'a')

    return 'UNRESTORABLE'


if __name__ == '__main__':
    print(main(*parse(sys.stdin)))

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







S_.reverse(),T.reverse()
key_index = -1 
judge = 0 
for i in range(n):
  if((S_[i] == '?')or(S_[i] == T[0])):
    if(i+m-1 <= n-1): 
     tmp = S_[i:i+m]
     judge = 1
     for j in range(m):
        if((tmp[j] == T[j])or(tmp[j] == '?')):
          continue
        else:
          judge = 0
          break
  if(judge == 1):
    key_index = i
    break
 
if(judge == 0):
  print('UNRESTORABLE')
else:
  j = 0
  for i in range(n):
    if(key_index <= i <= key_index+m-1):
      S_[i] = T[j]
      j += 1
    elif(S_[i] == '?'):
      S_[i] = 'a'
  S_.reverse()
  ans = ''.join(S_)
  print(ans)

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


ss = []

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j]== '?':
            if j == len(t)-1:
                sss = s[:i]+t+s[i+j+1:]
                sss = sss.replace('?', 'a')
                ss.append(sss)
        else:
            break

ss.sort()

print('UNRESTORABLE' if ss==[] else ss[0])

Solution (Python):
S = raw_input()
T = raw_input()
ans = 'UNRESTORABLE'
n = len(S)-len(T)+1
if n > 0:
	for i in range(0, n):
		flag = False
		for j in range(0, len(T)):
			if S[-1-i-j] != '?' and S[-1-i-j] != T[-1-j]: break
			if j == len(T)-1: flag = True
		if flag:
			ans = ''
			for j in range(0, len(S)-i-len(T)):
				if S[j] == '?': ans = ans + 'a'
				else: ans = ans + S[j]
			ans = ans + T
			for j in range(len(S)-i, len(S)):
				if S[j] == '?': ans = ans + 'a'
				else: ans = ans + S[j]
			break
print ans

Solution (Python):
def solve():
    S=input()
    S_len=len(S)
    T=input()
    T_len=len(T)
    if S_len<T_len:
        return 'UNRESTORABLE'
    for i in range(S_len-T_len,-1,-1):
        for j in range(T_len):
            if S[i+j]!=T[j] and S[i+j]!='?':
                break
        else:
            S = S[0:i] + T + S[i+T_len:]
            break
    else:
        return 'UNRESTORABLE'
    return S.replace('?','a')

print(solve())