Buggy python submission (verdict: Time Limit Exceeded):
import bisect
S=list(input())
T=list(input())
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in set(T):
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

Fixed submission:
import bisect
S=list(input())
T=list(input())
sT=set(T)
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in sT:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
S=list(input())
T=list(input())
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in T:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

Fixed submission:
import bisect
S=list(input())
T=list(input())
sT=set(T)
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in sT:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
S=list(input())
T=list(input())
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in T:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

Fixed submission:
import bisect
S=list(input())
T=list(input())
sT=set(T)
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in sT:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

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

i=-1
for t in T:
  if t in set(S[(i+1)%N:]):
    i+=S[(i+1)%N:].index(t)+1
  elif t in set(S[:(i+1)%N]):
    i+=N-1-i%N+S.index(t)+1
  else:
    print(-1)
    exit()

print(i+1)

Fixed submission:
import bisect
S=list(input())
T=list(input())
sT=set(T)
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in sT:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

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

i=-1
for t in T:
  if t in set(S[(i+1)%N:]):
    i+=S[(i+1)%N:].index(t)+1
  elif t in set(S[:(i+1)%N]):
    i+=len(S[(i+1)%N:])+S.index(t)+1
  else:
    print(-1)
    exit()

print(i+1)


Fixed submission:
import bisect
S=list(input())
T=list(input())
sT=set(T)
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in sT:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)

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

i=-1
for t in T:
  if t in set(S[(i+1)%N:]):
    i+=S[(i+1)%N:].index(t)+1
  elif t in set(S[:(i+1)%N]):
    i+=len(S[(i+1)%N:])+S.index(t)+1
  else:
    print(-1)
    exit()
print(i+1)

Fixed submission:
import bisect
S=list(input())
T=list(input())
sT=set(T)
N=len(S)
TI={}
for i in range(N):
  s=S[i]
  if s in sT:
    if s in TI:
      TI[s].append(i)
    else:
      TI[s]=[i]

i=-1
for t in T:
  if t not in TI:
    print(-1)
    exit()
  else:
    ni=TI[t][(bisect.bisect_right(TI[t],i%N))%len(TI[t])]
    if ni>i%N:
      i+=ni-i%N
    else:
      i+=N-i%N+ni
print(i+1)