Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = list(input())
    N = len(s)

    for tt in t:
        if tt not in s:
            ans = -1
            print(ans)
            exit()

    i = 0
    ans = 0
    r = s * 2
    while t:
        tt = t.pop(0)
        r = r[i::] + s
        cnt = 0
        for rr in r:
            cnt += 1
            if tt == rr:
                break
        ans += cnt
        i = cnt
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect


def search_alphabet_index(string):
    cs = [[] for i in range(26)]
    for i, s in enumerate(string):
        j = ord(s) - ord("a")
        cs[j].append(i)
    return cs


def main():
    S = input()
    T = input()
    N = len(S)

    cs = search_alphabet_index(S)

    for c in set(T):
        if not cs[ord(c) - ord("a")]:
            ans = -1
            print(ans)
            exit()

    rnd = 0
    k = -1
    for t in T:
        ti = ord(t) - ord("a")
        i = bisect(cs[ti], k)
        if i == len(cs[ti]):
            k = cs[ti][0]
            rnd += 1
        else:
            k = cs[ti][i]
    ans = rnd * N + k + 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = list(input())
    N = len(s)

    for tt in t:
        if tt not in s:
            ans = -1
            print(ans)
            exit()

    i = 0
    ans = 0
    r = s * 2
    while t:
        tt = t.pop(0)
        r = r[i::] + s
        for rr in r:
            if tt == rr:
                i = r.index(rr)
                break
        ans += (i + 1)
        i += 1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect


def search_alphabet_index(string):
    cs = [[] for i in range(26)]
    for i, s in enumerate(string):
        j = ord(s) - ord("a")
        cs[j].append(i)
    return cs


def main():
    S = input()
    T = input()
    N = len(S)

    cs = search_alphabet_index(S)

    for c in set(T):
        if not cs[ord(c) - ord("a")]:
            ans = -1
            print(ans)
            exit()

    rnd = 0
    k = -1
    for t in T:
        ti = ord(t) - ord("a")
        i = bisect(cs[ti], k)
        if i == len(cs[ti]):
            k = cs[ti][0]
            rnd += 1
        else:
            k = cs[ti][i]
    ans = rnd * N + k + 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = list(input())
    N = len(s)

    for tt in t:
        if tt not in s:
            ans = -1
            print(ans)
            exit()

    i = 0
    ans = 0
    r = s * 2
    while t:
        tt = t.pop(0)
        r = r[i::] + s
        for rr in r:
            if tt == rr:
                i = r.index(rr)
                break
        ans += (i + 1)
        i += 1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect


def search_alphabet_index(string):
    cs = [[] for i in range(26)]
    for i, s in enumerate(string):
        j = ord(s) - ord("a")
        cs[j].append(i)
    return cs


def main():
    S = input()
    T = input()
    N = len(S)

    cs = search_alphabet_index(S)

    for c in set(T):
        if not cs[ord(c) - ord("a")]:
            ans = -1
            print(ans)
            exit()

    rnd = 0
    k = -1
    for t in T:
        ti = ord(t) - ord("a")
        i = bisect(cs[ti], k)
        if i == len(cs[ti]):
            k = cs[ti][0]
            rnd += 1
        else:
            k = cs[ti][i]
    ans = rnd * N + k + 1
    print(ans)


if __name__ == "__main__":
    main()