Buggy python submission (verdict: Runtime Error):
import sys


def main():
    t = input()
    s = input()

    appear_pos = {}  # 文字が出てくる場所
    for idx, T in enumerate(t):
        if T not in appear_pos:
            appear_pos[T] = [idx]
        else:
            appear_pos[T].append(idx)

    search_idx = {}
    for key in appear_pos.keys():
        search_idx[key] = 0

    loop_count = 0
    find_idx = 0
    for S in s:
        if S not in appear_pos:
            print(-1)
            sys.exit()

        if len(appear_pos[S]) > search_idx[S]:
            idx_new = appear_pos[S][search_idx[S]]
        else:
            idx_new = appear_pos[S][search_idx[0]]
        search_idx[S] += 1

        if idx_new > find_idx:
            find_idx = idx_new
            continue

        # 初期化
        find_idx = idx_new
        loop_count += 1
        for key in appear_pos.keys():
            search_idx[key] = 0

    print(find_idx+loop_count*len(t)+1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def main():
    t = input()
    s = input()

    appear_pos = {}  # 文字が出てくる場所
    for idx, T in enumerate(t):
        if T not in appear_pos:
            appear_pos[T] = [idx]
        else:
            appear_pos[T].append(idx)

    search_idx = {}
    for key in appear_pos.keys():
        search_idx[key] = -1

    loop_count = 0
    find_idx = -1
    for S in s:
        if S not in appear_pos:
            print(-1)
            sys.exit()

        while True:
            search_idx[S] += 1
            if len(appear_pos[S]) == search_idx[S]:
                # 次のループに移動する
                loop_count += 1
                for key in appear_pos.keys():
                    search_idx[key] = -1
                find_idx = appear_pos[S][0]
                break

            idx_new = appear_pos[S][search_idx[S]]
            if idx_new > find_idx:
                find_idx = idx_new
                break

    print(find_idx+loop_count*len(t)+1)


if __name__ == '__main__':
    main()

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

    for T in t:
        if T not in s:
            print(-1)
            return

    for loop in range(10**100):
        for idx in range(len(s)):
            if s[idx] == t[-1]:
                t.pop()
                if len(t) == 0:
                    print(idx+1+loop*len(s))
                    return

    print(-1)


if __name__ == '__main__':
    main()

Fixed submission:
import sys


def main():
    t = input()
    s = input()

    appear_pos = {}  # 文字が出てくる場所
    for idx, T in enumerate(t):
        if T not in appear_pos:
            appear_pos[T] = [idx]
        else:
            appear_pos[T].append(idx)

    search_idx = {}
    for key in appear_pos.keys():
        search_idx[key] = -1

    loop_count = 0
    find_idx = -1
    for S in s:
        if S not in appear_pos:
            print(-1)
            sys.exit()

        while True:
            search_idx[S] += 1
            if len(appear_pos[S]) == search_idx[S]:
                # 次のループに移動する
                loop_count += 1
                for key in appear_pos.keys():
                    search_idx[key] = -1
                find_idx = appear_pos[S][0]
                break

            idx_new = appear_pos[S][search_idx[S]]
            if idx_new > find_idx:
                find_idx = idx_new
                break

    print(find_idx+loop_count*len(t)+1)


if __name__ == '__main__':
    main()

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

    for T in t:
        if T not in s:
            print(-1)
            return

    for loop in range(10**100):
        for idx in range(len(s)):
            if s[idx] == t[-1]:
                t.pop()
                if len(t) == 0:
                    print(idx+1+loop*len(s))
                    return

    print(-1)


if __name__ == '__main__':
    main()

Fixed submission:
import sys


def main():
    t = input()
    s = input()

    appear_pos = {}  # 文字が出てくる場所
    for idx, T in enumerate(t):
        if T not in appear_pos:
            appear_pos[T] = [idx]
        else:
            appear_pos[T].append(idx)

    search_idx = {}
    for key in appear_pos.keys():
        search_idx[key] = -1

    loop_count = 0
    find_idx = -1
    for S in s:
        if S not in appear_pos:
            print(-1)
            sys.exit()

        while True:
            search_idx[S] += 1
            if len(appear_pos[S]) == search_idx[S]:
                # 次のループに移動する
                loop_count += 1
                for key in appear_pos.keys():
                    search_idx[key] = -1
                find_idx = appear_pos[S][0]
                break

            idx_new = appear_pos[S][search_idx[S]]
            if idx_new > find_idx:
                find_idx = idx_new
                break

    print(find_idx+loop_count*len(t)+1)


if __name__ == '__main__':
    main()