Problem p03565 (python)

Fixed submission:
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")

Buggy submission (verdict: Runtime Error):
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+Slen
                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")

Buggy submission (verdict: Runtime Error):
S = str(input())
T = str(input())
slist = list(S)
tlist = list(T)
Slen = len(slist)
Tlen = len(tlist)
ANSlist = []
Flag = 0
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+Slen
            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")