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):
try:
    S = list(input())
    T = list(input())
    t = len(T)
    candidate = []
    for i in range(len(S)):
        tmp = S[i:i+t]
        for j in range(len(tmp)):
            if tmp[j] == T[j] or '?' == tmp[j]:
                pass
            else:
                break
        else:
            candidate.append(S[0:i]+T+S[i+t:len(S)])
    for i in range(len(candidate)):
        l = list(candidate[i])
        for j in range(len(l)):
            if l[j] == '?':
                l[j] = 'a'
        candidate[i]=l
    candidate = list(filter(lambda x:len(x)==len(S),candidate))
    candidate.sort()
    for x in candidate[0]:
        print(x,end='')
    print()
except:
    print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
s = len(S)
t = len(T)
ans = "UNRESTORABLE"
for i in range(s-t+1):
  for j in range(t):
    T[j],S[i+j]
    if(T[j] == S[i+j] or S[i+j] == '?'):
      continue
    else:
      break
  else:
    ans = S[:i] + T + S[i+t:]
    ans = ans.replace('?', 'a')
print(ans)

Solution (Python):
def same(s,t):
    for a,b in zip(s,t):
        if not (a==b or a=='?'):
            return False
    return True

s=input()
t=input()
if len(s)<len(t):
    print('UNRESTORABLE')
    exit()
elif len(s)==len(t):
    if same(s,t):
        print(t)
        exit()
for i in range(len(t),len(s)):
    i=len(s)-i
    if same(s[i:i+len(t)],t):
        s=s[:i]+t+s[i+len(t):]
        break
else:
    print('UNRESTORABLE')
    exit()
for c in s:
    print(c if c!='?'else 'a',end='')
print()

Solution (Python):
S = input()
T = input()
n = len(S)
m = len(T)

ans = 'UNRESTORABLE'
for i in range(n - m + 1):
    for j in range(m):
        if S[i + j] == T[j] or S[i + j] == '?':
            continue
        else:
            break
    else:
        x = S[: i] + T + S[i + m:]
        ans = x.replace('?', 'a')
        
print(ans)

Solution (Python):
from copy import deepcopy

s = list(input())
t = list(input())
st=[]

for i in range(len(s)-len(t)+1):
    l=deepcopy(s[len(s)-len(t)-i:len(s)-i])
    for j in range(len(t)):
        if l[j] ==  '?':
            l[j]=t[j]
    if l==t:
        u=deepcopy(s)
        u[len(u)-len(t)-i:len(u)-i]=t
        st.append(''.join(u).replace('?','a'))

if len(st) == 1:
    print(st[0])
elif len(st)>1:
    ans = st[0]
    for i in range(1,len(st)):
        if ans > st[i]:
            ans = st[i]
    print(ans)
else:
    print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
n = len(S)
m = len(T)

ans = 'UNRESTORABLE'
for i in range(n - m + 1):
    for j in range(m):
        if T[j] == S[i + j] or S[i + j] == '?':
            continue
        else:
            break
    else:
        ans = S[0 : i] + T + S[i + m :]
        ans = ans.replace('?', 'a')

print(ans)

Solution (Python):
S = input()
T = input()
n = len(S)
m = len(T)

ans = 'UNRESTORABLE'
for i in range(n - m + 1):
    flag = 1
    for j in range(m):
        if T[j] == S[i + j] or S[i + j] == '?':
            continue
        else:
            flag = 0
    if flag:
        ans = S[0 : i] + T + S[i + m :]
        ans = ans.replace('?', 'a')

print(ans)

Solution (Python):
s = list(str(input()))
t = list(str(input()))
ans = []
an = 0
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s)-len(t)+1):
    cou = s[i:i+len(t)]
    for k in range(len(t)):
        if s[i+k] != t[k] and s[i+k] != "?" and t[k] != "?":
            break
        if k == len(t)-1:
            ans.append(s[:i]+t+s[i+len(t):])
for h in range(len(ans)):
    for f in range(len(s)):
        if ans[h][f] == "?":ans[h][f] = "a"
    ans[h] = "".join(ans[h])
if ans == []:
    print("UNRESTORABLE")
    exit()
ans.sort()
print(ans[0])

