import sys



ordA = ord('a')



ss = eval(input())

ts = eval(input())



lenS, lenT = len(ss), len(ts)



setS = set(ss)

for t in ts:

    if t not in setS:

        print((-1))

        sys.exit()



poss = [-1] * 26

for i, s in enumerate(ss):

    ch = ord(s)-ordA

    if poss[ch] == -1:

        poss[ch] = i + lenS



nextss = [[0]*(26) for _ in range(lenS)]

for i in reversed(list(range(lenS))):

    ch = ord(ss[i])-ordA

    poss[ch] = i

    for ch, pos in enumerate(poss):

        nextss[i][ch] = pos-i



i = 0

ans = 1

for t in ts:

    ch = ord(t)-ordA

    d = nextss[i][ch]

    ans += d+1

    i = (i+d+1) % lenS



print((ans-1))

import sys



numChar = 26

ordA = ord('a')



Ss = input().rstrip()

Ts = input().rstrip()



setS, setT = set(Ss), set(Ts)

for T in setT:

    if T not in setS:

        print((-1))

        sys.exit()



def getDistNextss(As, numChar):

    lenA = len(As)

    poss = [-1] * numChar

    for i, A in enumerate(As):

        if poss[A] == -1:

            poss[A] = i + lenA

    distNextss = [[0]*(numChar) for _ in range(lenA)]

    for i in reversed(list(range(lenA))):

        poss[As[i]] = i

        distNextss[i] = [pos-i for pos in poss]

    return distNextss



As = [ord(S)-ordA for S in Ss]

distNextss = getDistNextss(As, numChar)



lenS = len(Ss)

i = 0

for T in Ts:

    T = ord(T) - ordA

    i += distNextss[i%lenS][T]

    i += 1



print(i)

import sys

ordA = ord("a")
ss = eval(input())
ts = eval(input())
lenS, lenT = len(ss), len(ts)
setS = set(ss)
for t in ts:
    if t not in setS:
        print((-1))
        sys.exit()
poss = [-1] * 26
for i, s in enumerate(ss):
    ch = ord(s) - ordA
    if poss[ch] == -1:
        poss[ch] = i + lenS
nextss = [[0] * (26) for _ in range(lenS)]
for i in reversed(list(range(lenS))):
    ch = ord(ss[i]) - ordA
    poss[ch] = i
    for ch, pos in enumerate(poss):
        nextss[i][ch] = pos - i
i = 0
ans = 1
for t in ts:
    ch = ord(t) - ordA
    d = nextss[i][ch]
    ans += d + 1
    i = (i + d + 1) % lenS
print((ans - 1))

import sys

numChar = 26
ordA = ord("a")
Ss = input().rstrip()
Ts = input().rstrip()
setS, setT = set(Ss), set(Ts)
for T in setT:
    if T not in setS:
        print((-1))
        sys.exit()


def getDistNextss(As, numChar):
    lenA = len(As)
    poss = [-1] * numChar
    for i, A in enumerate(As):
        if poss[A] == -1:
            poss[A] = i + lenA
    distNextss = [[0] * (numChar) for _ in range(lenA)]
    for i in reversed(list(range(lenA))):
        poss[As[i]] = i
        distNextss[i] = [pos - i for pos in poss]
    return distNextss


As = [ord(S) - ordA for S in Ss]
distNextss = getDistNextss(As, numChar)
lenS = len(Ss)
i = 0
for T in Ts:
    T = ord(T) - ordA
    i += distNextss[i % lenS][T]
    i += 1
print(i)

+numChar = 26 -ss = eval(input()) -ts = eval(input()) -lenS, lenT = len(ss), len(ts) -setS = set(ss) -for t in ts: -    if t not in setS: +Ss = input().rstrip() +Ts = input().rstrip() +setS, setT = set(Ss), set(Ts) +for T in setT: +    if T not in setS: -poss = [-1] * 26 -for i, s in enumerate(ss): -    ch = ord(s) - ordA -    if poss[ch] == -1: -        poss[ch] = i + lenS -nextss = [[0] * (26) for _ in range(lenS)] -for i in reversed(list(range(lenS))): -    ch = ord(ss[i]) - ordA -    poss[ch] = i -    for ch, pos in enumerate(poss): -        nextss[i][ch] = pos - i + + +def getDistNextss(As, numChar): +    lenA = len(As) +    poss = [-1] * numChar +    for i, A in enumerate(As): +        if poss[A] == -1: +            poss[A] = i + lenA +    distNextss = [[0] * (numChar) for _ in range(lenA)] +    for i in reversed(list(range(lenA))): +        poss[As[i]] = i +        distNextss[i] = [pos - i for pos in poss] +    return distNextss + + +As = [ord(S) - ordA for S in Ss] +distNextss = getDistNextss(As, numChar) +lenS = len(Ss) -ans = 1 -for t in ts: -    ch = ord(t) - ordA -    d = nextss[i][ch] -    ans += d + 1 -    i = (i + d + 1) % lenS -print((ans - 1)) +for T in Ts: +    T = ord(T) - ordA +    i += distNextss[i % lenS][T] +    i += 1 +print(i)