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=str(input())
t=str(input())
ans=0
for j in range(len(s)-len(t)+1):
    e=s[j:j+len(t)]
    
    for i in range(len(t)):
        if t[i]!=e[i] and e[i]!='?':
            break
    else:
        ans=s[:j]+t+s[j+len(t):]
if ans:
    for i in range(len(ans)):
        if ans[i]=='?':
            ans=ans[:i]+'a'+ans[i+1:]
    print(ans)
else:
    print('UNRESTORABLE')

Solution (Python):
import copy
S = list(input())
T = list(input())
ans = "UNRESTORABLE"

for i in range(len(S)-len(T),-1,-1):
    flag = 1
    s = copy.deepcopy(S)
    x = S[i:i+len(T)]
    for j in range(len(x)):
        if x[j] == "?":
            s[i+j] = T[j]
        elif x[j] != T[j]:
            flag = 0
            break
    if flag:
        ans = "".join(s).replace("?", "a")
        break
print(ans)

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

res = ""
for i in range(len(S)-len(T),-1,-1):
    tmp = list(S)
    flag = True
    for j in range(i,i+len(T)):
        if S[j] != T[j-i] and S[j] != "?":
            flag = False 
    if flag:
        for j in range(i,i+len(T)):
            tmp[j] = T[j-i]
        for i in range(len(tmp)):
            if tmp[i] == "?":
                tmp[i] = "a"
        res = "".join(tmp)
        break
else:
    res = "UNRESTORABLE"

print(res)

Solution (Python):
import re

s = input()
t = input()

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

res = s.replace('?', 'a')

print(res)

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

t_len = len(T)
found = False
for i in range(len(S)-len(T), -1,-1):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        if i + t_len == len(S):
            S = S[:i] + T
        else:
            S = S[:i] + T + S[i+t_len:]
        found = True
    if found:
        print(S.replace('?','a'))
        break
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()

for i in range(len(S_)-len(T), -1, -1):
    for j in range(len(T)):
        if S_[i+j] not in (T[j], '?'):
            break
    else:
        print(S_[:i].replace('?', 'a')+T+S_[i+len(T):].replace('?', 'a'))
        exit()
print('UNRESTORABLE')

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

if T in S:
    print(S.replace('?', 'a'))
    exit()

SL = len(S)
TL = len(T)

proposition = []
for i in range(SL-TL, -1, -1):
    S2 = S[i:i+TL]
    for j in range(TL):
        if S2[j] == T[j] or S2[j] == '?':
            continue
        else:
            break
    else:
        answer = S[:i] + T + S[i+TL:]
        proposition.append(answer.replace('?', 'a'))
if proposition:
    print(sorted(proposition)[0])
else:
    print('UNRESTORABLE')

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

if T in S:
    print(S.replace('?', 'a'))
    exit()

SL = len(S)
TL = len(T)

