Problem:
 Score : 300 points    Problem Statement E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S' , which turns out to be the string S with some of its letters (possibly all or none) replaced with ? .  One more thing he found is a sheet of paper with the following facts written on it:   Condition 1: The string S contains a string T as a contiguous substring.  Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.   Print the string S . If such a string does not exist, print UNRESTORABLE .      Constraints  1 \leq |S'|, |T| \leq 50  S' consists of lowercase English letters and ? .  T consists of lowercase English letters.         Input Input is given from Standard Input in the following format:  S  T'       Output Print the string S . If such a string does not exist, print UNRESTORABLE instead.        Sample Input 1 ?tc????
coder      Sample Output 1 atcoder  There are 26 strings that satisfy Condition 1: atcoder , btcoder , ctcoder ,..., ztcoder .
Among them, the lexicographically smallest is atcoder , so we can say S = atcoder .       Sample Input 2 ??p??d??
abc      Sample Output 2 UNRESTORABLE  There is no string that satisfies Condition 1, so the string S does not exist.

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

cand = []
for i in range(len(S) - len(T) + 1):
    f = True
    for s, t in zip(S[i:i+len(T)], T):
        if s == '?':
            continue
        if s != t:
            f = False
            break
    if f:
        cand.append(S[:i] + T + S[i+len(T):])
if cand == []:
    print('UNRESTORABLE')
    exit()
print(cand[-1].replace('?', 'a'))

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

ans = []
for i in range(len(S)-len(T)+1):
    ss = list(S)
    for j in range(len(T)):
        if S[i+j]=="?":
            ss[i+j] = T[j]
            continue
        elif S[i+j]!=T[j]:
            break
    else:
        ans.append("".join(ss))


if ans:
    for i in range(len(ans)):
        ans[i] = ans[i].replace("?", "a")
    print(min(ans))
else:
    print("UNRESTORABLE")

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

i = 0
check = False
start = 0
while i+m <= n:
    temp = True
    k = 0
    while k < m and temp:
        if s[i+k] == t[k] or s[i+k] == "?":
            k += 1
        else:
            temp = False
    if temp:
        check = True
        start = i
        i += 1
    else:
        i += 1
if check:
    for k in range(start,start+m):
        s[k] = t[k-start]

if check:
    for i in range(n):
        if s[i] == "?":
            s[i] = "a"
    for i in range(n):
        if i != n-1:
            print(s[i],end = "")
        else:
            print(s[i])
else:
    print("UNRESTORABLE")

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

ls=len(s)
lt=len(t)

def f(a,b):
    r=""
    for i in range(lt):
        if a[i]==b[i] or a[i]=="?":
            r+=b[i]
        else:
            return False
    return True
        
ans=[]

for i in range(ls-lt+1):
    c=""
    if f(s[i:i+lt],t):
        c+=s[0:i]
        c+=t
        c+=s[i+lt:ls]
        c=c.replace("?","a")
        ans.append(c)

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

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


for i in range(len(S)-len(T)+1):
    cnt=0
    for j in range(len(T)):
        if S[len(S)-len(T)-i+j]=="?":
            cnt+=1
        else:
            if S[len(S)-len(T)-i+j]==T[j]:
                cnt+=1
    if len(T)==cnt:
        ANS=S[:len(S)-len(T)-i]+T+S[len(S)-i:]
        ANS=ANS.replace("?","a")
        print(ANS)
        exit()
    
print("UNRESTORABLE")

Solution (Python):
S1=input()
T1=input()
S=""
T=""
A=""
for i in range(1,len(S1)+1):
    S+=S1[-i]
for i in range(1,len(T1)+1):
    T+=T1[-i]
j=0
i=0
flag = False
while i<=len(S)+1-len(T):
    while j<=len(T)+1:
        if i==len(S)-len(T)+1:
            A="UNRESTORABLE"
            flag=True
            break
        elif j==len(T):
            P=S.replace(S[i:i+len(T)],T,1)
            Q=P.replace("?","a")
            for i in range(1,len(Q)+1):
                A+=Q[-i]
            flag=True
            break
        elif S[i+j]==T[j] or S[i+j]=="?":
            j+=1
        else:
            j=0
            i+=1
    if flag:
        break
print(A)

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

p = ""
for i in range(len(t)):
    p += "[" + t[i] + "?]"