Solution (Python):
s = list(str(input()))
t = list(str(input()))
ans = []
an = 0
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s)-len(t)+1):
    cou = s[i:i+len(t)]
    for k in range(len(t)):
        if s[i+k] != t[k] and s[i+k] != "?" and t[k] != "?":
            break
        if k == len(t)-1:
            ans.append(s[:i]+t+s[i+len(t):])
for h in range(len(ans)):
    for f in range(len(s)):
        if ans[h][f] == "?":ans[h][f] = "a"
    ans[h] = "".join(ans[h])
if ans == []:
    print("UNRESTORABLE")
    exit()
ans.sort()
print(ans[0])

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

len_S = len(S)
len_T = len(T)
for i in range(len_S-len_T, -1, -1):
  if not all(s in ['?', t] for s, t in zip(S[i:i+len_T], T)):
    continue
  print((S[:i] + T + S[i+len_T:]).replace('?','a'))
  exit()
print("UNRESTORABLE")

Solution (Python):


Sd = input()
T = input()

is_replaced = False
for i in range(len(Sd) - len(T), -1, -1):
    can_replace = True
    k = i
    j = 0
    while can_replace and j < len(T):
        if Sd[k] == T[j] or Sd[k] == "?":
            k += 1
            j += 1
        else:
            can_replace = False
            break

    if can_replace:
        
        Sd_l = list(Sd)
        for ti in range(len(T)):
            Sd_l[i + ti] = T[ti]
        Sd = "".join(Sd_l)
        is_replaced = True
        break

if is_replaced:
    print(Sd.replace('?', 'a'))
else:
    print("UNRESTORABLE")

Solution (Python):
s=input()
p=input()
c=0
if len(s)<len(p):
    print("UNRESTORABLE")
else:
    for i in range(len(s)-len(p),-1,-1):
        if c!=0:
            break
        d=s[i:i+len(p)]
        for j in range(len(p)):
            if d[j]!="?":
                if d[j]!=p[j]:
                    break
        else:
            s=s[:i]+p+s[i+len(p):]
            c=1
    if c!=1:
        print("UNRESTORABLE")
    else:
        for i in range(len(s)):
            if s[i]=="?":
                s=s[:i]+"a"+s[i+1:]
        print(s)

Solution (Python):


Sd = input()
T = input()
lSd, lT = len(Sd), len(T)

found = []
for i in range(lSd - lT + 1):
    subFound = True
    for j in range(lT):
        if not (Sd[i + j] == T[j] or Sd[i + j] == '?'):
            subFound = False
    if subFound:
        found.append((Sd[0:i] + T + Sd[i + lT:]).replace('?', 'a'))

found.sort()
if len(found) == 0:
    S = "UNRESTORABLE"
else:
    S = found[0]

print(S)

Solution (Python):
S = input()
T = input()
lenS = len(S)
lenT = len(T)
res = []
for i in range(lenS - lenT + 1):
    tgt = S[i:i + lenT]
    for a, b in zip(tgt, T):
        if not (a == b or a == '?'):
            break
    else:
        tmp = S[:i] + T + S[i + lenT:]
        res.append(tmp.replace('?', 'a'))
if res:
    print(min(res))
else:
    print('UNRESTORABLE')

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

ans = []
flag = False
for i in range(len(S)-len(T)+1)[::-1]:
    if flag == False:
        counter = 0
        sample = [c for c in S]
        for j in T:
            if sample[i+counter] != '?':
                if sample[i+counter] != j:
                    break
            else:
                sample[i+counter] = j
            counter += 1
            if counter == len(T):
                for k in range(len(sample)):
                    if sample[k] == '?':
                        sample[k] = 'a'
                sample = ''.join(sample)
                ans = sample
                flag = True

if flag:
    print ans
else:
    print 'UNRESTORABLE'

Solution (Python):
S = str(input())
T = str(input())
slist = list(S)
tlist = list(T)
Slen = len(slist)
Tlen = len(tlist)
ANSlist = []
Flag = 0
if Slen < Tlen:
    Flag = 0
else:
    for i in range(Slen-Tlen+1):
        flag = 0
        for j in range(Tlen):
            if slist[i+j] == "?" or slist[i+j] == tlist[j]:
                pass
            else:
                flag = 1
                break
        if flag == 0:
            Skari = ""
            k = 0
            for k in range(i):
                if slist[k] == "?":
                    Skari+="a"
                else:
                    Skari+=slist[k]
            l = 0
            for l in range(Tlen):
                Skari+=tlist[l]
            m = 0
            Skarilen = len(Skari)
            for m in range(Slen-Skarilen):
                M = m+Skarilen
                if slist[M] == "?":
                    Skari+="a"
                else:
                    Skari+=slist[M]
            ANSlist.append(Skari)
            Flag+=1
        else:
            pass