for i in range(SL-TL, -1, -1):
    S2 = S[i:i+TL]
    for j in range(TL):
        if S2[j] == T[j] or S2[j] == '?':
            continue
        else:
            break
    else:
        answer = S[:i] + T + S[i+TL:]
        print(answer.replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Solution (Python):
s=input()
t=input()
u='UNRESTORABLE'
a=[]
if len(s)>=len(t):
  for i in range(len(s)-len(t)+1):
    f=0
    for j in range(i,i+len(t)):
      if s[j]!='?' and s[j]!=t[j-i]:
        f=1
    if f==0:
      m=s[:i]+t+s[i+len(t):]
      m=m.replace('?','a',50)
      a.append(m)
if len(a)==0:
  print(u)
else:
  a.sort()
  print(a[0])

Solution (Python):
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
strs.sort()
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

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

L = []

if len(s) >= len(t):
  for i in range(len(s)-len(t)+1):
    if all([s[i+j]==t[j] or s[i+j]=='?' for j in range(len(t))]):
      l = str()
      for k in range(len(s)):
        if i <= k < i+len(t):
          l += t[k-i]
        elif s[k] == '?':
          l += 'a'
        else:
          l += s[k]
      L += [l]
      
if L:
  print(min(L))
else:
  print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
lenS=len(S)
lenT=len(T)
ans=["a"]*lenS
for i in range (lenS):
    if(S[i]!="?"):
        ans[i]=S[i]
flag=0
for j in range(lenS-lenT+1):
    flag=1
    for i in range (lenS):
        if(S[i]=="?"):
            ans[i]="a"

    for i in range(1,lenT+1):
        if((S[lenS-i-j]!="?")&(S[lenS-i-j]!=T[lenT-i])):
            flag=0
            break
        else:
            ans[lenS-i-j]=T[lenT-i]
    
    if(flag==1):
        break

if(flag==1):
    print("".join(ans))
else:
    print("UNRESTORABLE")

Solution (Python):

sd = input()
scnt = len(sd)
t = input()
tcnt = len(t)

point = 0
unrestorable = True
while point <= scnt - tcnt:
    oneroopcorres = True
    for i in range(tcnt):
        anyone = sd[point+i] == '?'
        correspond = sd[point+i] == t[i]
        if not (anyone or correspond):
            oneroopcorres = False

    if oneroopcorres:
        unrestorable = False
        good_point = point

    point += 1

if unrestorable:
    print('UNRESTORABLE')
    exit()
else:
    sd = list(sd)
    for i in range(tcnt):
        sd[good_point + i] = t[i]
    sd = ''.join(sd)

sd = sd.replace('?', 'a')
print(sd)

Solution (Python):
SS = input()
T = input()
N = len(SS) - len(T)
key = []
key_t = []
for i in range(N,-1,-1):
  tmp = i
  cnt = 0
  cnt_t = 0
  for j in range(len(T)):
    if SS[tmp] != T[j] and SS[tmp] != "?":
      pass
    else:
      if SS[tmp] == T[j]:
        cnt += 1
        cnt_t += 1
      else:
        cnt += 1
    tmp += 1
  if cnt == len(T):
    key.append(i)
  if cnt_t == len(T):
    key_t.append(i)
SS = list(SS)
if len(key_t) >= 1:
  for i in SS:
    if i == "?":
      print("a",end="")
    else:
      print(i,end="")
elif len(key) >= 1:
    g = key[0]
    for i in range(len(T)):
      SS[g] = T[i]
      g += 1
    for s in SS:
      if s == "?":
        print("a",end="")
      else:
        print(s,end="")
else:
  print("UNRESTORABLE")

Solution (Python):
s = input()
S = input()
ary = []
flag = False
for i in range(len(s)-len(S)+1):
    if s[i] == S[0] or s[i] == "?":
        a = s[i:i+len(S)]
        for j in range(len(S)):
            if a[j] == S[j] or a[j] == "?":continue
            break
        else:
            flag = True
            ary.append(s[:i]+S+s[i+len(S):])
print(sorted(i.replace("?","a") for i in ary)[0] if flag else "UNRESTORABLE")

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

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if T[j] != S[i+j] != '?':
            break
    else:
        break
else:
    print('UNRESTORABLE')
    exit()

ans = (S[:i] + T + S[i+len(T):])[::-1]
ans = ans.replace('?', 'a')
print(ans)

Solution (Python):
s = input()
t = input()
def check(A, B):
    for a, b in zip(A, B):
        if a != '?' and a != b:
            return False
    return True


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

Solution (Python):
s = input()
S = input()
flag = False
ans = []
for i in range(len(s)-len(S)+1):
    if s[i] == S[0] or s[i] == "?":
        a = s[i:i+len(S)]
        for j in range(len(S)):
            if a[j] == S[j] or a[j] == "?":
                continue
            break
        else:
            flag = True
            ans.append(s[:i]+S+s[i+len(S):])
if not flag:
    print("UNRESTORABLE")
    exit()
for i in range(len(ans)):
    ans[i] = ans[i].replace("?","a")
ans.sort()
print(ans[0])

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

LS=len(S)
LT=len(T)
ans=[]

for i in range(LS-LT+1):
    for j in range(LT):
        if not (T[j]==S[i+j] or S[i+j]=="?"):
            break
        if j==LT-1:
            ans.append(list(S[0:i]+T+S[i+LT:]))

Lans=len(ans)

if Lans==0:
    print("UNRESTORABLE")
    exit()


for i in range(Lans):
    for j in range(LS):
        if ans[i][j]=="?":
            ans[i][j]="a"
    ans[i]="".join(ans[i])

ans.sort()

print(ans[0])

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



SD = list(input().rstrip())
T = list(input().rstrip())

lenSD = len(SD)
lenT = len(T)

def match(i):
    s = SD[i:i+lenT]
    for i in range(len(s)):
        if s[i] == '?':
            continue
        if s[i] != T[i]:
            return False

    return True




match_i = -1
for i in range(lenSD):
    if (lenSD - lenT) < i:
        break

    if match(i):
        match_i = i

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


i = match_i
for j in range(lenT):
    if SD[i+j] == '?':
        SD[i+j] = T[j]

for i in range(lenSD):
    if SD[i] == '?':
        SD[i] = 'a'

print(*SD, sep="")

Solution (Python):
import re


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


main()

Solution (Python):
s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    return a == b
  
cand = []
for i in range(len(s)-len(t)+1):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    cs = ''.join(c)
    cand.append(cs.replace('?', 'a'))
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
ns=len(s)
nt=len(t)
li=[]
for i in range(ns-nt+1):
    for j in range(nt):
        if s[i]==t[j] or s[i]=='?':
            i+=1
            continue
        else:
            break
    else:
        li.append(s[:i-nt]+t+s[i:])

li2=[]
for i in li:
    li2.append(i.replace('?','a'))
li2.sort()
print(li2[0] if li2 else 'UNRESTORABLE')

Solution (Python):
import copy

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

ans_list = []
for i in range(len(s) - len(t) + 1):
    tmps = s[i:i + len(t)]
    ok = True
    for j in range(len(tmps)):
        if t[j] == tmps[j] or tmps[j] == '?':
            pass
        else:
            ok = False
            break
    if ok == True:
        cp_s = copy.deepcopy(s)
        for k in range(len(t)):
            cp_s[k+i] = t[k]
        ans_list.append(cp_s)

if len(ans_list) == 0:
    print("UNRESTORABLE")
else:
    
    for i in range(len(ans_list)):
        for j in range(len(s)):
            if ans_list[i][j] == '?':
                ans_list[i][j] = 'a'
    ans_list.sort()
    for c in ans_list[0]:
        print(c, end="")
    print()

Solution (Python):
def resolve():
    S = input()
    T = input()
    can_insert = False

    for start in range(len(S)-len(T),-1,-1):
        can_insert = True
        for i,c in enumerate(T):
            if S[start+i] != c and S[start+i] != "?":
                can_insert = False
        if can_insert:
            list_s = list(S)
            list_s[start:start+len(T)] = T
            S = "".join(list_s)
            print(S.replace("?","a"))
            break
    if not can_insert:
        print("UNRESTORABLE")
resolve()

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

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

  for i in range(len(s)-len(t)+1)[::-1]:
    f=True
    for j in range(len(t)):
      
      if s[i+j]!=t[j] and s[i+j]!='?':
        f=False
        break
    if f:
      return (s[:i]+t+s[i+len(t):]).replace('?','a')
  return 'UNRESTORABLE'


print(main())

Solution (Python):
S = input()
T = input()
ls = len(S)
lt = len(T)
a = ''
for i in range(ls):
    try:
        s = S[ls-i-lt:ls-i]
        for j in range(lt):
            if not (s[j] == T[j] or s[j] == '?'):
                break
        else:
            a += S[:ls-i-lt].replace('?', 'a') + T + S[ls-i:].replace('?', 'a')
            break
    except:
        pass
print(a if a else 'UNRESTORABLE')

Solution (Python):
s = input()
t = input()
chancenum = []

for i in range(0,len(s) - len(t)+1):
    if s[i] == t[0] or s[i] == "?":
        n = 1
        while n < len(t) and (s[i+n] == t[n] or s[i+n] == "?"):
            n += 1
        if n == len(t):
            chancenum.append(i)

if chancenum == []:
    print("UNRESTORABLE")
else:
    tright = max(chancenum)
    for i in range(0,len(t)):
        s = s[:tright] + t + s[tright+len(t):]
    print(s.replace('?', 'a'))

Solution (Python):
def main():
    s = "".join(reversed(list(input())))
    t = "".join(reversed(list(input())))
    anses = []

    for i in range(len(s)):
        for j in range(len(t)):
            if i+j < len(s) and (s[i+j] == t[j] or s[i+j] == '?'):
                continue
            else:
                break
        else:
            
            ans = (s[:i]+t+s[i+len(t):]).replace('?', 'a')
            anses.append("".join(reversed(list(ans))))
            continue
    anses.sort()
    print(anses[0] if anses else "UNRESTORABLE")

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    s = input()
    t = input()
    if t in s:
        print(s.replace('?', 'a'))
        return
    s = "".join(reversed(list(s)))
    t = "".join(reversed(list(t)))
    anses = []

    for i in range(len(s)):
        for j in range(len(t)):
            if i+j < len(s) and (s[i+j] == t[j] or s[i+j] == '?'):
                continue
            else:
                break
        else:
            
            ans = (s[:i]+t+s[i+len(t):]).replace('?', 'a')
            anses.append("".join(reversed(list(ans))))
            continue
    anses.sort()
    print(anses[0] if anses else "UNRESTORABLE")

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    s = input()
    t = input()
    if t in s:
        print(s.replace('?', 'a'))
        return
    s = "".join(reversed(list(s)))
    t = "".join(reversed(list(t)))
    anses = []

    for i in range(len(s)):
        for j in range(len(t)):
            sw1, sw2 = False, False
            if i+j < len(s) and (s[i+j] == t[j] or s[i+j] == '?'):
                continue
            else:
                
                sw2 = True
                break
        else:
            
            ans = (s[:i]+t+s[i+len(t):]).replace('?', 'a')
            anses.append("".join(reversed(list(ans))))
            continue
    anses.sort()
    print(anses[0] if anses else "UNRESTORABLE")

if __name__ == '__main__':
    main()

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


li=[]
for i in range(len(s)-1,len(t)-2,-1):
    if s[i]==t[-1] or s[i]=='?':
        j=-1
        while s[i]==t[j] or s[i]=='?':
            i-=1
            j-=1

            if -j>len(t):
                ss=s[:i+1]+t+s[i+len(t)+1:]
                li.append(ss.replace('?','a'))
                break
li.sort()

print(li[0] if li else 'UNRESTORABLE')

Solution (Python):
s, t = [s.strip() for s in open(0)]

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

Solution (Python):

S = input()
T = input()
N = len(S)
K = len(T)

ans = []
flag = False
for i in range(N-K+1):
    for j in range(K):
        if not(S[i+j] == T[j] or S[i+j] == '?'):
            break
    else:
        flag = True
        tmp = list(S)
        for j in range(K):
            tmp[i+j] = T[j]
        for j in range(N):
            if tmp[j] == '?': tmp[j] = 'a'
        tmp = ''.join(tmp)
        ans.append(tmp)
        
if flag:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    s=input().replace('?','.')
    t=input()
    import re
    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):])
            return
    print("UNRESTORABLE")
