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:
alpha2num = lambda c: ord(c) - ord('a') 

s = list(input())
alpha = [[] for i in range(26)]
a = 'abcdefghijklmnopqrstuvwxyz'

for i in range(len(s)):
    alpha[alpha2num(s[i])].append(i)

#print(alpha)

t = list(input())
l = [0] * 26
ans = 0


s_unique = list(set(s))
t_unique = list(set(t))
check = 0

for i in t_unique:
    if i in s_unique:
        pass
    else:
        check = 1

if check == 0:

    for i in range(len(t)):
        if i == 0:
            last = alpha[alpha2num(t[i])][l[alpha2num(t[i])]]
        else:
            if l[alpha2num(t[i])] >= len(alpha[alpha2num(t[i])]):
                l = [0] * 26
                last = tmp
                ans += 1
            else:
                tmp = alpha[alpha2num(t[i])][l[alpha2num(t[i])]]
                l[alpha2num(t[i])] += 1
    #            print(tmp)
                if tmp < last:
                    l = [0] * 26
                    last = tmp
                    ans += 1
                else:
                    last = tmp

#    print(ans)
    print(max(ans * len(s) + tmp + 1, len(s)))

else:
    print(-1)

Submission status: Runtime Error

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

for i in list(t):
  if not i in list(s):
    print(-1)
    break
    
T = list(t)
count=0
while len(T)>0:
  for i,n in enumerate(list(s*len(T))):
    if T[0]==n:
      del T[0]
    if len(T)==0:
      print(i+1)
      break

Submission status: Runtime Error

Solution code:
flag = True
a_list = []
for i in range(len(t)):
    a = s.find(t[i])
    if a == -1:
        flag = False
        break
    else:
        a_list.append(a)

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:
def check(t,s):
    i=0
    for j in range(len(s)):
        if(i==len(t)):
            return (True,j)
        if(t[i]==s[j]):
            i+=1
    if(i==len(t)):
        return (True,len(s))
    return False,-1
        

def solve(s,t):
    new_s = s
    for a in t:
        if a not in s:
            return -1
    l = 1
    r = len(t)
    final = 10**100
    while(l<=r):
        mid = (l+r)//2
        new_s = s*mid
        done,ans = check(t,new_s)
        if(done):
            final = min(final,ans)
            r = mid-1
        else:
            l = mid+1
    return final

s = input()
t = input()
print(solve(s,t))

Submission status: Runtime Error

Solution code:
alpha2num = lambda c: ord(c) - ord('a') 

s = list(input())
alpha = [[] for i in range(26)]
a = 'abcdefghijklmnopqrstuvwxyz'

for i in range(len(s)):
    alpha[alpha2num(s[i])].append(i)

#print(alpha)

t = list(input())
l = [0] * 26
ans = 0


s_unique = list(set(s))
t_unique = list(set(t))
check = 0

for i in t_unique:
    if i in s_unique:
        pass
    else:
        check = 1

if check == 0:

    for i in range(len(t)):
        if i == 0:
            last = alpha[alpha2num(t[i])][l[alpha2num(t[i])]]
        else:
            if l[alpha2num(t[i])] >= len(alpha[alpha2num(t[i])]):
                l = [0] * 26
                last = tmp
                ans += 1
            else:
                tmp = alpha[alpha2num(t[i])][l[alpha2num(t[i])]]
                l[alpha2num(t[i])] += 1
    #            print(tmp)
                if tmp < last:
                    l = [0] * 26
                    last = tmp
                    ans += 1
                else:
                    last = tmp

#    print(ans)
    print(ans * len(s) + tmp + 1)

else:
    print(-1)

Submission status: Runtime Error

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

sLength = len(s)
cursor = 0
loopCount = 0
isImpossible = False
for i in t:
    for k in range(0, sLength):
        if i == s[cursor]:
            cursor += 1
            break
        cursor += 1
        if cursor >= sLength:
            cursor = 0
            loopCount += 1
    else:
        isImpossible = True
        break
    continue

if isImpossible:
    print('-1')
else:
    print(loopCount * sLength + cursor)

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(i)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
a=[]
import bisect
for i in range(len(s)):
	a.append([ord(s[i]),i])
