Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input()

    Slen = len(s)
    Index = -1
    Loop = 0
    LUT = [[] for i in range(26)]
    Cur = [0 for i in range(26)]

    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LUT[v].append(i)

    for c in t:
        v = ord(c) - ord('a')
        l = len(LUT[v])
        if l == 0:
            print(-1)
            return

    for c in t:
        v = ord(c) - ord('a')
        l = len(LUT[v])
        b = -1
        for a in range(Cur[v],l):
            if LUT[v][a] > Index:
                b = a
                break
        if b < 0:
            Loop += 1
            Cur = [0 for i in range(26)]
            b = 0
        Index = LUT[v][b]

    print(Loop*Slen+Index+1)


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input().splitlines()[0]

    Slen = len(s)

    LookupTable = [[] for i in range(26)]
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LookupTable[v].append(i)
    for i in range(26):
        LookupTable[i].append(-1)
        
    IndexTable = [0 for i in range(26)]
    NextTable = []
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        IndexTable[v] += 1
        if LookupTable[v][IndexTable[v]] < 0:
            IndexTable[v] = 0

    Index = 0
    Loop = 0
    for i, c in enumerate(t):
        v = ord(c) - ord('a')
        if NextTable[Index][v] < Index:
            Loop += 1
        Index = NextTable[Index][v]
        if Index < 0:
            print(-1)
            return
        Index += 1
        if Index >= Slen:
            Index = 0
            Loop += 1

    print(Loop*Slen+Index)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

s = input().splitlines()[0]
t = input()

Slen = len(s)
Index = -1
Loop = 0
LUT = [[] for i in range(26)]
Cur = [0 for i in range(26)]
for i, c in enumerate(s):
    v = ord(c) - ord('a')
    LUT[v].append(i)

NotFound = False
for c in t:
    v = ord(c) - ord('a')
    l = len(LUT[v])
    if l == 0:
        NotFound = True
        break
    if LUT[v][Cur[v]] > Index:
        Index = LUT[v][Cur[v]]
        Cur[v] += 1
        if Cur[v] >= l:
            Cur[v] = 0
    else:    
        Index = LUT[v][0]
        for i in range(26):
            Cur[i] = 0
            if len(LUT[i]) > 0:
                for j,k in enumerate(LUT[i]):
                    if k <= Index:
                        Cur[i] = j
        Loop += 1

if NotFound:
    print(-1)
else:
    print(Loop*Slen+Index+1)


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input().splitlines()[0]

    Slen = len(s)

    LookupTable = [[] for i in range(26)]
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LookupTable[v].append(i)
    for i in range(26):
        LookupTable[i].append(-1)
        
    IndexTable = [0 for i in range(26)]
    NextTable = []
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        IndexTable[v] += 1
        if LookupTable[v][IndexTable[v]] < 0:
            IndexTable[v] = 0

    Index = 0
    Loop = 0
    for i, c in enumerate(t):
        v = ord(c) - ord('a')
        if NextTable[Index][v] < Index:
            Loop += 1
        Index = NextTable[Index][v]
        if Index < 0:
            print(-1)
            return
        Index += 1
        if Index >= Slen:
            Index = 0
            Loop += 1

    print(Loop*Slen+Index)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


s = input().splitlines()[0]
t = input()


Slen = len(s)
Index = -1
Loop = 0
LUT = [[] for i in range(26)]
for i, c in enumerate(s):
    v = ord(c) - ord('a')
    LUT[v].append(i)

NotFound = False
for c in t:
    v = ord(c) - ord('a')
    if len(LUT[v]) == 0:
        NotFound = True
        break
    m = -1
    for l in LUT[v]:
        if l > Index:
            m = l
            break
    if m < 0:
        Index = LUT[v][0]
        Loop += 1
    else:
        Index = m

if NotFound:
    print(-1)
else:
    print(Loop*Slen+Index+1)


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input().splitlines()[0]

    Slen = len(s)

    LookupTable = [[] for i in range(26)]
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LookupTable[v].append(i)
    for i in range(26):
        LookupTable[i].append(-1)
        
    IndexTable = [0 for i in range(26)]
    NextTable = []
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        IndexTable[v] += 1
        if LookupTable[v][IndexTable[v]] < 0:
            IndexTable[v] = 0

    Index = 0
    Loop = 0
    for i, c in enumerate(t):
        v = ord(c) - ord('a')
        if NextTable[Index][v] < Index:
            Loop += 1
        Index = NextTable[Index][v]
        if Index < 0:
            print(-1)
            return
        Index += 1
        if Index >= Slen:
            Index = 0
            Loop += 1

    print(Loop*Slen+Index)


if __name__ == "__main__":
    main()