resolve()

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

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


for i in range(len(ss)-len(t)+1):
    match_len=0
    for j in range(len(t)):
        if ss[i+j]=="?" or ss[i+j]==t[j]:
            match_len+=1
        else:
            break
        if match_len==len(t):
            ss=ss[:i]+t+ss[i+len(t):]
            ss=ss.replace("?","a")
            print(ss[::-1])
            exit()
print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
s = len(S)
t = len(T)
l = []
ans = []

if s < t:
    print('UNRESTORABLE')
    exit()

for i in range(s - t + 1):
    for j in range(t):
        if T[j] == S[i + j] or S[i + j] == '?':
            if j == t - 1:
                l.append(i)
            continue
        else:
            break

if l:
    for i in l:
        if i != 0 and i != s - 1:
            ans.append((S[:i] + T + S[i + t:]).replace('?', 'a'))
        elif i == 0:
            ans.append((T + S[t:]).replace('?', 'a'))
        else:
            ans.append((S[:i] + T).replace('?', 'a'))
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

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

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

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

Sd = input()
T = input()
N = len(Sd)
M = len(T)
for i in range(N-M, -1, -1):
    t_ = Sd[i:i+M]
    for j in range(M + 1):
        if j == M:
            print((Sd[:i] + T + Sd[i+M:]).replace('?', 'a'))
            exit()
        if t_[j] == '?':
            continue
        elif t_[j] != T[j]:
            break
