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: Wrong Answer

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=[10*10 for i in range(26)]
lp=[-1 for i in range(26)]

for i,c in enumerate(s):
    fp[di[c]]=min(i,fp[di[c]])
    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
    has=0
    st=di[t[0]]
    loop+=g[0][st][1]
    i_n=g[0][st][0]
    has=i_n
    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: Wrong Answer

Solution code:
from bisect import bisect
S=input()
T=input()
c=[[] for _ in range(26)]
for i,s in enumerate(S):
    j=ord(s)-ord("a")
    c[j].append(i)
for t in set(T):
    if not c[ord(t)-ord("a")]:
        print(-1)
        exit()
rnd=0
k=-1
for t in T:
    ti=ord(t)-ord("a")
    i=bisect(c[ti],k)
    print(ti,i)
    if i==len(c[ti]):
        k=c[ti][0]
        rnd+=1
    else:
        k=c[ti][i]

print(c)

print(rnd*len(S)+k+1)

Submission status: Wrong Answer

Solution code:
import bisect

s=input()
t=input()

#index=list()
#for a in range(len(t)):
# index.append([i for i, x in enumerate(s) if x == t[a]])

char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
for i, ch in enumerate(s):
    char_appear[ch].append(i)
#print(char_appear['a'])
      
b=0
loop=0
condition=0

for j in range(len(t)):
  if len(char_appear[t[j]])<1:
    print(-1)
    condition=1
    break
  c=bisect.bisect_left(char_appear[t[j]],b)
 # print(j,char_appear[t[j]],b,c,loop)
  if j<1:
    b=char_appear[t[0]][0]    
  elif c == len(char_appear[t[j]]) or c==char_appear[t[j]][len(char_appear[t[j]])-1]: 
     loop +=1
     b=char_appear[t[j]][0]
     if loop==10**100:
        print(-1)
        condition=1
        break
  else:
     b=char_appear[t[j]][c]
     #print(j,b,loop)


if condition==0:
 print(b+loop*len(s)+1)

Submission status: Wrong Answer

Solution code:
import bisect

s=input()
t=input()

#index=list()
#for a in range(len(t)):
# index.append([i for i, x in enumerate(s) if x == t[a]])

char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
for i, ch in enumerate(s):
    char_appear[ch].append(i)
#print(char_appear['a'])
      
b=0
loop=0
condition=0

for j in range(len(t)):
  #print(j,index[j],b,c,loop)
  if len(char_appear[t[j]])<1:
    print(-1)
    condition=1
    break
  c=bisect.bisect_left(char_appear[t[j]],b)
  if j<1:
    b=char_appear[t[0]][0]    
  elif c == len(char_appear[t[j]]) or c==char_appear[t[j]][len(char_appear[t[j]])-1]: 
     loop +=1
     b=char_appear[t[j]][0]
  else:
     b=char_appear[t[j]][c]
     #print(j,b,loop)


if condition==0:
 print(b+loop*len(s)+1)

Submission status: Wrong Answer

Solution code:
import bisect

s=input()
t=input()

index=list()
for a in range(len(t)):
 index.append([i for i, x in enumerate(s) if x == t[a]])

char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
for i, ch in enumerate(s):
    char_appear[ch].append(i)
#print(char_appear['a'])
      
b=0
loop=0
condition=0

for j in range(len(t)):
  #print(j,index[j],b,c,loop)
  if len(char_appear[t[j]])<1:
    print(-1)
    condition=1
    break
  c=bisect.bisect_left(char_appear[t[j]],b)
  if j<1:
    b=char_appear[t[0]][0]    
  elif c == len(char_appear[t[j]]): #or c==index[j][len(index[j])-1]: 
     loop +=1
     b=char_appear[t[j]][0]
  else:
     b=char_appear[t[j]][c]
     #print(j,b,loop)


if condition==0:
 print(b+loop*len(s)+1)

Submission status: Wrong Answer

Solution code:
import bisect

s=input()
t=input()

index=list()
for a in range(len(t)):
 index.append([i for i, x in enumerate(s) if x == t[a]])