a.sort()
c=[]
d=[]
for i in range(len(s)):
	c.append(a[i][0])
	d.append(a[i][1])
b=[]
e=[]
for i in range(len(t)):
	if c[0]<=ord(t[i])<=c[-1]:
		b.append(bisect.bisect_left(c,ord(t[i])))
	else:
		print(-1)
		exit()
for i in range(len(t)):
	e.append(d[b[i]])
ans=e[0]+1
cnt=0
for i in range(len(e)-1):
	if e[i]<e[i+1]:
		ans+=e[i+1]-e[i]
		cnt=0
	elif e[i]==e[i+1] and s[i]==s[i+1]:
		ans+=1
	else:
		ans+=len(s)-e[i]+e[i+1]
		cnt=0
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
s_unique = list(set(list(s)))
t_unique = list(set(list(t)))
s_list = list(s)*(10**6)
t_list = list(t)
s_len = len(t_list)
cnt = 0
ans = 0
for i in range(len(s_unique)):
  for j in range(len(t_unique)):
    if t_unique[j] == s_unique[i]:
      cnt += 1
      break
if cnt != len(t_unique):
  print(-1)
else:
  for k in range(s_len):
    s_index = s_list.index(t_list[k])
    ans += (s_index+1)
    del s_list[:(s_index+1)]
  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 = sorted(dic[t[1]])
    if t0>min(t1) and t0<max(t1):
      l = 0
      r = len(t1)-1
      while l<r:
        m = (l+r)//2
        if t1[m]<t0 and t0<t1[m+1]:
          break
        elif t1[m]<t0:
          l = m+1
        else:
          r = m-1
      t1 = m
    if 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):
          l = 0
          r = len(t1)-1
          while l<r:
            m = (l+r)//2
            if t1[m]<t0 and t0<t1[m+1]:
              break
            elif t1[m]<t0:
              l = m+1
            else:
              r = m-1
          t1 = m
        if 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:
import numpy as np
s = input()
t = input()
i = 0
r = 1
n = len(s)

d = dict()
for x in t:
    d[x] = np.where(np.array(list(s)) == x)[0]
    if len(d[x]) == 0:
        print(-1)
        i = -1
        break

if i!=-1:
    for x in t:
        if i > d[x][-1]:
            r += n - i
            i = d[x][0]
            r += i
        else:
            j = d[x][np.where(d[x]>i)[0][0]]
            r += j - i
            i = j
    print(r)

Submission status: Runtime Error

Solution code:

import sys
input = sys.stdin.readline

S = list(input())
T = list(input())

alpha2num = lambda c: ord(c) - ord('a') 

alpha = [[] for _ in range(26)]
for i,s in enumerate(S):
    alpha[alpha2num(s)].append(i)

import bisect
tmp = 0
N = len(S)
base = 0
for t in T:
    a = alpha2num(t)
    if len(alpha[a]) == 0:
        print(-1)
        sys.exit()
    else:
        L = len(alpha[a])        
        num = bisect.bisect_right(alpha[a],tmp)
        
        if num == L:
            base += 1
            tmp = alpha[a][0]
        else:
            tmp = alpha[a][num]
            
            
ans = N * base + tmp + 1
print(ans)

Submission status: Runtime Error

Solution code:
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def solve(positions, s, t):
    # print('{}, s = {}, t = {}'.format(positions, s, t))
    if len(t) == 0:
        return 0
    if len(positions[t[0]]) == 0:
        return -1

    i = 0
    j = 0
    while i < len(s) and j < len(t):
        candidates = positions[t[j]]
        pos = bisect.bisect_left(candidates, i)
        if pos == len(candidates):
            break
        # print('pos = {} t = {}, i = {}'.format(candidates[pos], t[j], i))
        i = candidates[pos] + 1
        j += 1

    if j == len(t):
        return i
    else:
        rest = solve(positions, s, t[j:])
        return len(s) + rest if rest != -1 else -1