if Flag >= 1:
    print(min(ANSlist))
else:
    print("UNRESTORABLE")

Solution (Python):
s = input()
t = input()
s=s[::-1]
t=t[::-1]

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

for i in range(len_s-len_t+1):
  flag = True
  for j in range(len_t):
    if s[i+j]!=t[j] and s[i+j]!="?":
      flag = False
      break
  if flag:
    print((s[0:i]+t+s[i+len_t:len_s]).replace("?","a")[::-1])
    exit()
print("UNRESTORABLE")

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

l=[]
for i in range(len(S)-len(T)+1):
    f=True
    for j in range(len(T)):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            f=False
            break
    if f:
        tmp=S[:i]+T+S[i+len(T):]
        l.append(tmp.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
lst = []
for i in range(len(S) - len(T) + 1):
    pS = S[i:i + len(T)]
    for j in range(len(T)):
        if pS[j] != '?' and pS[j] != T[j]:
                break
    else:
        S_2 = S[0:i] + T + S[i + len(T):len(S)]
        lst.append(S_2.replace('?', 'a'))
if lst:
    lst.sort()
    print(lst[0])
else:
    print('UNRESTORABLE')

Solution (Python):
s0_r = list(input())[::-1]
t_r = list(input())[::-1]

for k in range(len(s0_r)-len(t_r)+1):
    for i in range(len(t_r)):
        if s0_r[k+i] != t_r[i] and s0_r[k+i] != "?":
            break
    else:
        for i in range(len(t_r)):
            s0_r[k+i] = t_r[i]
            s0 = s0_r[::-1]
        for k in range(len(s0)):
            if s0[k] == "?":
                s0[k] = "a"
        print(''.join(s0))
        break
else:
    print("UNRESTORABLE")

Solution (Python):


import re

def main():
    s = input()
    t = input()
    lt = len(t)
    for i in range(len(s) - lt, -1, -1):
        if re.match(s[i:i + lt].replace("?", "."), t):
            return s[:i].replace("?", "a") + t + s[i + lt:].replace("?", "a")
    return "UNRESTORABLE"


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

Solution (Python):


import re

def main():
    sp = input().replace("?", ".")
    t = input()
    ns = len(sp)
    nt = len(t)
    if ns < nt:
        return False
    se = set()
    for i in range(len(sp) - len(t) + 1):
        if re.match(sp[i:i + nt], t):
            res = sp[:i] + t + sp[i + nt:]
            assert len(res) == ns
            se.add(res.replace(".", "a"))
    if len(se) == 0:
        return False
    return sorted(list(se))[0]

res = main()
print(res if res else "UNRESTORABLE")

Solution (Python):
s=input()
t=input()
ans=[]
match=''
for i in range(len(s)-len(t)+1):
    flag=True
    for j in range(len(t)):
        if s[i+j]==t[j] or s[i+j]=='?':
            continue
        else:
            flag=False
    if flag:
        match=s[0:i]+t+s[i+len(t):]
        ans.append(match.replace('?','a'))
if ans==[]:
    print('UNRESTORABLE')
else:
    print(min(ans))

Solution (Python):
S=input()
T=input()
ans='UNRESTORABLE'
for j in range(len(S)-len(T)+1):
    flag=1
    for i in range(len(T)):
        if S[j+i]==T[i] or S[j+i]=='?':
            continue
        else:
            flag=0
    if flag:
        ans =S[0:j]+T+S[j+len(T):]
        ans =ans.replace('?','a')

print(ans)

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

for i in range(len(s) - len(t) + 1):
    match = True
    for tt, ss in zip(t, s[len(s) - len(t) - i: len(s) - i]):
        if ss not in ('?', tt):
            match = False
            break
    if match:
        ans = s[:len(s) - len(t) - i] + t + s[len(s) - i:]
        ans = ans.replace('?', 'a')
        break

print(ans)

Solution (Python):
import re

def resolve(patterns, text):
    res = "UNRESTORABLE"
    for i in reversed(range(len(patterns) - len(text) + 1)):
        if re.search(patterns[i:i+len(text)], text):
            res = patterns[:i] + text + patterns[i+len(T):]
            res = res.replace('.', 'a')
            return res
    return res

S_dash = raw_input().replace('?', '.')
T = raw_input()

print resolve(S_dash, T)

Solution (Python):
s = input()
t = input()
a = len(s)
b = len(t)
ans = []

for i in range(1+a-b):
  query = s[a-b-i:a-i] 
  
  ct= 0
  for j in range(b):
    if t[j] == query[j] or query[j] == '?':
      ct += 1
  if ct == b:
    ans.append(s[0:a-b-i]+t+s[a-i::])
if ans ==[] : print('UNRESTORABLE')
else:print(min(ans).replace('?','a'))

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

for i in range(len(s)-len(t),-1,-1):
    if (s[i] == '?') or (s[i] == t[0]):
        cnt = 0
        for j in range(len(t)):
            if (s[i+j] == '?') or (s[i+j] == t[j]):
                cnt += 1
            else:
                break
        
        if cnt == len(t):
            s[i:i+len(t)] = t
            break
else:
    print('UNRESTORABLE')
    exit()
        
for i in range(len(s)):
    if s[i] == '?':
        s[i] = 'a'
print(''.join(s))

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

def main(S, T, n, m):
    for i in range(n-m, -1, -1):
        flag = True
        for s, t in zip(S[i:i+m], T):
            if s == '?' or s == t:
                pass
            else:
                flag = False
                break
        if flag:
            S = S.replace('?', 'a')
            return S[:i] + T + S[i+m:]
    return 'UNRESTORABLE'

print(main(S, T, n, m))

Solution (Python):
S = input()
T = input()
 
ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    s = S[i:i+len(T)+1]
    flag = 1
    for j in range(len(T)):
        if s[j] == T[j] or s[j] == '?':
            pass
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T):]
        ans = ans.replace('?', 'a')