b=0
loop=0
condition=0

for j in range(len(t)):
  #print(j,index[j],b,c,loop)
  if len(index[j])<1:
    print(-1)
    condition=1
    break
  c=bisect.bisect_left(index[j],b)
  if j<1:
    b=index[0][0]    
  elif c == len(index[j]): 
     loop +=1
     b=index[j][0]
  else:
     b=index[j][c]
     #print(j,b,loop)


if condition==0:
 print(b+loop*len(s)+1)

Submission status: Wrong Answer

Solution code:
import bisect

s=input()
t=input()

condition=0

index=list()
for a in range(len(t)):
 index.append([i for i, x in enumerate(s) if x == t[a]])

b=-1
loop=0
condition=0

for j in range(len(t)):
  c=bisect.bisect_left(index[j],b)
  #print(j,index[j],b,c,loop)
  if len(index[j])<1:
     print(-1)
     condition=1
     break
  elif c<len(index[j]) and c != index[j][len(index[j])-1]:
     b=index[j][c]
     #print(j,b,loop)
  else:
     loop=loop+len(s)
     b=index[j][0]
     if loop == len(s)*(10**100):
       print(-1)
       break

if condition==0:
 print(b+loop+1)

Submission status: Wrong Answer

Solution code:
import bisect

s=input()
t=input()

condition=0

index=list()
for a in range(len(t)):
 index.append([i for i, x in enumerate(s) if x == t[a]])

b=0
loop=0
condition=0

for j in range(len(t)):
  c=bisect.bisect_left(index[j],b)
  #print(j,index[j],b,c,loop)
  if len(index[j])<1:
     print(-1)
     condition=1
     break
  elif c<len(index[j]) and c != index[j][len(index[j])-1]:
     b=index[j][c]
     #print(j,b,loop)
  else:
     loop=loop+len(s)
     b=index[j][0]
     if loop == len(s)*(10**100):
       print(-1)
       break

if condition==0:
 print(b+loop+1)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_right

s = ns()
t = ns()

# 判定
ok = True
sset = set(list(s))
tset = set(list(t))
for ti in tset:
    if ti not in sset:
        ok = False

if not ok:
    print(-1)
else:
    n = len(s)
    nex = [[] for _ in range(26)]
    sdouble = s + s
    orda = ord("a")
    for i, si in enumerate(sdouble):
        nex[ord(si) - orda].append(i)

    cur = -1
    ans = 0

    for ti in t:
        chridx = ord(ti) - orda
        dest = bisect_right(nex[chridx], cur)
        ans += (nex[chridx][dest] - cur)
        cur = ans % n

    print(ans+1)

Submission status: Wrong Answer

Solution code:
import bisect

s=input()
t=input()

#print(index)
condition=0
t2=list(set(t))
#print(t2)

for i in range(len(t2)):
 if s.count(t2[i])==0:
   condition=1
   break

if condition==1:
  print(-1)
else:
  index=list()
  for a in range(len(t)):
   index.append([i for i, x in enumerate(s) if x == t[a]])
  
  #print(index)
  b=index[0][0]
  j=1
  loop=0
  count=0
  if len(t)==1:
    print(b+1)
  else:
   while j <= len(t)-1:
     c=bisect.bisect_left(index[j],b-loop)
     #print(j,index[j],b,c,loop)
     if c < len(index[j]):
        b=index[j][c]+loop
       # print(j,b,loop)
        j=j+1
        if j==len(t):
          print(b+1)
     else:
        loop=loop+len(s)
        if loop == len(s)*(10**100):
           print(-1)
           break

Submission status: Wrong Answer

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



#print(index)
condition=0
t2=list(set(t))
#print(t2)

for i in range(len(t2)):
 if s.count(t2[i])==0:
   condition=1
   break

if condition==1:
  print(-1)
