Problem:


Score : 500 points

Problem Statement

Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists.

Let s' be the concatenation of 10^{100} copies of s. t is a subsequence of the string {s'}_1{s'}_2\ldots{s'}_i (the first i characters in s').

Notes

A subsequence of a string a is a string obtained by deleting zero or more characters from a and concatenating the remaining characters without changing the relative order. For example, the subsequences of contest include net, c, and contest.

Constraints

1 \leq |s| \leq 10^5

1 \leq |t| \leq 10^5

s and t consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

If there exists an integer i satisfying the following condition, print the minimum such i; otherwise, print -1.

Sample Input 1

contest
son

Sample Output 1

10

t = son is a subsequence of the string contestcon (the first 10 characters in s' = contestcontestcontest...), so i = 10 satisfies the condition.

On the other hand, t is not a subsequence of the string contestco (the first 9 characters in s'), so i = 9 does not satisfy the condition.

Similarly, any integer less than 9 does not satisfy the condition, either. Thus, the minimum integer i satisfying the condition is 10.

Sample Input 2

contest
programming

Sample Output 2

-1

t = programming is not a substring of s' = contestcontestcontest.... Thus, there is no integer i satisfying the condition.

Sample Input 3

contest
sentence

Sample Output 3

33

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.



Sample input:
contest
son


Sample output:
10

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import sys
import bisect
sys.setrecursionlimit(10000000)

def main():
    s = input()
    t = input()
    alphabets = dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"), None)
    # alphabets = alphabet.copy()
    for key_ in alphabets:
        lists = []
        for i in range(len(s)):
            if key_ == s[i]:
                lists.append(i)
        alphabets[key_] = lists
    # print(alphabets)
    now = -1
    count = 0
    for alpha in t:
        if alphabets[alpha] is None:
            print(-1)
            sys.exit()
        else:
            lists = alphabets[alpha]
            index = bisect.bisect_left(lists, now)
            if index >= len(lists):
                now = -1
                count += len(s)
                index = bisect.bisect_left(lists, now)
                now = lists[index]
            else:
                now = lists[index]
            # print(now, count)
    print(count + now + 1)
            







if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()
t = input()

N = len(s)

tN = len(t)


def alpha_index(c):
    return ord(c) - ord("a")


# 次の特定の文字が何文字先にあるか
next_string = np.zeros(N, 26)


def sarch_char(nowindex, c):
    if next_string[nowindex, alpha_index(c)] != 0:
        return next_string[nowindex, alpha_index(c)]
    else:
        for i in range(1, N):
            if s[(i + nowindex) % N] == c:
                next_string[nowindex, alpha_index(c)] = i
                return i
        next_string[nowindex, alpha_index(c)] = -1
        return -1


if not t[0] in s:
    print(-1)
    exit()

ans = s.find(t[0])
index = ans

for i in range(1, tN):
    nextindex = sarch_char(index, t[i])
    if nextindex == -1:
        print(-1)
        exit()
    ans += nextindex
    index = int(ans % N)

print(ans + 1)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
if len(t)==1:
  try:
    print(s.index(t)+1)
  except ValueError:
    print(-1)
    exit()
else:
  cd=0
  l=list()
  for _ in list(t):
    l.append([i for i,x in enumerate(list(s)) if x==_])
  try:
    ed=l[0][0]
  except IndexError:
    print(-1)
    exit()
  for i in range(len(t))[1:]:
    k=l[i]
    if k==[]:
      print(-1)
      exit()
    if max(k+[ed])==ed :
      cd+=1
      if i==len(t)-1:
        print((cd)*len(s)+ed+1)
        exit()
      else:
        ed=min(k)
    else:
      ex=list(sorted(k+[ed])).index(ed)
      ed=k[ex]
print((cd)*len(s)+ed+1)

Submission status: Runtime Error

Solution code:
s = input()
t = input()

len_s = len(s)
dp = [[-1 for _ in range(len_s)] for _ in range(26)]
# dp[i][j] = いまsのj文字目にいる。次に探しているのはアルファベットのi文字目であるとき、次までの必要文字数。
# print(len(dp))
# print(len(dp[0]))

for idx in range(len_s):

	ch = s[idx]
	i = ord(ch)-ord("a")
#	for j in range(len_s):
	if dp[i][0] == -1:
		dp[i] = [idx] * len_s
	else:
		temp = dp[i][j]
		dp[i][temp+1:idx] = idx

ans = 0
j = 0
first = True
for ch in t:

	i = ord(ch)-ord("a")

	if dp[i][j] < 0:
		print(-1)
		exit()

	distance = dp[i][j] - j
	if (not first )and distance <= 0 :
		distance += len_s
	ans += distance
	j = dp[i][j]

	first = False

print(ans + 1)

Submission status: Runtime Error

Solution code:
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

s = raw_input()
t = raw_input()

p = []
for i in range(26):
	p.append([])

for i in range(len(s)):
	p[ord(s[i]) - 97].append(i)

mn = 10**5 + 1
ans = 0
for i in range(len(t)):
	if p[ord(t[i]) - 97] == []:
		print -1
		break
	else:
		print p[ord(t[i]) - 97],mn
		if p[ord(t[i]) - 97][-1] <= mn:
			mn = p[ord(t[i]) - 97][0]
			ans += len(s)
			print ans
		else:
			mn = p[ord(t[i]) - 97][0]
# print p
print ans - len(s) + (p[ord(t[i]) - 97][-1] + 1)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
length=len(s)
pointer=0
flag=True
for string in t:
    count=0
    while flag and (string != s[pointer%length]):
        pointer+=1
        count+=1
        flag= not(count==length)
    if not flag:
        break
    count+=1
if flag:
    if pointer<length*10**100
    print(pointer+1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
s=input() #数値入力 「N」だけの入力のとき
t=input()  #数値入力 「N」だけの入力のとき
sa=list(s)
ta=list(t)
ans2
x=0
y=0
ans= [[] for i in range(26)]
for i in range(len(s)):
    ans[ord(sa[i])-96-1].append(i)
print(ans)
for i in range(len(t)):
    if len(ans[ord(ta[i])-97])==0:
        ans2=-1
        break;
    else:
        x_old=x
        for j in ans[ord(ta[i])-97]:
            if j>x:
                x=j
        if x_old==x:
            x=0
            y+=1
            for j in ans[ord(ta[i])-97]:
                if j>x:
                    x=j
print(y*len(s)+x+1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#ABC138 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    f[alpha.index(s[i])] = True
for i in range(m):
    f2[alpha.index(t[i])] = True
for i in range(26):
    if not f[i] and f2[i]:
        print(-1)
        quit()
x = []
inde = s.index(t[0])
x.append(inde+1)
if m > 1:
    x.append(n-inde-1)
for i in range(1,m):
    inde = s.index(t[i])
    preinde = s[i:].index(t[i])
    if inde > preinde:
        x.pop()
        x.append(inde-preinde)
        if i != m-1:
            x.append(n-inde-1)
    else:
        x.append(inde+1)
        if i != m-1:
            x.append(n-inde-1)
print(sum(x))

Submission status: Runtime Error

Solution code:
s = input()
t = input()

sd = ''
for _ in range(10**5):
  sd += s

flag = True
for c in t:
  if c not in s:
    flag = False

if flag==False:
  print(-1)

ret = 0
for c in t:
  a = sd.find(c)+1
  ret += a
  sd = sd[a:]
print(ret)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ans=1
order=0
judge=True
d={}
preorder=0
length=len(s)

for i in t:
        if i in s:
            if i not in d:
                    indexs=[j for j, x in enumerate(s) if x==i]
                    d[i]=list(indexs)
            if len(d[i])==0:
                    order=min([j for j in d[i] if j>order])
                    ans+=order-preorder
                    preorder=0
                    preorder+=order
             if min(d[i])>order-1:
                        order=min([j for j in d[i] if j>order])
                        ans+=order-preorder
                        preorder=0
                        preorder+=order

            else:
                    order=min(d[i])
                    ans+=order-preorder+length
                    preorder=0
                    preorder+=order

        else:
            judge=False

if judge:
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
s_set = list(set())
t_set = list(set())

able = True
for char in t_set:
  if not char in s_set:
    able = False
    break

if able:
  tt = False
  for k in range(len(s)*(10**100)):
    s_ = s*k
    ind_lis = []
    TF = True
    for char in t:
      if char in s_:
        ind = s_.index(char)
        ind_lis.append(ind)
        del s_[:ind+1]
      else:
        TF = False
        break
    if TF:
      tt = True
      break
  if tt:
    print(sum(ind_lis))
  else:
    print(-1)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
s = list(str(input()))
t = list(str(input()))

ans = []
for a in t:
    ans.append([i for i, x in enumerate(s) if x == a])

ans2 = 0

if [] in ans:
    print(-1)
else:
    _v = 0
    for y in ans:
        c = [x for x in y if _v < x]
        if c = []:
            ans2 += 1
            _v = min(y)
        else:
            _v = minc(c)
    print(ans2*len(s) + _v + 1)

Submission status: Runtime Error

Solution code:
#0818_E
import collections
import math
s = input()
t = input()
N = len(s)
M = len(t)
pos = 0
junflg = 0
# 可否判定
for i in range(M):
    if t[i] in s:
        for j in range(N):
            if s[j] == t[j]:
                nowpos = j
# 順どおりが成り立つのであれば、回数は1回減る
                if pos < nowpos:
                    pos = nowpos 
                else:
                    junflg = 1           
        continue
    else:
        print(-1)
        exit()
# 可能な場合
# 繰り返し回数を算出
cols = collections.Counter(s)
colt = collections.Counter(t)
coltmost = colt.most_common()
# 繰り返し回数
mulnum = math.floor(colt[coltmost[0][0]] / cols[coltmost[0][0]])
print(N * (mulnum+1) + nowpos + junflg)

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num__grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n, q = wi()
ab = mi(n - 1)
px = mi(q)
numdict = {}
for i in range(n + 1):
    numdict[i] = []

parli = [0 for i in range(n + 1)]
parli[1] = 1
for i in range(n - 1):
    if parli[ab[i][0]] == 0:
        parli[ab[i][0]] = 1
    else:
        numdict[ab[i][0]].append(ab[i][1])
    if parli[ab[i][1]] == 0:
        parli[ab[i][1]] = 1
    else:
        numdict[ab[i][1]].append(ab[i][0])

numli = [0 for i in range(n + 1)]

plsdict = defaultdict(int)
for i in range(q):
    plsdict[px[i][0]] += px[i][1]

for i in range(1, n + 1):
    numli[i] += plsdict[i]



queue = deque()
queue.append(1)
while queue != deque():
    po = queue.popleft()
    for kk in numdict[po]:
        queue.append(kk)
        numli[kk] += numli[po]

for i in range(1, n + 1):
    print(numli[i],"" , end="")

Submission status: Runtime Error

Solution code:
s = input()
t = input()
l = 10**5
S = s*l

a = 0
flag = True
for i in range(len(t)):
    if t[i] in S[a:]:
        a += S[a:].find(t[i])+1
    else:
        flag = False
        break
        
if flag:
    print(a)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    Flag = False
    s = list(input())
    t = list(input())
    s = s * 100
    
    for i in t:
        if i in s:
            ;
        else :
            print(-1)
            Flag = True
            break
            
    if Flag == False:
        for j in range(len(s)):
            if t == []: 
                print(j)
                break
            else :
                if t[0]==s[j]:
                    t.pop(0)

Submission status: Runtime Error

Solution code:
import sys
s=list(input())
t=list(input())
a=[[] for _ in range(len(t))]
d=[]

for i in range(len(t)):
  for k in range(len(d)):
    if t[i]==d[k][1]:
      a[i]=d[k][0]
      break
  print(a,d)
  if a[i]==[]:
    for j in range(len(s)):
      if t[i]==s[j]:
        a[i].append(j)
        if (a[i],t[i]) not in d:
          d.append((a[i],t[i]))
      if j==len(s)-1 and a[i]==[]:
        print('-1')
        sys.exit()

ans=0
cur=0
for i in range(len(t)-1):
  for j in range(len(a[i+1])):
    if a[i][cur]<a[i+1][j]:
      cur=j
      break
    if j==len(a[i+1])-1:
      ans+=len(s)
      cur=0
print(ans+1+a[-1][cur])

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())

l = list()
for i in range(len(t)):
    l.append([j for j, x in enumerate(s) if x == t[i]])
cnt = 0
now = 0
for i in range(len(l)):
    if any([now < j for j in l[i]]):
        now = min([e for e in l[i] if e > now])
    else:
        now = min(l[i])
        cnt += 1
print(cnt*len(s)+now+1)

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())

ls = len(s)
lt = len(t)
st = set(t)
flg = 0

for i in st:
  if s.count(i)==0:
    flg = -1
    print(flg)
    exit()

i = 0
j = 0
s = s*1000000

while i<lt:
  if t[i]==s[j]:
    i+=1
  j+=1
  
print(j)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    Flag = False
    s = list(input())
    t = list(input())
    s = s * len(t)
    
    for i in t:
        if i in s:
            ;
        else :
            print(-1)
            Flag = True
            break
            
    if Flag == False:
        for j in range(len(s)):
            if t == []: 
                print(j)
                break
            else :
                if t[0]==s[j]:
                    t.pop(0)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
dp = [0] * (len(t)+1)
for i in range(1,len(t)+1):
    dp[i] = dp[i-1] + (s.index(t[i-1]) + 1)
    s = s[s.index(t[i-1])+1:] + s[:s.index(t[i-1])+1]
print(dp[-1])

Submission status: Runtime Error

Solution code:
s = input()
t = input()
l = 10**5
S = s*l

a = 0
flag = True
for i in range(len(t)):
    if t[i] in S[a+1:]:
        a += S[a+1:].find(t[i])+1
    else:
        flag = False
        break
        
if flag:
    print(a+1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())

ls = len(s)
lt = len(t)
st = set(t)
flg = 0

for i in st:
  if s.count(i)==0:
    flg = -1
    print(flg)
    exit()

i = 0
j = 0
s = s*20000

while i<lt:
  if t[i]==s[j]:
    i+=1
  j+=1
  
print(j)

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

s=input()
t=input()
s=list(s)
t=list(t)
Ss=set(s)
St=set(t)
n=len(s)

alp=string.ascii_lowercase
di=dict([(i,j) for j,i in enumerate(alp)])
#print(di)
g=[{} for _ in range(n)]
fp=[-1 for i in range(26)]
lp=[-1 for i in range(26)]

for i,c in enumerate(s):
    fp[di[c]]=i
    for next_c in [di[l] for l in Ss]:
        if fp[next_c]!=-1:
            g[i][next_c]=(fp[next_c],1)

for i in range(n)[::-1]:
    lp[di[s[i]]]=i
    for next_c in [di[l] for l in Ss]:
        if lp[next_c]!=-1:
            g[i][next_c]=(lp[next_c],0)

m=[[] for i in range(n)]


#print(Ss,St,St-Ss)
if len(St-Ss)!=0:
    ans=-1
else:
    loop=0
    st=di[t[0]]
    i_n=g[0][st][0]
    for i in range(1,len(t)):
        ch=di[t[i]]
        loop+=g[i_n][ch][1]
        i_n=g[i_n][ch][0]
        has=g[i_n][ch][0]
        #print(loop,has,i_n,g[i_n][ch])
    ans=loop*n+has+1
print(ans)#,loop,has)
#print([[i,di[i]] for i in s])
'''
for i in g:
    print(sorted(list(i.items()),key=lambda x:x[0]))
'''

Submission status: Runtime Error

Solution code:
s = input()
t = input()
sr = s
rem = list(set(list(s))-set(list(t)))
for i in rem:
    sr.strip(i)

ss = sr*len(t)
lt = list(t)

if set(list(t)).issubset(set(list(s))):
    for i in range(len(s)*len(t)):
        if ss[i] == lt[0]:
            lt.pop(0)
            if len(lt) == 0:
                ans = i+1
                break
else:
    ans = -1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    T = str(input().strip())

    if not set(T) <= set(S):
        return -1

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

    cnt = 0
    pos = 0
    for t in T:
        if pos > max(d[t]):
            cnt += 1
            pos = d[t][0]
        else:
            left = 0
            right = len(d[t])
            while left < right:
                mid = (left + right) // 2
                np = d[t][mid]
                if np <= pos:
                    left = mid + 1
                else:
                    right = mid
            pos = d[t][left]

    return n * cnt + pos


if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    T = str(input().strip())

    if not set(T) <= set(S):
        return -1

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

    cnt = 0
    pos = 0
    for t in T:
        if pos > max(d[t]):
            cnt += 1
            pos = d[t][0]
        else:
            left = 0
            right = len(d[t])
            while left != right:
                mid = (left + right) // 2
                np = d[t][mid]
                if np <= pos:
                    left = mid + 1
                else:
                    right = mid
            pos = d[t][left]

    return n * cnt + pos


if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

s = raw_input()
t = raw_input()

p = []
for i in range(26):
	p.append([])

for i in range(len(s)):
	p[ord(s[i]) - 97].append(i)

mn = 10**5 + 1
ans = 0
for i in range(len(t)):
	if p[ord(t[i]) - 97] == []:
		print -1
		break
	else:
		if p[ord(t[i]) - 97][-1] <= mn:
			mn = p[ord(t[i]) - 97][0]
			ans += len(s)
# print p
print ans - len(s) + (p[ord(t[i]) - 97][-1] + 1)

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

s = str(input())
t = str(input())

q = deque([])

for x in t:
  q.append(x)

s = s*len(t)
cnt = 0
index = -1
for i in t:
  index = s.find(i,index+1)
  if index < 0:
    print('-1')
    sys.exit()

print(index+1)

Submission status: Runtime Error

Solution code:
import sys
s=list(input())
t=list(input())
a=[[] for _ in range(len(t))]
d=[]

for i in range(len(t)):
  for k in range(len(d)):
    if t[i]==d[k][1]:
      a[i]=d[k][0]
      break
  print(a,d)
  if a[i]==[]:
    for j in range(len(s)):
      if t[i]==s[j]:
        a[i].append(j)
      if (a[i],t[i]) not in d:
        d.append((a[i],t[i]))
      if j==len(s)-1 and a[i]==[]:
        print('-1')
        sys.exit()

ans=0
cur=0
for i in range(len(t)-1):
  for j in range(len(a[i+1])):
    if a[i][cur]<a[i+1][j]:
      cur=j
      break
    if j==len(a[i+1])-1:
      ans+=len(s)
      cur=0
print(ans+1+a[-1][cur])

Submission status: Runtime Error

Solution code:
import sys


if __name__ == "__main__":
    S = list(sys.stdin.readline().rstrip())
    T = list(sys.stdin.readline().rstrip())

    # 巻き戻る → 文字数分プラスする
    tmp = 0
    L = [S.index(t) if t in S else -1 for t in T]

    if -1 in L:
        print(-1)
        exit()

    prev = L[0]
    ans = 0
    Slen = len(S)

    for l in L[1::]:
        if prev >= l:
            ans += Slen
        prev = l
    if L[-2] < L[-1]:
        ans += (L[len(L) - 1] + 1)

    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()
t = input()

N = len(s)

tN = len(t)


def alpha_index(c):
    return ord(c) - ord("a")


# 次の特定の文字が何文字先にあるか
next_string = np.full((N, 26), 0)


def sarch_char(nowindex,c):
    if next_string[nowindex,alpha_index(c)] != 0:
        return next_string[nowindex,alpha_index(c)]
    else:
        for i in range(1, N):
            if s[(i + nowindex) % N] == c:
                next_string[nowindex,alpha_index(c)] = i
                return i
        next_string[nowindex,alpha_index(c)] = -1
        return -1


if not t[0] in s:
    print(-1)
    exit()

ans = s.find(t[0])
index = ans

for i in range(1,tN):
    nextindex = sarch_char(index, t[i])
    if nextindex == -1:
        print(-1)
        exit()
    ans += nextindex
    index = ans % N

print(ans + 1)

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())

ls = len(s)
lt = len(t)
st = set(t)
flg = 0

for i in st:
  if s.count(i)==0:
    flg = -1
    print(flg)
    exit()

i = 0
j = 0
s = s*100000

while i<lt:
  if t[i]==s[j]:
    i+=1
  j+=1
  
print(j)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
ss = s * (len(t))
ans = 0

if set(t) <= set(s):
    for i in range(len(t)):
        ans = ss.find(t[i], ans)
    print(ans + 1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
s=input()
t=input()

if not set(list(t))<=set(list(s)):
    print(-1)

else:
    ans=s*10**5
    t=list(t)

    i=0
    flag=True
    for l in range(len(ans)):
        if flag:
            if t[0] == ans[i]:
                del t[0]
            i+=1
            if len(t)==0:
                flag=False
    print(i)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
ss = s*len(t)
lt = list(t)

try:
    if set(list(t)).issubset(set(list(s))):
        for i in range(len(s)*len(t)):
            if ss[i] == lt[0]:
                lt.pop(0)
                if len(lt) == 0:
                    ans = i+1
                    break
    else:
        ans = -1
except:
    ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())

ls = len(s)
lt = len(t)
flg = 0

for i in t:
  if s.count(i)==0:
    flg = -1
    print(flg)
    exit()

i = 0
j = 0
s = s*10000

while i<lt:
  if t[i]==s[j]:
    i+=1
  j+=1
  
print(j)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ans=0
ti=0
si=0
f=0
for ti in range(len(t)):
  while t[ti]!=s[si]:
    ans+=1
    si+=1
    si=si%len(s)
    f+=1
    if f>len(s)+2:
      print("-1")
      exit()
  si+=1
  ti+=1
  ans+=1
  f=0
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
t = input()

ps, pt = 0, 0
cnt = 0

flg = False
for x in t:
  if not x in s:
    flg = True
  
if flg:
  print(-1)
else:
  dic = {}
  for i in range(len(s)):
    dic[s[i]] = dic.get(s[i], []) + [i]
    
  if len(t)==1:
    print(min(dic[t])+1)
  else:
    cnt = 0

    t0 = min(dic[t[0]])
    t1 = dic[t[1]]
    if t0>min(t1) and t0<max(t1):
      t1 = min([i for i in t1 if i>t0])
    elif t0>min(t1):
      cnt += 1
      t1 = min(t1)
    elif t0<min(t1):
      t1 = min(t1)
      
    if len(t)==2:
      print(cnt*len(s)+t1+1)
    else:
      for j in range(2, len(t)):
        t0, t1 = t1, dic[t[j]]
        if t0>min(t1) and t0<max(t1):
          t1 = min([i for i in t1 if i>t0])
        elif t0>min(t1):
          cnt += 1
          t1 = min(t1)
        elif t0<min(t1):
          t1 = min(t1)
        
      print(cnt*len(s)+t1+1)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
s_rev = s[::-1]

flag = True
a_list = []
for i in range(len(t)):
    cnt = s.count(t[i])
    if cnt == 0:
        flag = False
        break
    elif cnt == 1:
        a = s.find(t[i])
        a_list.append(a)
    else:
        a = len(s) - s_rev.find(t[i])


if flag:
    cnt = 0
    for i in range(len(a_list)-1):
        if a_list[i] >= a_list[i+1]:
            cnt += 1
    print(cnt*len(s) + a_list[-1] + 1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
ss = s*len(t)
lt = list(t)

if set(list(t)).issubset(set(list(s))):
    for i in range(len(s)*len(t)):
        if ss[i] == lt[0]:
            lt.pop(0)
            if len(lt) == 0:
                try:
                    ans = i+1
                    break
                except:
                    ans = 0
else:
    ans = -1

print(ans)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
s1=set(s)
t1=set(t)
union=s1.union(t1)
if(len(union)!=len(s1)):
  print(-1)
else:
  ans=0
  i=0
  while(i<len(t)):
    c=t[i]
    ind=s.index(c)
    nl=s[:ind]
    nr=s[ind+1:]
    if(i==len(t)-1):
      ans+=ind+1
    else:
      while(t[i] in nr):
        ind1=nr.index(t[i])
        
        nr=nr[ind1+1:]
        i+=1
      if(t[i+1] not in nr):
        ans+=len(s)
    i+=1
    #print(ans,t[i-1])
  print(ans)

Submission status: Runtime Error

Solution code:
s=input()
t=input()

ss=list(s)
tt=list(t)
l=len(ss)    
count=0
y=-1
ind={}
flag1=0
for x in tt:
    ind[x]=[i for i, xx in enumerate(ss) if xx == x]
    if ind[x]==[]:
        flag1=1

if flag1==0:    
    for x in tt:
        for z in ind[x]:
            if z>y:
                y=z
                flag=0
                break
            flag=1
        if flag==1:
            count+=1
            y=ind[x][0]
    #         print(count,z,y)
    ans=count*l+z+1
    print(ans)
else:
    pritn(-1)

Submission status: Runtime Error

Solution code:
s = input()
t = input()

ps, pt = 0, 0
cnt = 0

flg = False
for x in t:
  if not x in s:
    flg = True
  
if flg:
  print(-1)
else:
  dic = {}
  for i in range(len(s)):
    dic[s[i]] = dic.get(s[i], []) + [i]
    
  if len(t)==1:
    print(min(dic[t])+1)
  else:
    cnt = 0

    t0 = min(dic[t[0]])
    t1 = sorted(dic[t[1]])
    if t0>min(t1) and t0<max(t1):
      t1 = min([i for i in t1 if i>t0])
    elif t0>min(t1):
      cnt += 1
      t1 = min(t1)
    elif t0<min(t1):
      t1 = min(t1)
      
    if len(t)==2:
      print(cnt*len(s)+t1+1)
    else:
      for j in range(2, len(t)):
        t0, t1 = t1, sorted(dic[t[j]])
        if t0>min(t1) and t0<max(t1):
          t1 = min([i for i in t1 if i>t0])
        elif t0>min(t1):
          cnt += 1
          t1 = min(t1)
        elif t0<min(t1):
          t1 = min(t1)
        
      print(cnt*len(s)+t1+1)

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())

ls = len(s)
lt = len(t)
flg = 0

for i in t:
  if s.count(i)==0:
    flg = -1
    print(flg)
    exit()

i = 0
j = 0
s = s*100000

while i<lt:
  if t[i]==s[j]:
    i+=1
    j+=1
  else:
    j+=1
  
print(j)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
S = input()
T = input()
for i in T:
    if i not in S:
        print(-1)
        exit()

N = len(S)
nex = [[N] * 26 for i in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(26):
        nex[i][j] = nex[i + 1][j]
    nex[i][ord(S[i]) - ord('a')] = i


M = len(T)
i = 0
num = 0
j = 0
while j < M:
    if nex[i][ord(T[j]) - ord('a')] < N:
        num += nex[i][ord(T[j]) - ord('a')] - i + 1
        i = nex[i][ord(T[j]) - ord('a')] + 1
        j += 1
    else:
        num += N - i
        i = 0

print(num)

Submission status: Runtime Error

Solution code:
import sys
intMaxValue=sys.maxsize
s=input()
t=input()

if not set(list(t))<=set(list(s)):
    print(-1)

else:
    ans=s*10**5
    t=list(t)

    i=0
    flag=True
    for l in range(len(ans)):
        if flag:
            if t[0] == ans[i]:
                del t[0]
            i+=1
            if len(t)==0:
                flag=False
    print(float(i))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    s = input()
    t = list(input())
    s = s * len(t)
    for i in range(len(s)):
        if t == []: 
            print(i)
            break
        else :
            if t[0]==s[i]:
                t.pop(0)
    else :
        print(-1)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
for i in range(len(t)):
    s+=s
List_s=list(s)
List_t=list(t)

text = list(set(List_t) - set(List_s))
if len(text)!=0:
    print(-1)
    exit()

ans=0
for i in List_t:
    for j in range(ans,len(List_s)):
        ans+=1
        if i==List_s[j]:
            break

print(ans)