ans = []
for i in range(len(s)-len(t)+1):
    a = re.match(p, s[i:])
    if a is None:
        continue
    tmp = s[:i] + t + s[i+len(t):]
    ans.append(tmp.replace("?", "a"))

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

Solution (Python):
s=list(input())
t=list(input())
f=0
for i in range(len(s)-len(t),-1,-1):
  l=[]
  for j in range(len(t)):
    if s[i+j]=='?':l.append(t[j])
    else:l.append(s[i+j])
  if ''.join(t)==''.join(l):
    if f==0:
      for m in range(len(t)):
        s[i+m]=t[m]
    f=1
if f==0:print('UNRESTORABLE')
else:
  for k in range(len(s)):
    if s[k]=='?':s[k]='a'
  print(''.join(s))

Solution (Python):
def find_match(S, T):
    for i in range(len(S) - len(T) + 1):
        match = True
        for j in range(len(T)):
            if S[i+j] != "?" and S[i+j] != T[j]:
                match = False
                break
        if match:
            return i
    return -1


def main():
    S = input()[::-1]
    T = input()[::-1]
    idx = find_match(S, T)
    if idx != -1:
        S = S[:idx] + T + S[idx+len(T):]
        S = S[::-1].replace("?", "a")
    else:
        S = "UNRESTORABLE"
    print(S)


if __name__ == "__main__":
    main()

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

Solution (Python):
import math
import sys
import bisect

S1 = input()
T = input()

candidates = []


def check(sStart):
    for i in range(len(T)):
        sIdx = sStart + i
        if sIdx < len(S1) and (S1[sIdx] == T[i] or S1[sIdx] == "?"):
            pass
        else:
            return False
    return True


for i in range(len(S1)):
    s = ""
    if check(i):
        c = S1[0:i] + T +S1[i+len(T):]
        
        candidates.append(c)

clist = list(set(candidates))
clist = sorted(clist)


if len(clist) == 0:
    print("UNRESTORABLE")
else:
    ret = clist[0]
    ret = ret.replace("?","a")
    print(ret)

Solution (Python):

s = input()
t = input()
n = len(s)

def check(idx):
    for i in range(len(t)):
        ii = idx+i
        if ii>=n:
            return False
        if s[ii]!="?" and s[ii]!=t[i]:
            return False
    return True

def restore(idx):
    res = list(s)
    for i in range(len(t)):
        ii = idx+i
        res[ii] = t[i]
    for i in range(n):
        if res[i]=="?":
            res[i] = "a"
    return "".join(res)

res = []
for i in range(n):
    if check(i):
        res.append(restore(i))

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

Solution (Python):
from re import match

s = input().replace('?','.')
t = input()
s_len = len(s)
t_len = len(t)

for i in range(s_len-t_len,-1,-1):
    if match(s[i:i+t_len],t):
        s = s.replace('.','a')
        print(s[:i]+t+s[i+t_len:])
        exit()
print('UNRESTORABLE')

Solution (Python):
import sys

sd = input()
t = input()
NG = 'UNRESTORABLE'


def valid(os: int):
    if len(sd) <= os or len(sd) - os < len(t):
        return False
    for sc, tc in zip(sd[os:os+len(t)], t):
        if sc != tc and sc != '?':
            return False
    ans = ''
    for i, sc in enumerate(sd):
        if i < os:
            c = sc
        elif i < os + len(t):
            c = t[i - os]
        else:
            c = sc
        if c == '?':
            c = 'a'
        ans += c
    return ans


if len(t) > len(sd):
    print(NG)
    sys.exit()

for i in range(len(sd) - len(t) + 1):
    ans = valid(len(sd) - len(t) - i)
    if ans:
        print(ans)
        sys.exit()

print(NG)

Solution (Python):
import re
S = input().replace('?', '.')
T = input()
n = len(T)
for i in range(len(S) - n, -1, -1):
    if re.match(S[i:i+n], T):
        S = S.replace('.', 'a')
        print(S[:i] + T + S[i+n:])
        exit()
print('UNRESTORABLE')

Solution (Python):
s, t = [input() for _ in range(2)]

n, m = map(len, [s, t])
for i in range(n-m, -1, -1):
	if not all(s_j in ["?", t_j] for s_j, t_j in zip(s[i:i+m], t)):
		continue
	print((s[:i] + t + s[i+m:]).replace("?", "a"))
	exit()
