Problem p03565 (python)

Fixed submission:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)
    start = None

    for si, s in enumerate(S):
        if tn > (sn - si):
            break
        if s == T[0] or s == '?':
            sj = start_tmp = si
            for t in T:
                sj_c = S[sj]
                if not (t == sj_c or sj_c == '?'):
                    start_tmp = None
                    break
                sj += 1
            start = start_tmp if start_tmp is not None else start

    if start is None:
        return "UNRESTORABLE"

    ret = []
    ti = 0
    for si, s in enumerate(S):
        if si >= start and si < len(T) + start:
            ret.append(T[ti])
            ti += 1
        else:
            if s == '?':
                ret.append('a')
            else:
                ret.append(s)
    return ''.join(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Buggy submission (verdict: Runtime Error):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)

    start = None

    for ti in range(tn):
        t_c = T[ti]
        for si in range(ti, sn):
            s_c = S[si]
            if (tn - ti) > (sn - si):
                return "UNRESTORABLE"
            if t_c == s_c:
                sj = si - ti
                start = sj
                for tj in range(tn):
                    sj_c = S[sj]
                    tj_c = T[tj]
                    if not (tj_c == sj_c or sj_c == '?'):
                        start = None
                        break
                    sj += 1
                if start is not None:
                    created_s = []
                    tj = 0
                    for sj in range(sn):
                        sj_c = S[sj]
                        tj_c = T[tj]
                        if sj >= start and sj <= start + tn:
                            created_s.append(tj_c)
                            tj += 1
                        else:
                            if sj_c == '?':
                                created_s.append('a')
                            else:
                                created_s.append(sj_c)
                    return ''.join(created_s)
    return "UNRESTORABLE"


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)