def main():
    s = input()
    t = input()

    positions = defaultdict(list)
    for i in range(len(s)):
        positions[s[i]].append(i)

    # check can or cannot
    print(solve(positions, s, t))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
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()
s_unique = list(set(list(s)))
t_unique = list(set(list(t)))
s_list = list(s)*(10**5)
t_list = list(t)
s_len = len(t_list)
cnt = 0
ans = 0
for i in range(len(s_unique)):
  for j in range(len(t_unique)):
    if t_unique[j] == s_unique[i]:
      cnt += 1
      break
if cnt != len(t_unique):
  print(-1)
else:
  for k in range(s_len):
    s_index = s_list.index(t_list[k])
    ans += (s_index+1)
    del s_list[:(s_index+1)]
  print(ans)

Submission status: Runtime Error

Solution code:
def p_e():
    s = input()
    t = input()
    l = defaultdict(list)

    for i, c in enumerate(list(s)):
        l[c].append(i + 1)

    for c in list(t):
        if c not in l.keys():
            print(-1)
            exit()

    N = 0
    current = 0
    for c in list(t):
        if current >= l[c][-1]:
            current = l[c][0]
            N += 1
            continue

        for i in l[c]:
            if current < i:
                current = i
                break

    print(N * len(s) + current)


if __name__ == '__main__':
    p_e()

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())
c = 0
for i in t:
    if i in s:
        c += 1
        
if c != len(t):
    print(-1)
else:
    for k in range(10*100):
        j = 0
        for i in s:
            if i == t[j]:
                j += 1
        if j == len(t):
            print(len(s))
            break
        elif len(s) > 10**100:
            print(-1)
            break
        else:
            s.append(s[k])

Submission status: Runtime Error

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

for a in t:
  re1 = 0
  if a not in s:
    re1 += 1
s2=len(s)*len(t)
s3=s*len(t)
l=[]
j=0
m=0
k=len(t)-1
for i in range(s2):
  if t[j]==s3[i]:
    j+=1
    m+=1
    j=min(j,k)
    l.append(i)
print(-1 if re1>0 else l[-m+j]+1)

Submission status: Runtime Error

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

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

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

    i=0
    while len(t):
        if t[0] == ans[i]:
            del t[0]
        i+=1
    print(i)

Submission status: Runtime Error

Solution code:
import collections

s=input()
t=input()

if all([c in s for c in t])!=True:
	print(-1)
	exit()

i=0
ss=s
while t!="":
    if i>len(s)-1:
        ss=ss+s
    if t[0]==ss[i]:
        t=t[1:]

    i+=1
print(i)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
n_s = len(s)
n_t = len(t)

def my_index(lst, x):
    if x in lst:
        return lst.index(x)
    else:
        return -1

l = []
f = True
for i in range(n_t):
    tmp = my_index(s, t[i])
    if tmp >= 0:
        l.append(tmp)
    else:
        f = False
        break

if f:
    ans = 0
    for j in range(n_t):
        if l[j] >= l[j + 1]:
            ans += n_s
        
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

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

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

else:
    ans=s*len(t)
    t=list(t)

    i=0
    while len(t):
        if t[0] == ans[i]:
            del t[0]
        i+=1
    print(i)

Submission status: Runtime Error

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

tt = ''
index_t = 0
for i, c in enumerate(ss):
    if c == t[index_t]:
        tt += c
        index_t += 1
    if tt == t:
        print(i + 1)
        exit()

print('-1')

Submission status: Runtime Error

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

for i in range(len(t)):
  for j in range(len(s)):
    if t[i]==s[j]:
      a[i].append(j)

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 = [a for a in input()]
t = input()
d = {v:0 for v in set(t)}
for v in t:
    try: d[v] = s.index(v)
    except:
        print(-1)
        exit()

cnt = 0
for i in range(1,len(t)):
    if d[t[i-1]]>d[t[i]]: cnt+=1

if d[t[-1]]>d[t[-2]]:
    print(len(s)*cnt+s.index(t[-1])+1)
else:
    print(len(s)*(cnt-1)+s.index(t[-1])+1)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)

N,Q = map(int,input().split())
ab_list = [tuple(map(int,input().split())) for _ in range(N-1)]
px_list = [tuple(map(int,input().split())) for _ in range(Q)]

