Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
    input = sys.stdin.readline
    s = input()[:-1]
    t = input()[:-1]
#    S = "abcdefghijklmnopqrstuvwxyz"
    A = [[] for k in range(26)]
    for k in range(len(s)):
        A[ord(s[k])-97] += [k+1]
    ans = 0
    now = 0
    for k in range(len(t)):
        a = ord(t[k]) - 97
        if len(A[a]) == 0:
            print(-1)
            exit(0)
        if A[a][-1] <= now:
            ans += len(s)
            now = A[a][0]
        else:
            for l in range(len(A[a])):
    #            print(A[S.index(t[k])][l]>now)
                if A[a][l] > now:
                    now = A[a][l]
                    break
    print(ans+now)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from bisect import bisect_right as bisect
def main():
    input = sys.stdin.readline
    s = input()[:-1]
    t = input()[:-1]
#    S = "abcdefghijklmnopqrstuvwxyz"
    A = [[] for k in range(26)]
    for k in range(len(s)):
        A[ord(s[k])-97] += [k+1]
    ans = 0
    now = 0
    for k in range(len(t)):
        a = ord(t[k]) - 97
        if len(A[a]) == 0:
            print(-1)
            exit(0)
        if A[a][-1] <= now:
            ans += len(s)
            now = A[a][0]
        else:
            now = A[a][bisect(A[a],now)]
    print(ans+now)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
def main():
    input = sys.stdin.readline
    s = input()[:-1]
    t = input()[:-1]
    S = "abcdefghijklmnopqrstuvwxyz"
    A = [[] for k in range(26)]
    for k in range(len(s)):
        A[S.index(s[k])].append(k+1)
    ans = 0
    now = 0
    for k in range(len(t)):
        a = S.index(t[k])
        if len(A[a]) == 0:
            print(-1)
            exit(0)
        if A[a][-1] <= now:
            ans += len(s)
            now = A[a][0]
        else:
            for l in range(len(A[a])):
    #            print(A[S.index(t[k])][l]>now)
                if A[a][l] > now:
                    now = A[a][l]
                    break
    print(ans+now)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from bisect import bisect_right as bisect
def main():
    input = sys.stdin.readline
    s = input()[:-1]
    t = input()[:-1]
#    S = "abcdefghijklmnopqrstuvwxyz"
    A = [[] for k in range(26)]
    for k in range(len(s)):
        A[ord(s[k])-97] += [k+1]
    ans = 0
    now = 0
    for k in range(len(t)):
        a = ord(t[k]) - 97
        if len(A[a]) == 0:
            print(-1)
            exit(0)
        if A[a][-1] <= now:
            ans += len(s)
            now = A[a][0]
        else:
            now = A[a][bisect(A[a],now)]
    print(ans+now)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
def main():
    input = sys.stdin.readline
    s = input()[:-1]
    t = input()[:-1]
    S = "abcdefghijklmnopqrstuvwxyz"
    A = [[] for k in range(26)]
    for k in range(len(s)):
        A[S.index(s[k])].append(k+1)
    ans = 0
    now = 0
    for k in range(len(t)):
        if len(A[S.index(t[k])]) == 0:
            print(-1)
            exit(0)
        if max(A[S.index(t[k])]) <= now:
            ans += len(s)
            now = min(A[S.index(t[k])])
        else:
            for l in range(len(A[S.index(t[k])])):
    #            print(A[S.index(t[k])][l]>now)
                if A[S.index(t[k])][l] > now:
                    now = A[S.index(t[k])][l]
                    break
    print(ans+now)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from bisect import bisect_right as bisect
def main():
    input = sys.stdin.readline
    s = input()[:-1]
    t = input()[:-1]
#    S = "abcdefghijklmnopqrstuvwxyz"
    A = [[] for k in range(26)]
    for k in range(len(s)):
        A[ord(s[k])-97] += [k+1]
    ans = 0
    now = 0
    for k in range(len(t)):
        a = ord(t[k]) - 97
        if len(A[a]) == 0:
            print(-1)
            exit(0)
        if A[a][-1] <= now:
            ans += len(s)
            now = A[a][0]
        else:
            now = A[a][bisect(A[a],now)]
    print(ans+now)

if __name__ == '__main__':
    main()

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

S = "abcdefghijklmnopqrstuvwxyz"

A = [[] for k in range(26)]
for k in range(len(s)):
    A[S.index(s[k])].append(k+1)

ans = 0
now = 0
for k in range(len(t)):
    if len(A[S.index(t[k])]) == 0:
        print(-1)
        exit(0)
    if max(A[S.index(t[k])]) <= now:
        ans += len(s)
        now = min(A[S.index(t[k])])
    else:
        for l in range(len(A[S.index(t[k])])):
#            print(A[S.index(t[k])][l]>now)
            if A[S.index(t[k])][l] > now:
                now = A[S.index(t[k])][l]
                break
print(ans+now)


Fixed submission:
import sys
from bisect import bisect_right as bisect
def main():
    input = sys.stdin.readline
    s = input()[:-1]
    t = input()[:-1]
#    S = "abcdefghijklmnopqrstuvwxyz"
    A = [[] for k in range(26)]
    for k in range(len(s)):
        A[ord(s[k])-97] += [k+1]
    ans = 0
    now = 0
    for k in range(len(t)):
        a = ord(t[k]) - 97
        if len(A[a]) == 0:
            print(-1)
            exit(0)
        if A[a][-1] <= now:
            ans += len(s)
            now = A[a][0]
        else:
            now = A[a][bisect(A[a],now)]
    print(ans+now)

if __name__ == '__main__':
    main()