print('UNRESTORABLE')

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

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

Solution (Python):

import sys
import re
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

ss = input()[:-1].replace('?', '.')
t = input()[:-1]

ans = []
for i in range(len(ss) - len(t) + 1):
    m = re.match(ss[i:i+len(t)], t)
    if (m != None):
        ans.append(ss[:i] + t + ss[i + len(t):])
if (len(ans) == 0):
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    ans[i] = ans[i].replace('.', 'a')
ans.sort()
print(ans[0])

Solution (Python):
s=input()
t=input()
l=len(s)
m=len(t)
L=[]
for i in range(l-m+1):
    if all([s[i+j]=='?' or s[i+j]==t[j] for j in range(m)]):
        L.append(i)
if L:
    k=max(L)
    print((s[:k]+t+s[k+m:]).replace('?','a'))
else:
    print('UNRESTORABLE')

Solution (Python):

s = input()
t = input()
result = []
for i in range(len(s)-len(t)+1):
    restorable = True
    for j in range(len(t)):
        if (s[i+j] != "?") & (s[i+j] != t[j]):
            restorable = False
            break
    if restorable:
        tmp_s = []
        tmp_s.append(s[0:i].replace("?", "a"))
        tmp_s.append(t)
        tmp_s.append(s[i+len(t):len(s)+1].replace("?", "a"))
        result.append("".join(tmp_s))

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