print(ans)

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

ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    flag = 1
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == '?':
            continue
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T):]
        ans = ans.replace('?', 'a')
print(ans)

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

ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    flag = 1
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == '?':
            continue
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T):]
        ans = ans.replace('?', 'a')
    
print(ans)

Solution (Python):
S = input()
T = input()
ans_list = []
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        part = S[i:j]
        if len(part) != len(T):
            continue
        for k in range(len(part)):
            if part[k] != T[k] and part[k] != "?":
                break
            elif k == len(part)-1:
                ans_str = S[:i] + T + S[j:]
                ans_str = ans_str.replace("?","a")
                ans_list.append(ans_str)
ans_list.sort()
if ans_list == []:
    print("UNRESTORABLE")
else:
    print(ans_list[0])

Solution (Python):
S = input()
T = input()
ans_list = []
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        part = S[i:j]
        if len(part) != len(T):
            continue
        for k in range(len(part)):
            if part[k] != T[k] and part[k] != "?":
                break
            elif k == len(part)-1:
                ans_str = S[:i] + T + S[j:]
                ans_list.append(ans_str)
ans_list = sorted([s.replace("?","a") for s in ans_list])
if ans_list == []:
    print("UNRESTORABLE")
else:
    print(ans_list[0])

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


def search(s, t):
    l_s = len(s)
    l_t = len(t)
    for i in range(l_s):
        if s[i] == t[0] or s[i] == '?':
            for j in range(l_t):
                if i+j < l_s:
                    if s[i+j] == t[j] or s[i+j] == '?':
                        if j == l_t-1:
                            return i
                        continue
                    else:
                        break
    return -1


s = s[::-1]
t = t[::-1]
ret = search(s, t)
if ret == -1:
    ans = 'UNRESTORABLE'
    print(ans)
else:
    ans = []
    for k in range(len(s)):
        if ret <= k <= ret+len(t)-1:
            ans.append(t[k-ret])
        else:
            if s[k] == '?':
                ans.append('a')
            else:
                ans.append(s[k])
    print(''.join(map(str, ans[::-1])))

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

flag=0
if len(t) > len(s):
    print("UNRESTORABLE")
