Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

s = input()
t = input()
n = len(s)

dict_s = {}
for i, c in enumerate(s * 2):
    dict_s[c] = dict_s.get(c, []) + [i]


dict_next_i = {
    c: [dict_s[c][bisect_left(dict_s[c], i + 1)] for i in range(n)] for c in dict_s.keys()
}


def next_i(i, c):
    if c not in dict_s.keys():
        return -1
    else:
        return n * (i // n) + dict_next_i[c][i % n]


def answer():
    i = -1
    for c in t:
        i = next_i(i, c)
        if i == -1:
            return -1
    return i + 1  # 1-origin


print(answer())


Fixed submission:
from bisect import bisect_left
from string import ascii_lowercase

s = input()
t = input()
n = len(s)

dict_s = {c: [] for c in ascii_lowercase}
for i, c in enumerate(s * 2):
    dict_s[c].append(i)

for c in ascii_lowercase:
    if not dict_s[c]:
        del dict_s[c]


dict_next_i = {
    c: [dict_s[c][bisect_left(dict_s[c], i + 1)] for i in range(n)]
    for c in dict_s.keys()
}


def next_i(i, c):
    return n * (i // n) + dict_next_i[c][i % n]


def answer():
    if not all(c in s for c in t):
        return -1
    i = -1
    for c in t:
        i = next_i(i, c)
    return i + 1  # 1-origin


print(answer())

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
n = len(s)

dict_s = {}
for i, c in enumerate(s * 2):
    dict_s[c] = dict_s.get(c, []) + [i]


# dict_next_i = {
#     c: [min(j for j in dict_s[c] if j > i) for i in range(n)] for c in dict_s.keys()
# }
dict_next_i = {c: [None] * n for c in dict_s.keys()}

for c in dict_s.keys():
    for i in range(n):
        for j in dict_s[c]:
            if j > i:
                dict_next_i[c][i] = j
                break


def next_i(i, c):
    if c not in dict_s.keys():
        return -1
    else:
        return n * (i // n) + dict_next_i[c][i % n]


def answer():
    i = -1
    for c in t:
        i = next_i(i, c)
        if i == -1:
            return -1
    return i + 1  # 1-origin


print(answer())


Fixed submission:
from bisect import bisect_left
from string import ascii_lowercase

s = input()
t = input()
n = len(s)

dict_s = {c: [] for c in ascii_lowercase}
for i, c in enumerate(s * 2):
    dict_s[c].append(i)

for c in ascii_lowercase:
    if not dict_s[c]:
        del dict_s[c]


dict_next_i = {
    c: [dict_s[c][bisect_left(dict_s[c], i + 1)] for i in range(n)]
    for c in dict_s.keys()
}


def next_i(i, c):
    return n * (i // n) + dict_next_i[c][i % n]


def answer():
    if not all(c in s for c in t):
        return -1
    i = -1
    for c in t:
        i = next_i(i, c)
    return i + 1  # 1-origin


print(answer())

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
n = len(s)

dict_s = {}
for i, c in enumerate(s * 2):
    dict_s[c] = dict_s.get(c, []) + [i]


# dict_next_i = {
#     c: [min(j for j in dict_s[c] if j > i) for i in range(n)] for c in dict_s.keys()
# }
dict_next_i = {c: [None] * n for c in dict_s.keys()}

for c in dict_s.keys():
    for i in range(n):
        for j in dict_s[c]:
            if j > i:
                dict_next_i[c][i] = j
                break


def next_i(i, c):
    if c not in dict_s.keys():
        return -1
    else:
        return n * (i // n) + dict_next_i[c][i % n]


def answer():
    i = -1
    for c in t:
        i = next_i(i, c)
        if i == -1:
            return -1
    return i + 1  # 1-origin


print(answer())


Fixed submission:
from bisect import bisect_left
from string import ascii_lowercase

s = input()
t = input()
n = len(s)

dict_s = {c: [] for c in ascii_lowercase}
for i, c in enumerate(s * 2):
    dict_s[c].append(i)

for c in ascii_lowercase:
    if not dict_s[c]:
        del dict_s[c]


dict_next_i = {
    c: [dict_s[c][bisect_left(dict_s[c], i + 1)] for i in range(n)]
    for c in dict_s.keys()
}


def next_i(i, c):
    return n * (i // n) + dict_next_i[c][i % n]


def answer():
    if not all(c in s for c in t):
        return -1
    i = -1
    for c in t:
        i = next_i(i, c)
    return i + 1  # 1-origin


print(answer())