Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

s = [None] + list(input().rstrip("\n"))
len_s = len(s[1:])
t = list(input().rstrip("\n"))
len_t = len(t)

# s'からtが作れない場合
if (set(s[1:]) & set(t)) != set(t):
    print(-1)
    exit()

for i,x in enumerate(t):
    if i == len_t-1:
        tmp = [j for j,y in enumerate(s) if y == t[-1] and j > t[-2]]
        if tmp:
            t[i] = tmp[0]
        else:
            t[i] = s.index(x)
        break
    else:
        t[i] = s.index(x)

answer = 0
for i in range(len_t):
    if i == len_t-1:
        answer += t[-1]
        break
    if t[i] < t[i+1]:
        continue
    else:
        answer += len_s
    if answer > 10**100 * len_s:
        print(-1)
        exit()

if 1 <= answer <= 10**100 * len_s:
    print(answer)
else:
    print(-1)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from bisect import bisect_left


s = input().rstrip("\n")
len_s = len(s)
t = input().rstrip("\n")
len_t = len(t)

alpha = defaultdict(list)
for i in range(len_s):
    alpha[s[i]].append(i)

if not alpha[t[0]]:
    print(-1)
    exit()
else:
    now_index = alpha[t[0]][0]
    answer = now_index + 1

# O(|t|)
for i in range(1,len_t):
    index = alpha[t[i]]
    if not index:
        print(-1)
        exit()
    # O(log(index))
    next_index = bisect_left(index, now_index+1)
    # s[now_index+1:]にt[i]がある場合
    if next_index < len(index):
        answer += index[next_index] - now_index
        now_index = index[next_index]
    else:
        answer += (len_s -1) - now_index + (index[0] + 1)
        now_index = index[0]

print(answer)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = [None] + list(input().rstrip("\n"))
len_s = len(s[1:])
t = list(input().rstrip("\n"))

if (set(s[1:]) & set(t)) != set(t):
    print(-1)
    exit()

for i,x in enumerate(t):
    if i == len(t)-1:
        last = [i for i,x in enumerate(s) if x == t[-1] and i > t[-2]]
        if last:
            t[-1] = last[-1]
        else:
            t[i] = s.index(x)
        break

    t[i] = s.index(x)

answer = 0
for i in range(len(t)):
    if i == len(t)-1:
        answer += t[-1]
        break

    if t[i] < t[i+1]:
        continue
    else:
        answer += len_s

print(answer)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from bisect import bisect_left


s = input().rstrip("\n")
len_s = len(s)
t = input().rstrip("\n")
len_t = len(t)

alpha = defaultdict(list)
for i in range(len_s):
    alpha[s[i]].append(i)

if not alpha[t[0]]:
    print(-1)
    exit()
else:
    now_index = alpha[t[0]][0]
    answer = now_index + 1

# O(|t|)
for i in range(1,len_t):
    index = alpha[t[i]]
    if not index:
        print(-1)
        exit()
    # O(log(index))
    next_index = bisect_left(index, now_index+1)
    # s[now_index+1:]にt[i]がある場合
    if next_index < len(index):
        answer += index[next_index] - now_index
        now_index = index[next_index]
    else:
        answer += (len_s -1) - now_index + (index[0] + 1)
        now_index = index[0]

print(answer)