print("UNRESTORABLE")

Solution (Python):
def listToString(_list, split=""):
    maped_list = map(str, _list)  
    mojiretu = split.join(maped_list)
    return mojiretu


def stringToList(_string, split=" "):
    str_list = []
    temp = ''
    for x in _string:
        if x == split:  
            str_list.append(temp)
            temp = ''
        else:
            temp += x
    if temp != '':  
        str_list.append(temp)
    return str_list


s = input()
t = input()
firstMatch = False
out = listToString(["z" for i in range(len(s))])

for i in range(len(s) - len(t) + 1):
    localStr = []
    match = True
    for j in range(i):  
        if s[j] == "?":
            localStr.append("a")
        else:
            localStr.append(s[j])
    for j in range(i, i+len(t)):
        
        
        if s[j] != t[j - i]:
            if s[j] == "?":
                localStr.append(t[j - i])
            else:
                match = False
                break
        else:
            localStr.append(s[j])
    for j in range(i+len(t), len(s)):
        if s[j] == "?":
            localStr.append("a")
        else:
            localStr.append(s[j])
    
    if match:
        firstMatch = True
        if listToString(localStr) < out:
            
            out = listToString(localStr)
if firstMatch:
    print(out)
else:
    print("UNRESTORABLE")

Solution (Python):
S = list(input())
T = list(input())
ans = []
for i in range(len(S) - len(T) + 1):
    SS = S[i:i+len(T)]
    for j in range(len(T)):
        if SS[j] != T[j] and SS[j] != '?':
            break
    else:
        sfir = ''.join(S[:i])
        saft = ''.join(S[i+len(T):])
        sfir = sfir.replace('?', 'a')
        saft = saft.replace('?', 'a')
        ans.append(sfir+''.join(T)+saft)
    
if ans:
    print(sorted(ans)[0])
else:
    print('UNRESTORABLE')

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

flag = False
for i in range(len(ss)):
    if ss[i] == '?' or ss[i] == t[0]:
        for j in range(len(t)):
            if i+j >= len(ss):                
                break
            elif ss[i+j] == t[j] or ss[i+j] == '?':
                if j == len(t)-1:
                    flag = True
                    start_t = i
                continue
            else:
                break
        
ans = 'UNRESTORABLE'
if flag:
    ss[start_t:start_t+len(t)] = t
    ans = ''.join(ss).replace('?','a')

print(ans)

Solution (Python):
a = list(input())
b = list(input())
count = 0
m = 0
ar = []
c = ""
for i in range(len(a)-len(b)+1):
    for j in range(len(b)):
        if b[j] == a[i+j] or a[i+j] == "?":
            count += 1
    if count == len(b):
        for k in range(len(a)):
            if k >= i and k <= i + len(b) - 1:
                c += b[m]
                m += 1
            else:
                if a[k] == "?":
                    c += "a"
                else:
                    c += a[k]
        ar.append("".join(c))
        c = ""
    count = 0
    m = 0
if len(ar) == 0:
    print("UNRESTORABLE")
else:
    print(sorted(ar)[0])

Solution (Python):
import copy as cp
s = input()
t = input()
u = list(s)
v = list(t)
w = cp.deepcopy(u)
p = 0
q = 0
for h in range(len(u) - 1, -1, -1):
    if q == 1:
        break
    if v[-1] == u[h]:
        
        for j in range(len(v)):
            if (v[-1 - j] == u[h - j]) and h - j >= 0:
                pass
                if j == len(v) - 1:
                    
                        
                    q = 1
                    p = 1
            else:
                break
if q == 0:
    for i in range(len(u) - 1, -1, -1):
        if p == 1:
            break
        if v[-1] == u[i] or "?" == u[i]:
            
            for j in range(len(v)):
                if (v[-1 - j] == u[i - j] or "?" == u[i - j]) and i - j >= 0:
                    pass
                    if j == len(v) - 1:
                        for k in range(len(v)):
                            w[i - k] = v[-1 - k]
                        p = 1
                else:
                    break

if p == 1:
    for m in range(len(u)):
        if w[m] == "?":
            w[m] = "a"
    print("".join(w))
if p == 0:
    print("UNRESTORABLE")

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

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

    if flag:
        Sd_List = list(Sd)
        for j, k in zip(range(i, i+len(T)), T):
            Sd_List[j] = k
        Sd = "".join(Sd_List)
        result = Sd.replace('?', 'a')
        break