else:
  index=list()
  for a in range(len(t)):
   index.append([i for i, x in enumerate(s) if x == t[a]])
  
  #print(index)
  b=index[0][0]
  j=1
  loop=0
  count=0
  while j <= len(t)-1:
     cond=0
     for k in range(len(index[j])):
       if index[j][k]+loop >b:
         b=index[j][k]+loop
         #print(b)
         j=j+1
         cond=1
         if j==len(t):
           print(b+1)
         break
       if cond==0:   
         loop=loop+len(s)
         if loop == len(s)*(10**100):
            print(-1)
            break

Submission status: Wrong Answer

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

#print(t[0])


#print(index)

condition=0
for i in range(len(t)):
 if s.count(t[i])==0:
   condition=1
   break

if condition==1:
  print(-1)
else:
  index=list()
  for a in range(len(t)):
   index.append([i for i, x in enumerate(s) if x == t[a]])
  
  #print(index)
  b=index[0][0]
  j=1
  loop=0
  count=0
  while j <= len(t)-1:
     cond=0
     for k in range(len(index[j])):
       if index[j][k]+loop >b:
         b=index[j][k]+loop
         #print(b)
         j=j+1
         cond=1 
         break
     if j==len(t):
        print(b+1)
        break
     elif cond==0:   
       loop=loop+len(s)
       if loop == len(s)*(10**100):
         print(-1)
         break

Submission status: Wrong Answer

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

#print(t[0])


#print(index)

condition=0
for i in range(len(t)):
 if s.count(t[i])==0:
   condition=1
   break

if condition==1:
  print(-1)
else:
  index=list()
  for a in range(len(t)):
   index.append([i for i, x in enumerate(s) if x == t[a]])
  
  #print(index)
  b=0
  j=0
  loop=0
  count=0
  while j <= len(t)-1:
     cond=0
     for k in range(len(index[j])):
       if index[j][k]+loop >b:
         b=index[j][k]+loop
         #print(b)
         j=j+1
         cond=1 
         break
       elif index[j][k]+loop==b:
         b=b+1
         j=j+1
         cond=1
         break
     if j==len(t):
        print(b+1)
        break
     elif cond==0:   
       loop=loop+len(s)
       if loop == len(s)*(10**100):
         print(-1)
         break

Submission status: Wrong Answer

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

#print(t[0])


#print(index)

condition=0
for i in range(len(t)):
 if s.count(t[i])==0:
   condition=1
   break

if condition==1:
  print(-1)
else:
  index=list()
  for a in range(len(t)):
   index.append([i for i, x in enumerate(s) if x == t[a]])
  
  #print(index)
  b=0
  j=0
  loop=0
  count=0
  while j <= len(t)-1:
     cond=0
     for k in range(len(index[j])):
       if index[j][k]+loop >=b:
         b=index[j][k]+loop
         #print(b)
         j=j+1
         cond=1 
         break
     if j==len(t):
        print(b+1)
        break
     elif cond==0:   
       loop=loop+len(s)
       if loop == len(s)*(10**100):
         print(-1)
         break

Submission status: Wrong Answer

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

#print(t[0])


#print(index)

condition=0
for i in range(len(t)):
 if s.count(t[i])==0:
   condition=1
   break

if condition==1:
  print(-1)
else:
  index=list()
  for a in range(len(t)):
   index.append([i for i, x in enumerate(s) if x == t[a]])
  
  #print(index)
  b=0
  j=0
  loop=0
  count=0
  while j <= len(t)-1 and count<=len(s)*(10**(100)):
     count=count+1
     cond=0
     for k in range(len(index[j])):
       if index[j][k]+loop >=b:
         b=index[j][k]+loop
         #print(b)
         j=j+1
         cond=1 
         break
     if cond==0:   
       loop=loop+len(s)
     if count == len(s)*(10**100):
      print(-1)
      break
  print(b+1)

Submission status: Wrong Answer

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

#print(t[0])


#print(index)

condition=0
for i in range(len(t)):
 if s.count(t[i])==0:
   condition=1
   break

if condition==1:
  print(-1)
