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


s, t = input(), input()

if not all(i in s for i in t):
    print(-1)
    exit()

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

ans, cnt = 1 - len(s), 0
for i in t:
    l = alp[i]
    ans += len(s) * (cnt == 0)
    num = bisect(l, cnt)
    ans += len(s) * (num == len(l))
    cnt = (l[num % len(l)] + 1) % len(s)
print(ans + (cnt - 1) % len(s))


Fixed submission:
from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

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

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)

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

s, t = input(), input()
lens = len(s)


def index(I, CNT, ANS):
    LIST = alp[ord(I) - 97]
    NUM = bisect(LIST, CNT)
    ANS += (NUM == len(LIST)) * lens
    CNT = (LIST[NUM % len(LIST)] + 1) % lens
    return ANS, CNT

if not all(i in s for i in t):
    print(-1)
    exit()

alp = [[] for i in range(26)]
for i, si in enumerate(s):
    alp[ord(si) - 97].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    ans += (cnt == 0) * lens
    ans, cnt = index(i, cnt, ans)
print(ans + (cnt - 1) % lens)


Fixed submission:
from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

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

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)

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

def index(I, CNT, ANS):
    LIST = alp[ord(I) - 97]
    NUM = bisect(LIST, CNT)
    ANS += (NUM == len(LIST)) * len(s)
    CNT = (LIST[NUM % len(LIST)] + 1) % len(s)
    return ANS, CNT

s, t = input(), input()

if not all(i in s for i in t):
    print(-1)
    exit()

alp = [[] for i in range(26)]
for i, si in enumerate(s):
    alp[ord(si) - 97].append(i)

ans, cnt = 1 - len(s), 0
for i in t:
    ans += (cnt == 0) * len(s)
    ans, cnt = index(i, cnt, ans)
print(ans + (cnt - 1) % len(s))


Fixed submission:
from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

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

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)

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

if not all(i in s for i in t):
    print(-1)
    exit()

lens = len(s)
ans, cnt = 1 - lens, 0
for i in t:
    ans += (cnt == 0) * lens
    if i in s[cnt:]:
        cnt = (cnt + s[cnt:].index(i) + 1) % lens
    else:
        ans += lens
        cnt = (s.index(i) + 1) % lens
print(ans + (cnt - 1) % lens)


Fixed submission:
from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

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

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)