Problem p03565 (python)

Fixed submission:
#!/usr/bin/env python3
import re
No = "UNRESTORABLE"

def main():
    S = input()
    T = input()
    T_LEN = len(T)
    match_index = []

    for i in range(len(S) - T_LEN + 1):
        for idx in range(T_LEN):
            if S[i:i+T_LEN][idx] == T[idx] or S[i:i+T_LEN][idx] == "?":
                continue
            else:
                break
        else:
            match_index.append(i)
    
    if not match_index:
        print(No)
    
    else:
        answer = list(S)
        answer[match_index[0]:match_index[0] + T_LEN] = list(T)
        answer = "".join(answer)
        answer = answer.replace("?","a")

        if len(match_index) == 1:
            print(answer)

        else:
            for i in match_index[1:]:
                tmp_ans = list(S)
                tmp_ans[i:i + T_LEN] = list(T)
                tmp_ans = "".join(tmp_ans)
                tmp_ans = tmp_ans.replace("?","a")
                answer = min(tmp_ans,answer)

            print(answer)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import re
No = "UNRESTORABLE"

def main():
    S = input()
    T = input()
    T_LEN = len(T)
    match_index = []

    for i in range(len(S) - T_LEN + 1):
        for idx in range(T_LEN):
            if S[i:i+T_LEN][idx] == T[idx] or S[i:i+T_LEN][idx] == "?":
                continue
            else:
                break
        else:
            match_index.append(i)
    
    if not match_index:
        print(No)
    
    else:
        answer = list(S)
        answer[match_index[0]:match_index[0] + T_LEN] = list(T)
        answer = "".join(answer)

        if len(match_index) == 1:
            answer = answer.replace("?","a")
            print(answer)

        else:
            for i in match_index[1:]:
                tmp_ans = answer = list(S)
                tmp_ans[match_index[i]:match_index[i] + T_LEN] = list(T)
                tmp_ans = "".join(tmp_ans)
                tmp_ans = tmp_ans.replace("?","a")
                answer = min(tmp_ans,answer)

            print(answer)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import re
No = "UNRESTORABLE"

def main():
    S = input()
    T = input()
    T_LEN = len(T)
    match_index = []

    for i in range(len(S) - T_LEN + 1):
        for idx in range(T_LEN):
            if S[i:i+T_LEN][idx] == T[idx] or S[i:i+T_LEN][idx] == "?":
                continue
            else:
                break
        else:
            match_index.append(i)
    
    if not match_index:
        print(No)
    
    else:
        answer = list(S)
        answer[match_index[0]:match_index[0] + T_LEN] = list(T)
        answer = "".join(answer)

        if len(match_index) == 1:
            answer = answer.replace("?","a")
            print(answer)

        else:
            for i in match_index[1:]:
                tmp_ans = answer = list(S)
                tmp_ans[match_index[i]:match_index[i] + T_LEN] = list(T)
                tmp_ans = "".join(tmp_ans)
                tmp_ans = tmp_ans.replace("?","a")
                answer = min(tmp_ans,answer)

            print(answer)

if __name__ == '__main__':
    main()