else:
  index=list()
  for a in range(len(t)):
   index.append([i for i, x in enumerate(s) if x == t[a]])
   
  b=0
  j=0
  loop=0
  while j <= len(t)-1:
     cond=0
     for k in range(len(index[j])):
       if index[j][k]+loop*len(s) >=b:
         b=index[j][k]+loop*len(s)
         j=j+1
         cond=1 
         break
     if cond ==0:   
       loop=loop+1
  print(b+1)

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
c=a*10

letterDic={}
j=0
for i in a:
  if i in letterDic:
    letterDic[i].append(j)
  else:
    letterDic[i]=[j]
  j=j+1

#print(letterDic)
    
result=0

flag=1
temp=0

for word in b:
  #print(word,temp,"#############################")
  if word in letterDic:
    endFlag=0
    #print(letterDic[word])
    for item in letterDic[word]:
      if item>=temp:
        result+=item-temp
        temp=item
        endFlag=1

        break
    if endFlag==0:
      result+=min(letterDic[word])-temp+len(a) 
      temp=min(letterDic[word])
    #print(c[0:result+1])

      
      
  
  else:
    print("-1")
    flag=0
    break

if flag==1:
  print(result+1)

Submission status: Wrong Answer

Solution code:
def e_strings_of_inpurity():
    from bisect import bisect_left
    S = input()
    T = input()

    char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
    for i, ch in enumerate(S):
        char_appear[ch].extend([i, i + len(S)])  # Sを2個連結させた文字列を考える

    ans = 0
    # editorial における二分探索を使うやり方
    p = -1  # 文字 t は S' の p (mod |S|) 番目に現れた
    for t in T:
        if len(char_appear[t]) == 0:
            return -1  # 文字tが存在しなかった
        p = char_appear[t][bisect_left(char_appear[t], p)] + 1
        if p >= len(S):
            p -= len(S)
            ans += len(S)
    ans += p  # 残った分を足す
    return ans

print(e_strings_of_inpurity())

Submission status: Wrong Answer

Solution code:
def e_strings_of_inpurity():
    from bisect import bisect_left
    S = input()
    T = input()

    char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
    for i, ch in enumerate(S):
        char_appear[ch].extend([i, i + len(S)])  # Sを2個連結させた文字列を考える

    ans = 0
    # editorial における二分探索を使うやり方
    p = 0  # 文字 t は S' の p (mod |S|) 番目に現れた
    for t in T:
        if len(char_appear[t]) == 0:
            return -1  # 文字tが存在しなかった
        p = char_appear[t][bisect_left(char_appear[t], p + 1)]
        if p >= len(S):
            p -= len(S)
            ans += len(S)
    ans += p + 1  # 残った分を足す
    return ans

print(e_strings_of_inpurity())

Submission status: Wrong Answer

Solution code:
def e_strings_of_inpurity():
    from bisect import bisect_left
    S = input()
    T = input()

    char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
    for i, ch in enumerate(S):
        char_appear[ch].extend([i, i + len(S)])  # Sを2個連結させた文字列を考える

    ans = 0
    # editorial における二分探索を使うやり方
    p = 0  # 文字 t は S' の p (mod |S|) 番目に現れた
    for t in T:
        if len(char_appear[t]) == 0:
            return -1  # 文字tが存在しなかった
        p = char_appear[t][bisect_left(char_appear[t], p)]
        if p >= len(S):
            p -= len(S)
            ans += len(S)
    ans += p + 1  # 残った分を足す
    return ans

print(e_strings_of_inpurity())

Submission status: Wrong Answer

Solution code:
def e_strings_of_inpurity():
    from bisect import bisect_left
    S = input()
    T = input()

    char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
    for i, ch in enumerate(S):
        char_appear[ch].extend([i, i + len(S)])  # Sを2個連結させた文字列を考える

    ans = 0
    # editorial における二分探索を使うやり方
    p = 0  # 文字 t は S' の p (mod |S|) 番目に現れた
    for t in T:
        if len(char_appear[t]) == 0:
            return -1  # 文字tが存在しなかった
        p = char_appear[t][bisect_left(char_appear[t], p + 1)]
        if p >= len(S):
            p %= len(S)
            ans += len(S)
    ans += p + 1  # 残った分を足す
    return ans