Solution (Python):
s=input()
t=input()
if len(s)<len(t):
	print("UNRESTORABLE")
	exit()
d=[]
for i in range(len(s)-len(t)+1):
	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):
		p=""
		for j in range(i):
			if s[j]=="?":
				p+="a"
			else:
				p+=s[j]
		for j in range(i,len(t)+i):
			p+=t[j-i]
		for j in range(len(t)+i,len(s)):
			if s[j]=="?":
				p+="a"
			else:
				p+=s[j]
		d.append(p)
if len(d)==0:
	print("UNRESTORABLE")
else:
	print(min(d))

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

N, M = len(S), len(T)

if N < M:
    print('UNRESTORABLE')
else:
    for i in range(max(0,N-M), -1, -1):
        
        
        now = S[i:i+M]

        
        for j in range(M):
            if now[j] == '?' or now[j] == T[j]:
                continue
            else:
                break
        else:
            
            S = S[0:i] + T + S[i+M:N]
            
            S = S.replace('?', 'a')
            print(S)
            break
    else:
        
        print('UNRESTORABLE')

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


def main():
    S = input()[:-1]
    T = input()[:-1]

    A = []
    for i in range(len(S)-len(T)+1):
        flg = True
        for j in range(len(T)):
            if S[i+j:i+j+1] not in [T[j:j+1], '?']:
                flg = False
        
        if flg:
            K = S[:i] + T + S[i+len(T):]
            A.append(K.replace('?', 'a'))
    
    if len(A)==0 or len(S)<len(T):
        print('UNRESTORABLE')
        return
    print(min(A))


if __name__ == '__main__':
    main()

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

if len(S)>=len(T):
    emptylists=[]
    flag=True
    for x in range(len(S)+1-len(T)):
        judgement=1 if all(  S[-(x+j)]=="?" or S[-(x+j)]==T[-j] for j in range(1,len(T)+1)) else 0
        if judgement==1:
            flag=False
            if x==0:
                words=str(S[:-len(T)]+T)
                changed=words.replace("?","a")
                emptylists.append(changed)
                
                
            else:
                words=S[:-len(T)-x]+T+S[-x:]
                changed=words.replace("?","a")
                emptylists.append(changed)
        else:
            continue
        ans=sorted(emptylists)

    if flag:
        print("UNRESTORABLE")
    else:
        print(ans[0])
        
if len(S)<len(T):
    print("UNRESTORABLE")

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    s = list(str(input().rstrip('\n')))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t), -1, -1):
        ts = s[i:i + len(t)]
        b = True
        for j in range(len(t)):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(t)):
                s[i + j] = t[j]
            for j in range(len(s)):
                if s[j] == "?":
                    s[j] = "a"
            print("".join(s))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

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

t = float('inf')
for i in range(len(S2)-len(T), -1, -1):
    flag = True
    for j in range(len(T)):
        if S2[i+j] == '?':
            continue
        if S2[i+j] != T[j]:
            flag = False
            break
    if flag:
        t = i
        break
        
if t == float('inf'):
    print('UNRESTORABLE')
    exit()
else:
    S2 = S2.replace('?', 'a')
    answer = S2[:t] + T + S2[t+len(T):]
    print(answer)

Solution (Python):
S,T=input(),input()
N=len(S)
M=len(T)
U=[]

ans="UNRESTORABLE"
if N>=M:
  for i in range(N-M+1):
    cnt=0
    for j in range(M):
      if S[i+j]==T[j] or S[i+j]=="?":
        cnt+=1
        
    if cnt==M:
      U.append((S[:i]+T+S[i+M:]).replace("?","a"))