print(result if result else 'UNRESTORABLE')

Solution (Python):
s, t = [input() for _ in range(2)]
t_len = len(t)

def is_fit(a, b):
	for i in range(t_len):
		if a[i] not in [b[i], "?"]:
			return False
	return True

for i in range(len(s)-t_len, -1, -1):
	if not is_fit(s[i:i+t_len], t):
		continue
	s = list(s)
	s[i:i+t_len] = list(t)
	s = "".join(s).replace("?", "a")
	print(s)
	exit()
print("UNRESTORABLE")

Solution (Python):
S_hint=input()
T=input()
List_S_hint=list(S_hint)
S_candidates=[]
Out=0
for i in range(len(S_hint)-len(T)+1):
  Out=0
  Word=""
  Candidate=list(List_S_hint)
  for j in range(len(T)):
    if Candidate[i+j] is "?":
      Candidate[i+j]=T[j]
    elif Candidate[i+j]==T[j]:
      pass
    else:
      Out=1
      break
  if Out==1:
    pass
  else:
    for n in Candidate:
      if n=="?":
        Word+="a"
      else:
        Word+=n
    S_candidates.append(Word)  
if len(S_candidates)==0:
  print("UNRESTORABLE")
else:  
  print(min(S_candidates))

Solution (Python):

Sd = input()
T = input()

LSd = len(Sd)
LT = len(T)

ans = "UNRESTORABLE"
for i in range(LSd - LT + 1):
    for si, ti in zip(Sd[LSd - LT - i: LSd - i], T):
        if si != ti and si != "?": break
    else:
        ans = Sd[:LSd - LT - i].replace("?", "a") + T + Sd[LSd - i:].replace("?", "a")
        break

print(ans)