print(e_strings_of_inpurity())

Submission status: Wrong Answer

Solution code:
def e_strings_of_inpurity():
    from bisect import bisect_left
    S = input()
    T = input()

    char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
    for i, ch in enumerate(S):
        char_appear[ch].extend([i, i + len(S)])  # Sを2個連結させた文字列を考える

    ans = 0
    # editorial における二分探索を使うやり方
    p = 0  # 文字 t は S' の p (mod |S|) 番目に現れた
    for t in T:
        if len(char_appear[t]) == 0:
            return -1  # 文字tが存在しなかった
        p = char_appear[t][bisect_left(char_appear[t], p)]
        if p >= len(S):
            p %= len(S)
            ans += len(S)
    ans += p + 1  # 残った分を足す
    return ans

print(e_strings_of_inpurity())

Submission status: Wrong Answer

Solution code:
def e_strings_of_inpurity():
    from bisect import bisect_left
    S = input()
    T = input()

    char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
    for i, ch in enumerate(S):
        char_appear[ch].extend([i, i + len(S)])  # Sを2個連結させた文字列を考える

    ans = 0
    # editorial における二分探索を使うやり方
    p = 0  # 文字 t は S' の p-1 (mod |S|) 番目に現れた
    for t in T:
        if len(char_appear[t]) == 0:
            return -1  # 文字tが存在しなかった
        p = char_appear[t][bisect_left(char_appear[t], p)] + 1
        if p >= len(S):
            p %= len(S)
            ans += len(S)
    ans += p  # 残った分を足す
    return ans

print(e_strings_of_inpurity())

Submission status: Wrong Answer

Solution code:
a=input()
b=input()

letterDic={}
j=0
for i in a:
  if i in letterDic:
    letterDic[i].append(j)
  else:
    letterDic[i]=[j]
  j=j+1

#print(letterDic)
    
result=0

flag=1
temp=0

for word in b:
  if word in letterDic:
    endFlag=0
    for item in letterDic[word]:
      if item>temp:
        result+=item-temp
        temp=item
        endFlag=1
        break
    if endFlag==0:
      result+=min(letterDic[word])-temp+len(a) 
      temp=item

      
      
  
  else:
    print("-1")
    flag=0
    break

if flag==1:
  print(result+1)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
D = {}
len_s = len(s)
for tc in t:
    if not tc in D:
        D[tc] = [0] * len_s
s += s
flag = True
for a in D.keys():
    index = -1
    for i in reversed(range(len(s))):
        if s[i] == a:
            index = i
        D[a][i % len_s] = index % len_s
    if index == -1:
        flag = False
i = 0
ans = 0
for tc in t:
    index = D[tc][i]
    if index < i:
        ans += index + (len_s - i)
    else:
        ans += index - i
    i = index
if not flag:
    print(-1)
else:
    print(ans + 1)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
D = {}
len_s = len(s)
for tc in t:
    D[tc] = [0] * len_s
s += s
flag = True
for a in D.keys():
    index = -1
    for i in range(len_s * 2):
        pass

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
D = {}
len_s = len(s)
for tc in t:
    D[tc] = [0] * len_s
s += s
flag = True
for a in D.keys():
    index = -1
    for i in range(len_s * 2):
        if s[i] == a:
            index = i
        D[a][i % len_s] = index % len_s
    if index == -1:
        flag = False

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
cnt = 0
for i in range(23):
  for j in range(len(s)):
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
cnt = 0
for i in range(len(t)):
  for j in range(len(s)):
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
D = {}
len_s = len(s)
for tc in t:
    D[tc] = [0] * len_s
s += s
flag = True
for a in D.keys():
    index = -1
    for i in range(len(s)):
        if s[i] == a:
            index = i
        D[a][i % len_s] = index % len_s
    if index == -1:
        flag = False
