Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import bisect

S = input()
T = input()

d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)

ans = 0
i = 0

for t in T:
    if not d[t]:
        print(-1)
        exit()

    if i > d[t][-1]:
        ans += len(S)
        i = 0
    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]

ans += i
print(ans)


Fixed submission:
import collections
import bisect
S = input()
T = input()
N = len(S)

d = collections.defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)

ans = 0
end = 0
isOK = True
i = 0

for t in T:
    if len(d[t]) == 0:
        isOK = False
        break
    dic = d[t]
    idx = bisect.bisect_right(dic, i)
    if len(dic) == idx:
        i = dic[0]
        end += 1
    else:
        i = dic[idx]

if isOK:
    ans = N * end + i
else:
    ans = -1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()


def search():
    pos=0
    now=S
    for t in T:
        if t in S:
            if not t in now:
                now+=S
            ind=now.index(t)+1
            now=now[ind:]

            pos+=ind
        else:
            return -1
    return pos

print(search())


Fixed submission:
import collections
import bisect
S = input()
T = input()
N = len(S)

d = collections.defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)

ans = 0
end = 0
isOK = True
i = 0

for t in T:
    if len(d[t]) == 0:
        isOK = False
        break
    dic = d[t]
    idx = bisect.bisect_right(dic, i)
    if len(dic) == idx:
        i = dic[0]
        end += 1
    else:
        i = dic[idx]

if isOK:
    ans = N * end + i
else:
    ans = -1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()

pos=0
now=""
for t in T:
    if t in S:
        if not t in now:
            now+=S
        ind=now.find(t)+1
        now=now[ind:]
        pos+=ind
    else:
        print(-1)
        exit()
else:
    print(pos)

Fixed submission:
import collections
import bisect
S = input()
T = input()
N = len(S)

d = collections.defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)

ans = 0
end = 0
isOK = True
i = 0

for t in T:
    if len(d[t]) == 0:
        isOK = False
        break
    dic = d[t]
    idx = bisect.bisect_right(dic, i)
    if len(dic) == idx:
        i = dic[0]
        end += 1
    else:
        i = dic[idx]

if isOK:
    ans = N * end + i
else:
    ans = -1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()


def search():
    pos=0
    now=""
    for t in T:
        if t in S:
            if not t in now:
                now+=S
            ind=now.index(t)+1
            now=now[ind:]
            pos+=ind
        else:
            return -1
    return pos

print(search())

Fixed submission:
import collections
import bisect
S = input()
T = input()
N = len(S)

d = collections.defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)

ans = 0
end = 0
isOK = True
i = 0

for t in T:
    if len(d[t]) == 0:
        isOK = False
        break
    dic = d[t]
    idx = bisect.bisect_right(dic, i)
    if len(dic) == idx:
        i = dic[0]
        end += 1
    else:
        i = dic[idx]

if isOK:
    ans = N * end + i
else:
    ans = -1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()


def search():
    pos=0
    now=""
    for i,t in enumerate(T):
        if t in S:
            if not t in now:
                now+=S
            ind=now.index(t)+1
            now=now[ind:]

            pos+=ind
        else:
            return -1
    return pos

print(search())

Fixed submission:
import collections
import bisect
S = input()
T = input()
N = len(S)

d = collections.defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)

ans = 0
end = 0
isOK = True
i = 0

for t in T:
    if len(d[t]) == 0:
        isOK = False
        break
    dic = d[t]
    idx = bisect.bisect_right(dic, i)
    if len(dic) == idx:
        i = dic[0]
        end += 1
    else:
        i = dic[idx]

if isOK:
    ans = N * end + i
else:
    ans = -1

print(ans)