else:
    index = len(s)-len(t)
    while index > -1:
        index2=0
        while index2 < len(t):
            if s[index+index2] == t[index2] or s[index+index2] == "?":
                index2+=1
            else:
                break
        if index2!=len(t):
            index-=1
        else:
            flag=1
            index2=0
            while index2 < len(t):
                if s[index+index2] == "?":
                    s[index+index2] = t[index2]
                index2+=1
            index3=0
            while index3 < len(s):
                if s[index3] == "?":
                    s[index3] = "a"
                index3+=1
            break
    if index == -1 and flag==0:
        print("UNRESTORABLE")
    else:
        print("".join(s))

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


def check1(s):
    ret = True
    for i in range(len(T)):
        if s[i] != '?' and s[i] != T[i]:
            ret = False
            break
    return ret


candidate = []
for i in range(len(S)-len(T)+1):
    if check1(S[i:i+len(T)]):
        candidate.append(i)

if not candidate:
    print('UNRESTORABLE')
else:
    S = S[:candidate[-1]] + T + S[candidate[-1]+len(T):]
    for i in range(len(S)):
        if S[i] == '?':
            S = S[:i] + 'a' + S[i+1:]
    print(S)

Solution (Python):
import copy
s = list(input())
t = list(input())
ans_list = []

if len(t)>len(s):
    print('UNRESTORABLE')
    exit()
else:

    for i in range(len(s)-len(t)+1): 
        sublist = copy.copy(s)
        for j in range(len(t)):
            if sublist[i+j] == '?':
                sublist[i+j] = t[j]
            elif sublist[i+j] != t[j]:
                break
        else:
            str_ans = ''.join(sublist)
            str_ans = str_ans.replace('?','a')
            ans_list.append(str_ans)

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

Solution (Python):
S = input()
T = input()
S = S[::-1]
T = T[::-1]

ans = "UNRESTORABLE"[::-1]
if len(S) >= len(T) :
    if T in S :
        ans = S
    else :
        for i in range(len(S)-len(T)+1) :
            S_ = S[i:i+len(T)]
            
            for j in range(len(T)) :
                if S_[j] == "?" :
                    continue
                if S_[j] != T[j] :
                    break
            else :
                ans = S[:i] + T + S[i+len(T):]
                break
ans = ans.replace("?","a")
ans = ans[::-1]
print(ans)

Solution (Python):
S_ = list(input())
T = list(input())
ans = []
for i in range(len(S_)-len(T)+1):
    for j in range(len(T)):
        if (T[j] == S_[i+j]) or (S_[i+j] == '?'):
            continue
        else:
            break
    else:
        S = S_[:i] + T + S_[i+len(T):]
        ans.append((''.join(S)).replace('?','a'))

if len(ans)!=0:
    print((sorted(ans))[0])
else:
    print('UNRESTORABLE')

Solution (Python):
SS = input()
T = input()
S = ""
for i in range(len(SS) - len(T) + 1):
    flg = True
    for j in range(len(T)):
        if SS[i+j] == "?":
            continue
        elif SS[i+j] == T[j]:
            continue
        else:
            flg = False
            break
    if flg == True:
        S = SS[0:i] + T + SS[i+len(T):]

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

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

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


def ok(i):
    for j in range(len(t)):
        if s[i + j] == '?':
            continue
        elif s[i + j] != t[j]:
            return False
    return True


for i in range(len(s) - len(t), -1, -1):
    if ok(i):
        s = s[:i] + t + s[i + len(t) :]
        s = s.replace('?', 'a')
        print(s)
        import sys
        sys.exit()
print('UNRESTORABLE')

Solution (Python):
Sd = input()
T = input()
flag = False
t = len(T)
answers = set()
if len(Sd) < t: pass
else:
    for i in range(0, len(Sd)+1-t):
        for j in range(0,t):
            if Sd[i+j] in (T[j], '?'):
                if j == t-1: flag = True
            else: break
        if flag:
            answers.add(Sd[:i].replace('?','a')+T+Sd[i+t:].replace('?','a'))
        flag = False

if answers:
    print(min(answers))
else:
    print('UNRESTORABLE')

Solution (Python):
s = str(input())
t = str(input())
ans = []
for i in range(len(s)-len(t)+1):
    s_part = s[i:i+len(t)]
    check = True
    for j in range(len(t)):
        if (s_part[j] != "?"): 
            if (s_part[j] != t[j]):
                check = False
    if check:
        a = s[0:i]+t+s[i+len(t):len(s)]
        ans.append(a.replace("?","a"))
if ans == []:
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])

