Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

Ss = input()
T =  input()

Tdic = defaultdict(lambda: len(T))

for idx,i in  enumerate(T):
    Tdic[i] = len(T) -(idx+1)
    
Tdic[T[-1]] = len(T)
Tdic["?"] = 1
    
Flag = False
mutchdic = dict()
mutch = 0
head = len(T)-1
          
while(1):
    for i in range(len(T)):
        if T[-(i+1)] == Ss[head-i]:
            mutch += 1
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += len(T)
                mutch = 0
                Flag = True
        elif Ss[head-i] == "?":
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += 1
                mutch = 0
                Flag = True
        else:
            mutchdic[head] = mutch
            head += Tdic[Ss[head]]
            break
    if head > len(Ss)-1:
        break

if Flag:
    SsL = list(Ss)
    max_head = max(mutchdic.items(), key=lambda x:x[1])[0]
    for i in range(len(T)):
        SsL[max_head-i] = T[-(i+1)]
        SsLstr = "".join(SsL)
        SsLstr=SsLstr.replace("?","a")
        ans = SsLstr
else:
    ans = "UNRESTORABLE"

print(ans)

Fixed submission:
Sd = input()
T  = input()

S_r = Sd[::-1]
T_r = T[::-1]

lenS = len(Sd)
lenT = len(T)

Flag2 = True

if lenS < lenT:
    pass
else:
    for i in range(lenS - lenT + 1):
        for j in range(lenT):
            Flag1 = True
            if S_r[i+j] == "?" or S_r[i+j] == T_r[j]:
                pass
            else:
                Flag1 =False
                break
        if Flag1:
            Flag2 = False
            S_r = S_r.replace(S_r[i:i+lenT],T_r,1)
            S_r = S_r.replace("?","a")
            ans = S_r[::-1]
            break

if Flag2:
    ans = "UNRESTORABLE"
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

Ss = input()
T =  input()

Tdic = defaultdict(lambda: len(T))

for idx,i in  enumerate(T):
    Tdic[i] = len(T) -(idx+1)
    
Tdic[T[-1]] = len(T)
Tdic["?"] = 1
    
Flag = False
mutchdic = dict()
mutch = 0
head = len(T)-1
          
while(1):
    for i in range(len(T)):

        if T[-(i+1)] == Ss[head-i]:
            mutch += 1
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += len(T)
                mutch = 0
                Flag = True
        elif T[-(i+1)] == "?":
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += 1
                mutch = 0
                Flag = True
        else:
            mutchdic[head] = mutch
            head += Tdic[Ss[head-i]]+1-i
    if head > len(Ss)-1:
        break

if Flag:
    SsL = list(Ss)
    max_head = max(mutchdic.items(), key=lambda x:x[1])[0]
    for i in range(len(T)):
        SsL[max_head-i] = T[-(i+1)]
        SsLstr = "".join(SsL)
        SsLstr=SsLstr.replace("?","a")
        ans = SsLstr
else:
    ans = "UNRESTORABLE"

print(ans)

Fixed submission:
Sd = input()
T  = input()

S_r = Sd[::-1]
T_r = T[::-1]

lenS = len(Sd)
lenT = len(T)

Flag2 = True

if lenS < lenT:
    pass
else:
    for i in range(lenS - lenT + 1):
        for j in range(lenT):
            Flag1 = True
            if S_r[i+j] == "?" or S_r[i+j] == T_r[j]:
                pass
            else:
                Flag1 =False
                break
        if Flag1:
            Flag2 = False
            S_r = S_r.replace(S_r[i:i+lenT],T_r,1)
            S_r = S_r.replace("?","a")
            ans = S_r[::-1]
            break

if Flag2:
    ans = "UNRESTORABLE"
print(ans)