px_dict = {}
for p, x in px_list:
    if p in px_dict:
        px_dict[p] += x
    else:
        px_dict[p] = x

ab_dict = {}
for a,b in ab_list:
    if a in ab_dict:
        ab_dict[a].append(b)
    else:
        ab_dict[a] = [b]

scores = [0 for _ in range(N+1)] # 1子おおい

def add_cnt(v, score):
    # pxdictから持ってきてスコアを足す
    if v in px_dict:
        score += px_dict[v]
    # スコアを足さないこともある
    
    #今いる頂点に現在のスコアをめも
    scores[v] = score
    
    # 繋がっている頂点に今のスコアを投げる
    if v in ab_dict:
        for b in ab_dict[v]:
            add_cnt(b,score)

add_cnt(1,0)

print(" ".join(list(map(str,scores[1:]))))

Submission status: Runtime Error

Solution code:
a=input()
b=input()
i=0
j=0
cnt=0
li=len(a)-1
lj=len(b)-1
pd=1
for i in a:
    if i not in b:
        b.replace(b[b.index(i)],'')
for i in b:
    if i not in a:
        pd=0
        break
i=0
if pd==0:
    print(-1)
    exit()
while(j!=lj+1):
    if a[i]==b[j]:
        j+=1
        i+=1
        if(i==li+1):i=0
    else:
        i+=1
        if (i == li + 1): i = 0
    cnt+=1


if pd==1:print(cnt)

Submission status: Runtime Error

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

concat = '' + s

check = False
for target in t:
    if target not in list(s):
        check = True

if check:
    print(-1)
else:
    i = 0
    flag = True
    final = False
    target = t.pop(0)
    start = 0
    cnt = 0
    while flag:
        for i in range(start, len(concat)):
            if concat[i] == target:
                if final:
                    cnt = i + 1
                    flag = False
                    break
                target = t.pop(0)
                if len(t) == 0:
                    final = True
        start = len(concat)
        concat = concat + s
    print(cnt)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
alphabet_small = [chr(i) for i in range(97, 97+26)]
s = input()
t = input()
m = len(s)
n = len(t)

alpha = [[] for i in range(26)]
for i,let in enumerate(s):
    for j,al in enumerate(alphabet_small):
        if let == al:
            alpha[j].append(i)

#alpha　はsのどこに文字があるか

dp = [0 for i in range(n+1)] #i文字目までの最小
#求めるのはdp[n]
t_num = []
append = t_num.append
for let in t:
    for j,al in enumerate(alphabet_small):
        if let == al:
            t_num.append(j)

#t_num　はtの文字を数字に変換
now = -1
for i,let_num in enumerate(t_num):
    #print(i,let_num,alpha[let_num])
    if len(alpha[let_num]) == 0:
        print(-1)
        exit()
    else:
        if alpha[let_num][-1] >= now:
            q = bisect_right(alpha[let_num],now)
            next = alpha[let_num][q]
            #print(next)
            dp[i+1] = dp[i] + next - now
        else:
            next = alpha[let_num][0]
            #print(next)
            dp[i+1] = dp[i] + next - now + m
        now = next


print(dp[n])

Submission status: Runtime Error

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

x=list(s)
y=list(t)
import sys
if len(set(y)-set(x))!=0:
	print(-1)
	sys.exit()

a=[[] for _ in range(26)]
for i in range(len(s)):
	a[ord(x[i])-97].append(i)



import bisect
#t=bisect.bisect_right(res[p-1],y)

repeat=0
last=0
for i in range(len(t)):
	temp=a[ord(y[i])-97]
	if last>=temp[-1]:
		repeat+=1
		last=temp[0]
	else:
		last=temp[bisect.bisect_right(temp,last)]
	print(temp,repeat,last)
print(repeat*len(s)+last+1)

Submission status: Runtime Error

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

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

else:
    ans=s*len(t)
    t=list(t)

    i=0
    key=0
    while len(t):
        if t[0] == ans[i]:
            del t[0]
        i+=1
    print(i)

Submission status: Runtime Error