Solution (Python):
s = str(input())
t = str(input())
index = []
n = len(s)
m = len(t)
if n>=m:
    for i in range(n-m+1):
        isFittable = True
        for j in range(m):
            if not (s[i+j]==t[j] or s[i+j]=="?"):
                isFittable = False
                break
        if isFittable:
            index.append(i)
ans = ""
if len(index)>0:
    i = index[-1]
    for j in range(n):
        if j<i or j>=i+m:
            if s[j]=="?":
                ans += "a"
            else:
                ans += s[j]
        else:
            ans += t[j-i]
    print(ans)
else:
    print("UNRESTORABLE")

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

def hantei(S,T):
    ans=True
    if(len(S)!=len(T)):
        return False
    for i in range(0,len(T)):
        if(S[i]==T[i] or S[i]=='?'):
            pass
        else:
            ans=False
            break
    return ans

ans=list()
for i in range(0,len(S)):
    if(hantei(S[i:i+len(T)],T)):
        ans.append(S[0:i]+T+S[i+len(T):100])
if(len(ans)>0):
    ans=list(ans[-1])
    for i in range(0,len(ans)):
        if(ans[i]=='?'):
            ans[i]="a"
            
    ans="".join(ans)
    print(ans)
else:
    print("UNRESTORABLE")

Solution (Python):
s = [x for x in input()]
t = [x for x in input()]
s_num = len(s);t_num = len(t)
ans = [x for x in 'z'*51]
chinpo = [x for x in 'z'*51]
for i in range(s_num-t_num+1):
    anco = list(s)
    for j in range(t_num):
        check = 0
        if s[i+j] == '?' or s[i+j] == t[j]:
            pass
        else:
            check = 1
            break
    if check == 0:
        for k in range(0,i):
            if anco[k] == '?':anco[k] = 'a'
        c = 0
        for k in range(i,i+t_num):
            anco[k] = t[c]
            c += 1
        for k in range(i+t_num,s_num):
            if anco[k] == '?':anco[k] = 'a'
        ans = min(ans,anco)
if ans == chinpo:print('UNRESTORABLE')
else:print(''.join(ans))

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


f=False




ns = len(S)
nt = len(T)
correspond=-1
index=ns-nt
answer=-1

while(1):
    correspond=1
    if index<0:break


    
    if nt > ns : break
    if (ns-index) < nt:break

    for i in range(index,nt+index):
        if S[i]=='?':
            continue
        elif S[i]!=T[i-index]:
            correspond=-1
            break

    if correspond==1 :    
        f=True
        answer=index
        
        break

    index-=1
    


if f==False:
    print('UNRESTORABLE')

if f==True:
    if ns==nt:
        answer_word=T
    else:
        if answer==0:
            answer_word=T+S[nt:]
        elif ns-answer==nt:
            answer_word=S[:answer]+T
        else:
            answer_word=S[:answer]+T+S[(nt+answer):]

    while(answer_word.count('?')>=1):
        answer_word=answer_word.replace('?','a')
        

    print(answer_word)

Solution (Python):
S = list(input())
T = list(input())
ans = []
for i in range(len(S) - len(T) + 1):
    tmp = S[:]
    count = 0
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
        elif S[i+j] == T[j]:
            tmp[i+j] = T[j]
            count += 1
        elif S[i+j] == '?':
            tmp[i+j] = T[j]
            count += 1

    if len(T) == count:
        ans.append(tmp)

if ans:

    ans1 = []
    for i in ans:
        word = ''.join(i)
        word = word.replace('?', 'a')
        ans1.append(word)

    ans1.sort()
    print(ans1[0])
else:
    print('UNRESTORABLE')

Solution (Python):
def check(i):
    for j in range(len(T)):
        if T[j] == S[i+j] or S[i+j] == "?":
            continue
        return False
    return True


def okikae(i):
    for j in range(len(T)):
        S[i+j] = T[j]
    return

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

for i in reversed(range(len(S)-len(T)+1)):
    if check(i) is True:
        last = i
        break
else:
    print("UNRESTORABLE")
    exit()

okikae(last)

for i in range(len(S)):
    if S[i] == "?":
        S[i] = "a"
print("".join(S))

Solution (Python):
s = input()
t = input()
S = len(s)
T = len(t)
ans= ''
for i in range(S-T+1):
    c = 1
    for j in range(T):
        if s[i+j] == t[j] or s[i+j] == '?':
            continue
        else:
            c = 0
    if c :
        ans = s[0:i] + t + s[i+T:]
