Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
else:
    l = i+1
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
    if d:
        if d[-1] > ind:
    #    print("c=",c,"d=",d)
            for i in d: #iは各文字のindex 昇順
        #        print("i=",i)
                if ind < i: #もし現在位置<iなら
                    ind = i
        #            print("found, ind=",i)
                    break
        else:
    #        print("not found")
            cnt += 1
            ind = d[0]
    else:
        ans = -1
        break

print(cnt*l+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
else:
    l = i+1
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
    if d:
        if d[-1] > i:
    #    print("c=",c,"d=",d)
        for i in d: #iは各文字のindex 昇順
    #        print("i=",i)
            if ind < i: #もし現在位置<iなら
                ind = i
    #            print("found, ind=",i)
                break
        else:
    #        print("not found")
            cnt += 1
            ind = d[0]
    else:
        ans = -1
        break
        
print(cnt*l+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
#    print("c=",c,"d=",d)
    for i in d: #iは各文字のindex 昇順
#        print("i=",i)
        if ind < i: #もし現在位置<iなら
            ind = i
#            print("found, ind=",i)
            break
    else:
#        print("not found")
        cnt += 1
        if d:
            ind = d[0]
        else:
#            print("!!!!!!!!!!!!!")
            ans = -1
            break
print(cnt*len(s)+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
#    print("c=",c,"d=",d)
    for i in d: #iは各文字のindex 昇順
#        print("i=",i)
        if ind < i: #もし現在位置<iなら
            ind = i
#            print("found, ind=",i)
            break
    else:
#        print("not found")
        cnt += 1
        if d:
            ind = d[0]
        else:
#            print("!!!!!!!!!!!!!")
            ans = -1
            break
print(cnt*len(s)+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
#    print("c=",c,"d=",d)
    for i in d: #iは各文字のindex 昇順
#        print("i=",i)
        if ind < i: #もし現在位置<iなら
            ind = i
#            print("found, ind=",i)
            break
    else:
#        print("not found")
        cnt += 1
        ind = -1
        # もう一度
        for j in d :  # jは各文字のindex 昇順
#            print("2周目i=", i)
            if ind < j :  # もし現在位置<iなら
                ind = j
#                print("2周目found, ind=", j)
                break
        else:
#            print("!!!!!!!!!!!!!")
            ans = -1
            break
print(cnt*len(s)+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
#    print("c=",c,"d=",d)
    for i in d: #iは各文字のindex 昇順
#        print("i=",i)
        if ind < i: #もし現在位置<iなら
            ind = i
#            print("found, ind=",i)
            break
    else:
#        print("not found")
        cnt += 1
        ind = -1
        # もう一度
        for j in d :  # jは各文字のindex 昇順
#            print("2周目i=", i)
            if ind < j :  # もし現在位置<iなら
                ind = j
#                print("2周目found, ind=", j)
                break
        else:
#            print("!!!!!!!!!!!!!")
            ans = -1
            break
print(cnt*len(s)+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
#    print("c=",c,"d=",d)
    for i in d: #iは各文字のindex 昇順
#        print("i=",i)
        if ind < i: #もし現在位置<iなら
            ind = i
#            print("found, ind=",i)
            break
    else:
#        print("not found")
        cnt += 1
        ind = -1
        # もう一度
        for j in d :  # jは各文字のindex 昇順
#            print("2周目i=", i)
            if ind < j :  # もし現在位置<iなら
                ind = j
#                print("2周目found, ind=", j)
                break
        else:
#            print("!!!!!!!!!!!!!")
            ans = -1
            break
print(cnt*len(s)+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s = input()[:-1]
t = input()
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
#    print("c=",c,"d=",d)
    for i in d: #iは各文字のindex 昇順
#        print("i=",i)
        if ind < i: #もし現在位置<iなら
            ind = i
#            print("found, ind=",i)
            break
    else:
#        print("not found")
        cnt += 1
        ind = -1
        # もう一度
        for j in d :  # jは各文字のindex 昇順
#            print("2周目i=", i)
            if ind < j :  # もし現在位置<iなら
                ind = j
#                print("2周目found, ind=", j)
                break
        else:
#            print("!!!!!!!!!!!!!")
            ans = -1
            break
print(cnt*len(s)+ind+1 if ans > -1 else -1)


Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)