Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()

for ch in t:
    if ch not in s:
        print("-1")
        exit()

indices = defaultdict(list)
for i, v in enumerate(s):
    indices[v].append(i)

cnt = 0
cur = -1
mod = len(s)
for v in t:

    i = bisect_right(indices[v], cur)
    if i == len(indices[v]):
        j = indices[v][0]
    else:
        j = indices[v][i]

    if cur >= j:
        cnt += 1
    cur = j
print(cnt * mod + cur + 1)

Fixed submission:
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# Tの文字はSに出ていないといけない
for v in T:
    if v not in iS:
        print(-1)
        exit()

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[v], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)

Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Tの文字はSに出ていないといけない
for ch in T:
    if ch not in S:
        print("-1")
        exit()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[ch], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)

Fixed submission:
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# Tの文字はSに出ていないといけない
for v in T:
    if v not in iS:
        print(-1)
        exit()

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[v], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)

Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Tの文字はSに出ていないといけない
for ch in T:
    if ch not in S:
        print("-1")
        exit()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[ch], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)

Fixed submission:
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# Tの文字はSに出ていないといけない
for v in T:
    if v not in iS:
        print(-1)
        exit()

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[v], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)