if ans:
    ans = ans.replace('?','a')
    print(ans)
else:
    print('UNRESTORABLE')

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

ans = ''

for i in range(0, len(SD) - len(T)+1):
    flg = True
    for j in range(len(T)):
        if SD[i+j] == '?' or SD[i+j] == T[j]:
            continue
        else:
            flg = False
    if flg == True:
        ans = SD[0:i] + T + SD[i+len(T):]
            
if ans:
    ans = ans.replace('?', 'a')
else:
    ans = 'UNRESTORABLE'
    
print(ans)

Solution (Python):
S = input()
T = input()
r_S = S[::-1]
r_T = T[::-1]
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
if T in S:
    q_ans = r_S
else:
    for i in range(len(r_S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if r_S[i+j] == '?':
                pass
            elif r_S[i+j] == r_T[j]:
                pass
            elif r_S[i+j] != r_T[j]:
                flag = False
                break
        if flag:
            q_ans = r_S[:i] + r_T + r_S[i+len(T):]
            break
    if not flag:
        print('UNRESTORABLE')
        exit()

q_ans = q_ans[::-1]
ans = ''
for i in q_ans:
    if i == '?':
        ans += 'a'
    else:
        ans += i
print(ans)

Solution (Python):

SD = input()
T = input()
wordList = []
for i in range(len(SD)-len(T)+1):
    
    found = True
    for j in range(len(T)):
        
        if T[j]==SD[i+j] or SD[i+j]=='?': continue
        else:
            found = False
            break
    if found: 
        s = SD[:i]
        for j in range(len(T)): s +=  T[j]
        s += SD[i+len(T):]
        wordList.append(s)
wordList.sort()

if wordList==[]:
    S = 'UNRESTORABLE'
else:
    S = ''
    for c in wordList[0]:
        if c=='?': S += 'a'
        else:    S += c
print(S)

Solution (Python):
def judge(s,t):
    j = True
    if len(s) != len(t):
        return False
    for i in range(len(s)):
        if s[i] != '':
            if(s[i] == t[i] or s[i] == '?') :
                continue
            else:
                j  = False
        else:
            j = False
    return j
            
s = input()
t = input()
ans = 'z'*50
ok = False

for i in range(len(s)):
    if judge(s[i:(len(t)+i)],t):
        ok = True
        s1 = s[0:i]
        s1 += t
        s1 += s[len(t)+i:len(s)]
        if ans > s1:
            ans = s1
if ok :
    print(ans.replace('?','a'))
else:
    print('UNRESTORABLE')

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


def Find(S, T):
    ans = ''
    for i in range(0, len(S)-len(T)+1):
        s = S[i:i+len(T)]
        boolen = 1
        for j in range(len(s)):
            if not(s[j] == '?' or T[j] == s[j]):
                boolen *= 0
        if boolen == 1:
            ans = S[:i] + T + S[i+len(T):]
    return ans


ans = Find(S, T)

if ans:
    ans = list(ans)
    for i, v in enumerate(ans):
        if v == '?':
            ans[i] = 'a'
    ans = ''.join(ans)
    print(ans)
else:
    print('UNRESTORABLE')

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

reslis = []

if len(Sdash) >= len(T):
    for i in range(len(Sdash) - len(T) + 1):
        res = Sdash
        temp = Sdash[i:i+len(T)]
        for k in range(len(T)):
            if T[k] == temp[k] or temp[k] == "?":
                res = list(res)
                res[k+i] = T[k]
                res = "".join(res)
            else:
                break
        else:
            reslis.append(res) 

if reslis:
    reslis = [st.replace("?", "a") for st in reslis]
    print(min(reslis))
else:
    print("UNRESTORABLE")

Solution (Python):
def may_eq(s, t):
    return all(c_s == '?' or c_s == c_t for c_s, c_t in zip(s, t))


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

    if not '?' in s:
        print(s)
        return

    if len(t) > len(s):
        print('UNRESTORABLE')
        return

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

    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

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

for i in range(len(S)-len(T)+1) :
    for j in range(len(T)) :
        if S[i+j] not in ("?", T[j]) :
            break
    else :
        l = S[:i]+T+S[i+len(T):]
        l = l.replace("?","a")
        L.append(l)
if L :
    print(min(L))
else :
    print("UNRESTORABLE")