Solution code:
import sys
s = input()
t = input()
ss = s*len(t)
lt = list(t)
ans = sys.maxsize

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
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def solve(positions, s, t):
    # print('{}, s = {}, t = {}'.format(positions, s, t))
    if len(t) == 0:
        return 0
    if len(positions[t[0]]) == 0:
        return -1

    i = 0
    j = 0
    while i < len(s) and j < len(t):
        pos = list(filter(lambda idx: idx >= i, positions[t[j]]))
        # print('pos = {} t = {}, i = {}'.format(pos, t[j], i))
        if len(pos) == 0:
            break
        i = pos[0] + 1
        j += 1

    if j == len(t):
        return i
    else:
        rest = solve(positions, s, t[j:])
        return len(s) + rest if rest != -1 else -1


def main():
    s = input()
    t = input()

    positions = defaultdict(list)
    for i in range(len(s)):
        positions[s[i]].append(i)

    # check can or cannot
    print(solve(positions, s, t))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def main():
    s = SI()
    t = SI()

    d = {}
    for i, c in enumerate(s):
        if c not in d.keys():
            d[c] = [i]
        else:
            d[c].append(i)

    def init_didx():
        didx = {}
        for k in d.keys():
            didx[k] = 0
        return didx

    didx = init_didx()
    for c in set(t):
        if c not in d.keys():
            print(-1)
            return

    i_loop = 0
    currentidx = 0
    for c in t:
        # 次の文字を読む
        pos = d[c][didx[c]]
        if pos > currentidx:
            # 同じループでいけるならいく
            currentidx = pos
            didx[c] += 1
        else:
            # いけないなら次のループに
            i_loop += 1
            didx = init_didx()
            currentidx = pos

        dprint(c, i_loop, pos)

    print(len(s)*i_loop + pos + 1)

main()

Submission status: Runtime Error

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

concat = '' + s
i = 0
flag = True
final = False
target = t.pop(0)
start = 0
cnt = 0
while flag:
    for i in range(start, len(concat)):
        if concat[i] == target:
            if final:
                cnt = i + 1
                flag = False
                break
            target = t.pop(0)
            if len(t) == 0:
                final = True
    start = len(concat)
    concat = concat + s
print(cnt)

Submission status: Runtime Error

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

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
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

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

ma = len(s)*len(t)
s_lis = set(s)
t_lis = set(t)

if t_lis <= s_lis:
  k = t[0]
  c = 0
  i = 0
  j = -1
  for _ in range(ma):
    for _ in range(len(s)):
      if c > ma:
        print(-1)
        exit()
      c += 1
      j = (j + 1)%len(s)
      if t[i] == s[j]:
        i += 1
        break
    if i == len(s)+1:
      break
  print(c)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
import sys
s = input()
t = input()
ss = s*(10**100)
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
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import bisect
s = input()
t = input()
N = len(s)

next_map = sorted(zip(s*2,range(N*2)))
br = bisect.bisect_right
ans = 0
i = 0
for c in t:
    map_idx = br(next_map,(c,i))
    a,j = next_map[map_idx]
    if a != c :
        ans = -2
        break
    ans += j - i
    i = j%N
ans += 1
print(ans)

Submission status: Runtime Error

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

x=list(s)
y=list(t)
import sys
if len(set(y)-set(x))!=0:
	print(-1)
	sys.exit()

a=[[] for _ in range(26)]
for i in range(len(s)):
	a[ord(x[i])-97].append(i)



import bisect
#t=bisect.bisect_right(res[p-1],y)

repeat=0
last=0
for i in range(len(t)):
	temp=a[ord(y[i])-97]
	if last>max(temp):
		repeat+=1
		last=min(temp)
	else:
		last=temp[bisect.bisect_right(temp,last)]
	#print(temp,repeat,last)
print(repeat*len(s)+last+1)

Submission status: Runtime Error

Solution code:
import bisect
try:
    S,T = input(),input()
    lenS = len(S)
    alp = [[]for i in range(26)]
    for i in range(len(S)):
        alp[ord(S[i])-97].append(i)

    l = [alp[ord(T[0])-97][0]]
    for c in T[1:]:
        A = alp[ord(c)-97]
        l.append(A[bisect.bisect_left(A,l[-1])%len(A)])

    ans = 0
    for i in range(len(l)-1):
        if l[i] > l[i+1]:
            ans += lenS
    print(ans+l[-1]+1)