print(D)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input().splitlines()[0]

    Slen = len(s)

    LookupTable = [[] for i in range(26)]
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LookupTable[v].append(i)
    for i in range(26):
        LookupTable[i].append(-1)
        
    IndexTable = [0 for i in range(26)]
    NextTable = []
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        IndexTable[v] += 1
        if LookupTable[v][IndexTable[v]] < 0:
            IndexTable[v] = 0

    Index = 0
    Loop = 0
    for i, c in enumerate(t):
        v = ord(c) - ord('a')
        if NextTable[Index][v] < Index:
            Loop += 1
        Index = NextTable[Index][v]
        if Index < 0:
            print(-1)
            return
        Index = (Index + 1) % Slen

    print(Loop*Slen+Index)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
D = {}
len_s = len(s)
for tc in t:
    D[tc] = [0] * len_s
s += s
flag = True
for a in D.keys():
    index = -1
    for i in reversed(range(len(s))):
        if s[i] == a:
            index = i
        D[a][i % len_s] = index % len_s
    if index == -1:
        flag = False

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input()

    Slen = len(s)

    LookupTable = [[] for i in range(26)]
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LookupTable[v].append(i)
    for i in range(26):
        LookupTable[i].append(Slen)
        
    IndexTable = [0 for i in range(26)]
    NextTable = []
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        if LookupTable[v][IndexTable[v]] >= i:
            IndexTable[v] += 1
        if LookupTable[v][IndexTable[v]] == Slen:
            IndexTable[v] = 0

    Index = 0
    Loop = 0
    for i, c in enumerate(t):
        v = ord(c) - ord('a')
        if NextTable[Index][v] < Index:
            Loop += 1
        Index = NextTable[Index][v]
        if Index == Slen:
            print(-1)
            return

    print(Loop*Slen+Index+1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input()

    Slen = len(s)

    LookupTable = [[] for i in range(26)]
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LookupTable[v].append(i)
    for i in range(26):
        LookupTable[i].append(Slen)
        
    IndexTable = [0 for i in range(26)]
    NextTable = []
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        if LookupTable[v][IndexTable[v]] >= i:
            IndexTable[v] += 1
        if LookupTable[v][IndexTable[v]] == Slen:
            IndexTable[v] = 0
        
    Index = 0
    Loop = 0
    for i, c in enumerate(t):
        v = ord(c) - ord('a')
        if NextTable[Index][v] >= Index:
            Loop += 1
        Index = NextTable[Index][v]
        if Index == Slen:
            print(-1)
            return

    print(Loop*Slen+Index+1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    s = input().splitlines()[0]
    t = input()

    Slen = len(s)

    LookupTable = [[] for i in range(26)]
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        LookupTable[v].append(i)
    for i in range(26):
        LookupTable[i].append(Slen)
        
    IndexTable = [0 for i in range(26)]
    NextTable = []
    for i, c in enumerate(s):
        v = ord(c) - ord('a')
        NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        if LookupTable[v][IndexTable[v]] >= i:
            IndexTable[v] += 1
        if LookupTable[v][IndexTable[v]] == Slen:
            IndexTable[v] = 0
    NextTable.append( [LookupTable[k][IndexTable[k]] for k in range(26)] )
        
    Index = 0
    Loop = 0
    for i, c in enumerate(t):
        v = ord(c) - ord('a')
        if NextTable[Index][v] >= Index:
            Loop += 1
        Index = NextTable[Index][v]

    if Loop == Slen:
        print(-1)
    else:
        print(Loop*Slen+Index+1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
D = {}
len_s = len(s)
for tc in t:
    D[tc] = [0] * len_s
s += s
flag = True
for a in D.keys():
    index = -1
    for i in reversed(range(len(s))):
        if s[i] == a:
            index = i
        D[a][i % len_s] = index % len_s
    if index == -1:
        flag = False
i = 0
ans = 0
for tc in t:
    index = D[tc][i]
    if index < i:
        ans += index + (len_s - i)
    else:
        ans += index - i
    i = index
if not flag:
    print(-1)
else:
    print(ans + 1)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
s = len(S)
a = 0
ans = 0
for t in T:
    b = S.find(t)+1
    if b==0:
        ans = -1
        break
    elif a>=b:
        ans += (s-a)+b
    else:
        ans += (b-a)
    a = b
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s_len = len(s)
t_len = len(t)
s_list = [s[i] for i in range(s_len)]
str_sum = 0
for i in range(t_len):
  try:
    num = s_list.index(t[i])
    str_num += num+1
    s_list = s_list[num+1:] + s_list[:num+1]
  except:
    str_num = -1
    break
print(str_num)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
char = {c: [] for c in alphabet}
for i, c in enumerate(s):
    char[c].append(i)

result = 0
for c in t:
    if len(char[c]) == 0:
        print(-1)
        exit()
    idx = bisect(char[c], result % len(s))
    result = result - result % len(s)
    try:
        result += char[c][idx]
    except IndexError:
        result += len(s) + char[c][0]

print(result+1)
# contestcontestconte

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
char = {c: [] for c in alphabet}
for i, c in enumerate(s):
    char[c].append(i)

result = 0
for c in t:
    if len(char[c]) == 0:
        print(-1)
        exit()
    idx = bisect_left(char[c], result % len(s))
    result = result - result % len(s)
    try:
        result += char[c][idx]
    except IndexError:
        result += len(s) + char[c][0]

print(result+1)
# contestcontestconte

Submission status: Wrong Answer

Solution code:
from bisect import bisect
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
char = {c: [] for c in alphabet}
for i, c in enumerate(s):
    char[c].append(i)

result = 0
for c in t:
    if len(char[c]) == 0:
        print(-1)
        exit()
    idx = bisect(char[c], result % len(s))
    try:
        result += char[c][idx] - result % len(s)
    except IndexError:
        result += len(s) + char[c][0] - result % len(s)

print(result+1)
# contestcontestconte

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    s = input()
    t = input()
    sletters = [0]*26
    for i in range(len(s)):
        x = ord(s[i])-ord('a')
        if sletters[x] == 0:
            sletters[x] = [i]
        else:
            sletters[x].append(i)

    ans = 0
    curr_index = 0
    for i in t:
        x = ord(i)-ord('a')
        if sletters[x] == 0:
            print(-1)
            return
        index = bisect.bisect(sletters[x],curr_index)
        if index == len(sletters[x]):
            ans += len(s)-curr_index
            curr_index = sletters[x][0]
            ans += curr_index
        else:
            ans += sletters[x][index]-curr_index
            curr_index = sletters[x][index]
        

    print(ans+1)


main()

Submission status: Wrong Answer

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)
c = [[] for i in range(26)]
for i in range(n):
    c[alpha.index(s[i])].append(i)
for i in c:
    i.sort()
for i in range(1,m):
    preinde = s.index(t[i-1])
    for j in c[alpha.index(t[i])]:
        if j > preinde:
            inde = j
            break
    else:
        inde = s.index(t[i])
    if inde > preinde:
        x.pop()
        x.append(inde-preinde)
        x.append(n-inde-1)
    else:
        x.append(inde+1)
        x.append(n-inde-1)
x.pop()
print(sum(x))

Submission status: Wrong Answer

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

cnt, bfr = 0, 0
is_error = False
for c in t:
  line = s.find(c)
  if line == -1:
    is_error = True
  if bfr > line:
    cnt += 1
  bfr = line
if is_error:
  print( -1 )    
else: 
  print( cnt * len(s) + line+1 )

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect

s = stdin.readline().rstrip()
t = stdin.readline().rstrip()

ss = s+s
alpos = []

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

for i in range(len(ss)):
   alpos[ord(ss[i])-ord('a')].append(i)

pos = 0
mpos= 0
for i in range(len(t)):
    tn = ord(t[i])-ord('a')
    if ( len(alpos[tn]) == 0 ):
        pos = -2
        break
    minsteps = len(s)
    bpos = bisect.bisect_left(alpos[tn], mpos)
    pos += alpos[tn][bpos]-mpos
    mpos = pos%len(s)

print(pos+1)