Solution (Python):
sp = list(input())
t = list(input())
n = len(sp)
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s = ''
        sp[n - i:n - i + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')

Solution (Python):
sp = list(input())
t = list(input())
n = len(sp)
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s = ''
        sp[n - i:n - i + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')

Solution (Python):
sp = list(input())
t = list(input())
n = len(sp)
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s = ''
        sp[n - i:n - i + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')

Solution (Python):
sp = list(input())
t = list(input())
n = len(sp)
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s = ''
        sp[n - i:n - i + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')

Solution (Python):
sp = list(input())
t = list(input())
n = len(sp)
s = []
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s.append('')
        ss = sp
        ss[n - i:n - i + len(t)] = t
        for j in range(n):
            if ss[j] == '?':
                s[-1] += 'a'
            else:
                s[-1] += ss[j]
if s == []:
    print('UNRESTORABLE')
else:
    s.sort()
    print(s[0])

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

if len(sd)<len(T):
    fl=False
else:
    for i in range(len(sd)-len(T),-1,-1):
    
        st=sd[i:len(T)+i]
    
        fl=True
        for j in range(len(T)):
            if st[j]!='?':
                if st[j]!=T[j]:
                    fl=False
        if fl:
            s=sd[:i]+T+sd[len(T)+i:]
            for k in range(len(s)):
                if s[k]=='?':
                    s=s[:k]+'a'+s[k+1:]
            break
if fl:
    print(s)
else:
    print('UNRESTORABLE')

Solution (Python):
def solve(S, T):
    for i in reversed(range(0, len(S) - len(T) + 1)):
        if all(S[j] == "?" or S[j] == T[j - i] for j in range(i, i + len(T))):
            return (S[0:i] + T + S[i + len(T):]).replace("?", "a")
    return "UNRESTORABLE"


if __name__ == "__main__":
    S = input()
    T = input()
    print(solve(S, T))

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

s_len = len(s)
t_len = len(t)
ans = s[:]
question_num = 0
unrestorable = True
for i in range(s_len):
    si = (s_len-1) - i
    restorable = True
    if s_len - si >= t_len:
        for ti in range(t_len):
            w = s[si+ti]
            if w == "?" or w == t[ti]:
                continue
            restorable = False
    else:
        restorable = False
    if restorable:
        unrestorable = False
        for ti in range(t_len):
            ans[si+ti] = t[ti]
        break

for i in range(s_len):
    if ans[i] == "?":
        ans[i] = "a"

if unrestorable:
    print("UNRESTORABLE")
else:
    print(''.join(ans))

Solution (Python):
def 解():
    sS = input().rstrip()
    sT = input().rstrip()
    impo = "UNRESTORABLE"
    iS = len(sS)
    iT = len(sT)
    for i in range(iS-iT,-1,-1):
        bF = 1
        for j in range(iT):
            if sS[i+j] != "?" and sS[i+j] != sT[j]:
                bF = 0
                break
        if bF:
            sAns = (sS[0:i]+sT+sS[i+iT:]).replace("?","a")
            print(sAns)
            exit()
    print(impo)
解()

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

for i in range(len(s) - 1, len(t) - 2, -1):
    j = 0
    tmps = s.copy()
    while s[i - j] == '?' or s[i - j] == t[len(t) - 1 - j]:
        tmps[i - j] = t[len(t) - 1 - j]
        j += 1
        if len(t) - 1 - j < 0:
            for k in range(len(tmps)):
                if tmps[k] == '?':
                    tmps[k] = 'a'
            print(''.join(tmps))
            sys.exit(0)

print('UNRESTORABLE')

Solution (Python):
import sys

def is_match(x, t, n):
    for i in range(n):
        if x[i] != '?' and x[i] != t[i]:
            return False
    return True


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

if len_s < len_t:
    print('UNRESTORABLE')
    sys.exit(0)

segs = [s[i:i+len_t] for i in range(len_s - len_t + 1)]
ans = 'z' * 51

for i, seg in enumerate(segs):
    if is_match(seg, t, len_t):
        tmp = s[0:i] + t + s[i+len_t:]
        tmp = tmp.replace('?', 'a')
        ans = min(ans, tmp)

if len(ans) > 50:
    print('UNRESTORABLE')
else:
    print(ans)

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

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

if len(T) > len(Sprime):
    print('UNRESTORABLE')
else:
    ans = -1
    for i in range(len(Sprime)-len(T)+1):
        for j in range(len(T)):
            if Sprime[i:i+len(T)][j] != '?' and\
            Sprime[i:i+len(T)][j] != T[j]:
                break
        else:
            ans = max(i,ans)
    if ans == -1:
        print('UNRESTORABLE')
    else:
        Sprime = list(Sprime)
        Sprime[ans:ans+len(T)] = T
        Sprime = ''.join(Sprime)
        print(Sprime.replace('?','a'))

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

get = []
for i in range(len(S)-len(T)+1):
    for s, t in zip(S[i:], T):
        if s != '?' and s != t:
            break
    else:
        get.append(i)
if not get:
    print('UNRESTORABLE')
    exit()

result = 'z' * 51
for i in get:
    x = S[:i] + T + S[i+len(T):]
    result = min(result, x.replace('?', 'a'))
print(result)

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

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

Ans = []
for i in range(len(S)-len(T)+1):
    same = True
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j]!="?":
            same = False
    if same:
        out = ""
        for k in range(i):
            out += ("a" if S[k] == "?" else S[k])
        out += T
        for k in range(i+len(T), len(S)):
            out += ("a" if S[k] == "?" else S[k])
        Ans.append(out)
        
Ans.sort()
print(Ans[0] if Ans else "UNRESTORABLE")

Solution (Python):
a = list(input())
b = list(input())

n = len(a)
m = len(b)
s = n - m
check = 0
while s >= 0:
    count = 0
    for i in range(m):
        if a[s + i] == '?' or a[s + i] == b[i]:
            count += 1
        else:
            s -= 1
            break
    
    if count == m:
        for i in range(m):
            a[s + i] = b[i]
        print(''.join(a).replace('?', 'a'))
        exit()

print('UNRESTORABLE')

Solution (Python):

S = input()
T = input()

match_idx = 999
for i in range(len(S)-len(T)+1):
    unmatch = 0
    for s,t in zip(S[i:i+len(T)],T):
        if s != t and s != '?':
            unmatch = 1
    if unmatch == 0:
        match_idx = i


if match_idx > len(S)-len(T):
    print('UNRESTORABLE')
    exit()

xT = '?'*(match_idx) + T + '?'*(len(S)-len(T)-match_idx)

ans_list = []
for s,t in zip(S,xT):
    if s == '?' and t == '?':
        ans_list.append('a')
    elif s == '?':
        ans_list.append(t)
    else:
    
        ans_list.append(s)

print(''.join(ans_list))

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

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

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.append((s[:i]+t+s[i+len(t):]).replace('?','a'))

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

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

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

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.append((s[:i]+t+s[i+len(t):]).replace('?','a'))

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

Solution (Python):

"""
Created on Sun Oct 14 17:08:52 2018
ABC076C
@author: maezawa
"""

sp = list(input())
t = list(input())

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

lt = len(t)
i = len(sp)-lt
ok = False
while i >=0:
    spc = sp[i:i+lt]
    if can_replace(spc,t):
        sp[i:i+lt] = t
        ok = True
        break
    i -= 1
if ok:
    for i in range(len(sp)):
        if sp[i] == '?':
            sp[i] = 'a'

    s = ''.join(sp)
    print(s)
else:
    print('UNRESTORABLE')

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

if len(T) > len(S):
    print("UNRESTORABLE")
    exit()

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.append((S[:i] + T + S[i+len(T):]).replace('?', 'a'))

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

Solution (Python):
a = input()
t = input()
n = len(a)
m = len(t)
if n<m:
  print("UNRESTORABLE")
  exit()
for i in range(n-m+1)[::-1]:
  flag = True
  for j in range(m):
    if a[i+j] != t[j] and a[i+j] != "?":
      flag = False
  if flag:
    b = a.replace("?","a")
    print(b[:i] + t + b[i+m:])
    exit()
        
print("UNRESTORABLE")

Solution (Python):
S = input()
ns = len(S)
T = input()
nt = len(T)
if T in S:
    print(S.replace('?', 'a'))
    exit()

for i in reversed(range(ns - nt + 1)):
    for x, y in zip(S[i:], T):
        if not (x == '?' or x == y):
            break
    else:
        r = S.replace('?', 'a')
        print(r[:i] + T + r[i + nt:])
        break
else:
    print('UNRESTORABLE')

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

found = []
for i in range(len(S) - len(T) + 1):
    for cs,ct in zip(S[i:],T):
        if cs != '?' and cs != ct:
            break
    else:
        found.append(i)

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

ans = 'z' * 51
for i in found:
    tmp = S[:i] + T + S[i+len(T):]
    ans = min(ans, tmp.replace('?', 'a'))
print(ans)

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

ans = -1
for i in range(len(s)-len(t)+1):
    u = s[i:i+len(t)]
    flag = 0
    k = i
    for index, iu in enumerate(u):
        if not (iu == "?" or iu == t[index]):
            k = index
            flag = 1
    if flag == 0:
        ans = k

if ans == -1:
    print("UNRESTORABLE")
else:
    i = 0
    word = ""
    while i < len(s):
        if i == ans:
            word += t
            i += len(t)
        elif s[i] == "?":
            word += "a"
            i += 1
        else:
            word += s[i]
            i += 1
    print(word)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()
t = lc()

ans = "z"*50

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

            if sij != '?' and sij != t[j]:
                break

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

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

found = []
for i in range(len(S) - len(T) + 1):
    for cs,ct in zip(S[i:],T):
        if cs != '?' and cs != ct:
            break
    else:
        found.append(i)

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

ans = 'z' * 51
for i in found:
    tmp = S[:i] + T + S[i+len(T):]
    ans = min(ans, tmp.replace('?', 'a'))
print(ans)

Solution (Python):
from itertools import zip_longest
S = input()
T = input()
NT = len(T)

candidate = []
for i in range(len(S)):
    for target, t in zip_longest(S[i:i+NT], T):
        if target != "?" and target != t:
            break
    else:
        candidate.append(S[:i] + T + S[i+NT:])

ans_candidate = []
for c in candidate:
    c = c.replace("?", "a")
    ans_candidate.append(c)

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

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

ans = -1
ansS = []
if len(S) < len(T):
    ans = -1
else:
    for i in range(len(S) - len(T) + 1):
        ans = 1
        for j in range(len(T)):
            
            if S[i + j] != T[j] and S[i + j] != "?":
                ans = -1
                break
        if ans == 1:
            thisS = S[:i] + T + S[i + len(T):]
            for j in range(len(S)):
                if thisS[j] == "?":
                    thisS[j] = "a"
            ansS.append(thisS)

if len(ansS) == 0:
    print("UNRESTORABLE")
else:
    ansS.sort()
    for i in ansS[0]:
        print(i, end = "")
    print()

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

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