except IndexError:
    print(-1)

Submission status: Runtime Error

Solution code:
s = input() # これを繰り返しまくる
t = input() # これを探す

s_set = set(s)
ss = s * len(t)

if all((t_ in s_set) for t_ in t):
    current_index = 0

    for t_ in t:
        current_index = ss.find(t_, current_index) + 1
    print(current_index)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def solve(s, t):
    # print('{} {}'.format(s, t))
    if len(t) == 0:
        return 0
    if s.find(t[0]) == -1:
        return -1
    i = 0
    j = 0
    while i < len(s) and j < len(t):
        target = s[i:]
        pos = target.find(t[j])
        # print('pos = {} t = {}'.format(pos, t[j]))
        if pos == -1:
            break
        i += pos + 1
        j += 1

    if j == len(t):
        return i
    else:
        rest = solve(s, t[j:])
        return len(s) + rest if rest != -1 else -1


def main():
    s = input()
    t = input()

    # check can or cannot
    print(solve(s * 10, t))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = [a for a in input()]
t = input()
cnt,i = 0,1
while i<len(t):
    try:
        if s.index(t[i])<s.index(t[i-1]): cnt += 1
        i+=1
    except:
        print(-1)
        exit()
print(cnt*len(s)+s.index(t[-1])+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:
                ans = i+1
                break
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "T" : "F");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

int main() {
  ios::sync_with_stdio(0); cin.tie(0);

  string s, t; cin >> s >> t;
  {
    set<char> S, T;
    for(char c: s) S.emplace(c);
    for(char c: t) T.emplace(c);
    for(char c: T)
      if( S.find(c) == S.end() ) {
	cout << -1 << nl;
	return 0;
      }
  }

  int n = s.length();
  int nxt[256][n];

  for(char c='a'; c<='z'; c++) {
    vi pos;
    fill(nxt[c], nxt[c]+n, n);
    for(int zz=0; zz<2; zz++) {
      for(int i=n-1; i>=0; i--) {
	nxt[c][i] = nxt[c][ (i+1) % n ];
	if( s[i] == c ) nxt[c][i] = i;
      }
    }
  }

  int pos = 0, i = 0;
  for(; i<(int)t.length(); i++) {
    for(; i<(int)t.length() and t[i] == s[pos % n]; pos++, i++);
    if( i == (int)t.length() ) break;
    int npos = nxt[ t[i] ][pos % n];
    // pr(i, t[i], pos % n, npos);
    if( npos > (pos % n) ) pos += npos - (pos % n);
    else pos += n - (pos%n) + npos;
    i--;
    // pr(pos);
  }
  cout << pos << endl;

}

Submission status: Runtime Error

Solution code:
S = input()
T = input()
if set(T)-set(S):
    print(-1)
    exit()
ans = 0
for t in T:
    while True:
        if S[ans]==t:break
        ans+=1
    S+=S
print(ans+1)

Submission status: Runtime Error

Solution code:
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def solve(s, t):
    # print('{} {}'.format(s, t))
    if len(t) == 0:
        return 0
    if s.find(t[0]) == -1:
        return -1
    i = 0
    j = 0
    while i < len(s) and j < len(t):
        target = s[i:]
        pos = target.find(t[j])
        # print('pos = {} t = {}'.format(pos, t[j]))
        if pos == -1:
            break
        i += pos + 1
        j += 1

    if j == len(t):
        return i
    else:
        rest = solve(s, t[j:])
        return len(s) + rest if rest != -1 else -1

def main():
    s = input()
    t = input()

    # check can or cannot
    print(solve(s, t))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

ti = 0
si = 0
tl = len(t)
sl = len(s)
count = 0
found = False
while ti < tl:
	if s[si] == t[ti]:
#		print(s[si])
		si += 1
		ti += 1
		found = True
	else:
		si += 1
		if si == sl:
			if not found:
				count = -1
				break
			si = 0
			found = False
	count += 1
print(count)