U.sort()


if len(U)>0:
  ans=U[0]
print(ans)

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

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

d_len = len(D)
t_len = len(T)

flag = 0
p = -1






for i in range(d_len - t_len, -1, -1):
        
        for j in range(t_len):
            if flag == 1:
                break

            if D[i+j] == '?' or D[i+j] == T[j]:
                if j == t_len - 1:
                    flag = 1
                    p = i
                    break
            else:
                break
    
if flag == 1:
    
    c = 0

    while True:
        if c == p:
            print("".join(T),end="")
            c += t_len
        elif c >= d_len:
            break
        elif D[c] == '?':
            print("a",end="")
            c += 1
        else:
            print(D[c],end="")
            c += 1
    
    print()

else:
    print("UNRESTORABLE")

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

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

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

for i in range(-1,len(T)-len(S)-2,-1):
  f=1
  for j in range(-1,-1*len(T)-1,-1):
    if S[i+j+1]==T[j] or S[i+j+1]=="?":pass
    else:f=0
  if f==1:
    S=list(S)
    for j in range(-1,-1*len(T)-1,-1):
      S[i+j+1]=T[j]
    for k in range(len(S)):
      if S[k]=="?":S[k]="a"
    print("".join(S))
    exit(0)
print("UNRESTORABLE")

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

S.reverse()
T.reverse()


cnt=False
cnti = 0

for i in range(0, len(S)-len(T)+1):
    if cnt:break
    for j in range(len(T)):
        if S[i+j]=='?' or S[i+j]==T[j]:
            cnt = True
            cnti=i
        else:
            cnt=False
            break

if not cnt:print('UNRESTORABLE')
else:
    for i in range(len(T)):
        S[i+cnti] =T[i]

    S.reverse()
    S = ''.join(S)
    print(S.replace('?', 'a'))

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

for i in range(len(S) - len(T) + 1):
    if all((S[i+j] == "?" or S[i+j] == T[j]) for j in range(len(T))):
        UNRESTORABLE = False
        break
if UNRESTORABLE:
    print("UNRESTORABLE")
else:
    ans = []
    for k in range(len(S)):
        if i <= k <= i + len(T) - 1:
            ans.append(T[k-i])
        elif S[k] == '?':
            ans.append('a')
        else:
            ans.append(S[k])

    print(''.join(ans[::-1]))

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

Solution (Python):
s=input()
t=input()
f=0
e=len(t)
flg=0
while e<=len(s):
  tmp=s[f:e]
  for i in range(len(t)):
    if tmp[i]!=t[i] and tmp[i]!='?':
      break
    if i==len(t)-1:
      ans=s[:f]+t+s[e:]
      flg=1
  f+=1
  e+=1
if flg==0:
  print('UNRESTORABLE')
else:
  print(ans.replace('?','a'))

Solution (Python):
import re
S_ = input()
T = input()
Tr = T[::-1]
Sr = S_[::-1]
reg = "".join(map(lambda x: "[{}?]".format(x), Tr))
ans = re.sub(reg, Tr, Sr, count=1)
if ans.count(Tr)==1:
    print(ans.replace("?", "a")[::-1])
else:
    print("UNRESTORABLE")

Solution (Python):
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

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


cand = []
for i in range(0, len_s - len_t + 1):
    a = list(s)
    flag = True
    for j in range(len_t):
        
        if s[i+j] == "?":
            a[i+j] = t[j]
        elif s[i+j] != t[j]:
            flag = False
            break
    if flag:
        cand.append(a)

if cand:
    print("".join(cand[-1]).replace("?", "a"))
    sys.exit()
else:
    print("UNRESTORABLE")

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

li=[]
for i in range(len(s)-len(t)+1):
    if s[i]==t[0] or s[i]=='?':
        check=1
        tid=1
        if len(t)==1:
            li.append(s[:i-len(t)+1]+t+s[i+1:])
        else:

            while True:
                if s[i+1] ==t[tid] or s[i+1]=='?':

                    check+=1
                    i+=1
                    tid+=1

                    if check==len(t):
                        li.append(s[:i-len(t)+1]+t+s[i+1:])
                        break
                else:
                    break

li2=[]      

for i in li:

    li2.append(i.replace('?','a'))
    

li2.sort()


print(li2[0] if li2 else 'UNRESTORABLE')