S = list(str(eval(input())))

T = list(str(eval(input())))



S_ = set(list(S))

T_ = set(list(T))

for c in T:

    if c not in S_:

        print((-1))

        exit()



d = [[] for _ in range(26)]

for i, s in enumerate(S):

    d[ord(s)-ord('a')].append(i)

#print(d)



q = 0

pre = -1

import bisect

for t in T:

    j = ord(t)-ord('a')

    idx = bisect.bisect_right(d[j], pre)

    if idx == len(d[j]):

        q += 1

        pre = d[j][0]

    else:

        pre = d[j][idx]

print((q*len(S)+pre+1))

s = list(str(eval(input())))

t = list(str(eval(input())))



X = [[] for _ in range(26)]

for i, c in enumerate(s):

    j = ord(c)-ord('a')

    X[j].append(i)



n = len(s)

q = 0

r = -1

import bisect

for c in t:

    j = ord(c)-ord('a')

    if len(X[j]) == 0:

        print((-1))

        exit()

    idx = bisect.bisect_right(X[j], r)

    #print(X[j], idx)

    if idx == len(X[j]):

        q += 1

        r = X[j][0]

    else:

        r = X[j][idx]

    #print(q, r)

ans = q*n + r+1

print(ans)

S = list(str(eval(input())))
T = list(str(eval(input())))
S_ = set(list(S))
T_ = set(list(T))
for c in T:
    if c not in S_:
        print((-1))
        exit()
d = [[] for _ in range(26)]
for i, s in enumerate(S):
    d[ord(s) - ord("a")].append(i)
# print(d)
q = 0
pre = -1
import bisect

for t in T:
    j = ord(t) - ord("a")
    idx = bisect.bisect_right(d[j], pre)
    if idx == len(d[j]):
        q += 1
        pre = d[j][0]
    else:
        pre = d[j][idx]
print((q * len(S) + pre + 1))

s = list(str(eval(input())))
t = list(str(eval(input())))
X = [[] for _ in range(26)]
for i, c in enumerate(s):
    j = ord(c) - ord("a")
    X[j].append(i)
n = len(s)
q = 0
r = -1
import bisect

for c in t:
    j = ord(c) - ord("a")
    if len(X[j]) == 0:
        print((-1))
        exit()
    idx = bisect.bisect_right(X[j], r)
    # print(X[j], idx)
    if idx == len(X[j]):
        q += 1
        r = X[j][0]
    else:
        r = X[j][idx]
    # print(q, r)
ans = q * n + r + 1
print(ans)

-S = list(str(eval(input()))) -T = list(str(eval(input()))) -S_ = set(list(S)) -T_ = set(list(T)) -for c in T: -    if c not in S_: +s = list(str(eval(input()))) +t = list(str(eval(input()))) +X = [[] for _ in range(26)] +for i, c in enumerate(s): +    j = ord(c) - ord("a") +    X[j].append(i) +n = len(s) +q = 0 +r = -1 +import bisect + +for c in t: +    j = ord(c) - ord("a") +    if len(X[j]) == 0: -d = [[] for _ in range(26)] -for i, s in enumerate(S): -    d[ord(s) - ord("a")].append(i) -# print(d) -q = 0 -pre = -1 -import bisect - -for t in T: -    j = ord(t) - ord("a") -    idx = bisect.bisect_right(d[j], pre) -    if idx == len(d[j]): +    idx = bisect.bisect_right(X[j], r) +    # print(X[j], idx) +    if idx == len(X[j]): -        pre = d[j][0] +        r = X[j][0] -        pre = d[j][idx] -print((q * len(S) + pre + 1)) +        r = X[j][idx] +    # print(q, r) +ans = q * n + r + 1 +print(ans)