ZhenlongDai/ACPR huggingface dataset:
Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect_right

s = input()
t = input()

table = {}
for i in range(len(s)):
    if s[i] in table:
        table[s[i]].append(i)
    else:
        table[s[i]] = [i]

dup = 0
prev = 0
for i in range(len(t)):
    if t[i] not in table:
        print(-1)
        exit()

    ind_list = table[t[i]]
    if prev < ind_list[-1]:
        temp = bisect_right(ind_list, prev)
        prev = ind_list[temp]
        continue
    else:
        dup += 1
        prev = ind_list[0]

print(dup * len(s) + prev + 1)


Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
from bisect import bisect_right

s = input()
t = input()

table = {}
for i in range(len(s)):
    if s[i] in table:
        table[s[i]].append(i)
    else:
        table[s[i]] = [i]

dup = 0
prev = -1
for i in range(len(t)):
    if t[i] not in table:
        print(-1)
        exit()

    ind_list = table[t[i]]
    if prev < ind_list[-1]:
        temp = bisect_right(ind_list, prev)
        prev = ind_list[temp]
        continue
    else:
        dup += 1
        prev = ind_list[0]

print(dup * len(s) + prev + 1)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
s=list(input())
t=list(input())
N=len(s)
sd={x:[] for x in sorted(set(s))}
if not set(t) <= set(sd.keys()):
    print(-1)
    exit()

for i,c in enumerate(s):
    sd[c].append(i)
index=0
ans=0
for c in t:
    i=bisect.bisect_left(sd[c],index+1)

    if i==len(sd[c]):
        ans+=1
        i=bisect.bisect_left(sd[c],0)
    index=sd[c][i]
print(ans*N+index+1)


Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
import bisect
s=list(input())
t=list(input())
N=len(s)
sd={x:[] for x in sorted(set(s))}
if not set(t) <= set(sd.keys()):
    print(-1)
    exit()

for i,c in enumerate(s):
    sd[c].append(i)
index=-1
ans=0
for c in t:
    i=bisect.bisect_left(sd[c],index+1)

    if i==len(sd[c]):
        ans+=1
        i=bisect.bisect_left(sd[c],0)
    index=sd[c][i]
print(ans*N+index+1)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()

c=0
j=-1
k=1


for i in range(0,len(t)):
  while True:
    j=j+1
    c=c+1

    if t[i:i+1]==s[j:j+1]:
      
      k=1
      break
    else:
      
      k=k+1
      if j>len(s)-1:
        
        j=0
      
      if k>len(s)+1:
        print("-1")
        exit()
print(c)


Failing test case input:
contest
sentence

Expected output:
33

Actual output:
-1


Fixed submission (verdict: Accepted):
s = input()
t = input()

x = len(s)
y = len(t)

a = 0
b = x
c = 0
a0 = 0


for i in range(0,y):
  while True:
    
    a=s.find(t[i:i+1],a0)+1
    if a <= 0:
      a=s.find(t[i:i+1])+1
    if a <= 0:
      print("-1")
      exit()
    
    if a<=a0:
      c=c+a+b
    else:
      c=c+a-a0
    b=x-a
    a0=a
    break
    
print(c)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

S = input()
T = input()

d = [[] for _ in range(27)]
alpha2num = lambda c: ord(c) - ord("a") + 1

for i, s in enumerate(S):
    d[alpha2num(s)].append(i)

idx = 0
ans = 1
for t in T:
    dl = d[alpha2num(t)]
    if not(dl):
        ans = -1
        break
    insert_idx = bisect.bisect_right(dl, idx)
    if insert_idx == len(dl):
        ans += (len(S) - idx + dl[0])
        idx = dl[0]
    else:
        ans += (dl[insert_idx] - idx)
        idx = dl[insert_idx]

print(ans)

Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
import bisect

S = input()
T = input()

d = [[] for _ in range(27)]
alpha2num = lambda c: ord(c) - ord("a") + 1

for i, s in enumerate(S):
    d[alpha2num(s)].append(i)

idx = -1
l = 0
ans = 0
for t in T:
    dl = d[alpha2num(t)]
    if not dl:
        ans = -1
        break
    insert_idx = bisect.bisect_right(dl, idx)
    if insert_idx == len(dl):
        l += 1
        idx = dl[0]
    else:
        idx = dl[insert_idx]
    ans = l * len(S) + idx + 1

print(ans)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import string
import bisect

S, T = input(), input()
lS, lT = len(S), len(T)

l = {s: [] for s in string.ascii_lowercase}
for i in range(lS):
    l[S[i]].append(i)

id, ans = 0, 0
for i in range(lT):
    if len(l[T[i]]) == 0:
        print(-1)
        exit()
    else:
        tmp = l[T[i]][(bisect.bisect(l[T[i]], id)) % len(l[T[i]])]
        if id >= tmp:
            ans += lS
        id = tmp

print(ans + id + 1)


Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
import string
import bisect

S, T = input(), input()
lS, lT = len(S), len(T)

l = {s: [] for s in string.ascii_lowercase}
for i in range(lS):
    l[S[i]].append(i)

id, ans = -1, 0
for i in range(lT):
    if len(l[T[i]]) == 0:
        print(-1)
        exit()
    else:
        tmp = l[T[i]][(bisect.bisect(l[T[i]], id)) % len(l[T[i]])]
        if id >= tmp:
            ans += lS
        id = tmp

print(ans + id + 1)
Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import collections

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

    ns, nt = len(s), len(t)
    cs, ct = set(list(s)), set(list(t))
    for c in ct:
        if c not in cs: return -1

    d = collections.defaultdict(list)
    for i in range(ns):
        if s[i] in ct: d[s[i]].append(i)

    i = 0
    for c in t:
        while d[c][0] <= i:
            d[c].append(d[c].pop(0)+ns)
        i = d[c][0]
    return i+1


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

Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
import collections
import bisect

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

    ns, nt = len(s), len(t)
    cs, ct = set(list(s)), set(list(t))
    for c in ct:
        if c not in cs: return -1

    
    
    
    
    
    
    

    d = collections.defaultdict(list)
    for i in range(ns):
        if s[i] in ct: d[s[i]].append(i)
    
    i = 0
    for c in t:
        
        j = i % ns
        k = bisect.bisect_left(d[c], j)
        if k == len(d[c]):
            i = (i 
        else:
            if j <= d[c][k]:
                i = (i 
            else:
                i = (i 
        
        i += 1
    return i
    


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

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()
lent = len(t)
tcount = 0
snow = 0
count = 0
flag = True
if t[0] not in s:
    print(-1)
else:
    snow = s.index(t[0])
    while True:
        tcount += 1
        if tcount == lent:
            break
        if t[tcount] in s[snow+1:]:
            snow = s[snow+1:].index(t[tcount])+snow
        elif t[tcount] in s:
            snow = s.index(t[tcount])
            count += 1
        else:
            flag = False
            break
    if flag:
        print(count*len(s) + s.index(t[-1])+1)
    else:
        print(-1)

Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
s = input()
t = input()
lent = len(t)
tcount = 0
snow = 0
count = 0
flag = True
if t[0] not in s:
    print(-1)
else:
    snow = s.index(t[0])
    while True:
        tcount += 1
        if tcount == lent:
            break
        if t[tcount] in s[snow+1:]:
            snow = s[snow+1:].index(t[tcount])+snow+1
        elif t[tcount] in s:
            snow = s.index(t[tcount])
            count += 1
        else:
            flag = False
            break
    if flag:
        print(count*len(s) + snow+1)
    else:
        print(-1)
Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
t = input()

from collections import defaultdict
pos = defaultdict(list)
for i, char in enumerate(s):
    pos[char].append(i)

from bisect import bisect_left

ans = 0
before = -1
flag = True
for char in t:
    if pos[char] == []:
        flag = False
        break

    if before > pos[char][-1]:
        ans += len(s)
        before = pos[char][0]
    else:
        idx = bisect_left(pos[char], before)
        before = pos[char][idx]

if flag:
    print(ans + before + 1)
else:
    print(-1)


Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
s = input()
t = input()

from collections import defaultdict
pos = defaultdict(list)
for i, char in enumerate(s):
    pos[char].append(i)

from bisect import bisect_left

ans = 0
before = -1
flag = True
for char in t:
    if pos[char] == []:
        flag = False
        break

    if before > pos[char][-1]:
        ans += len(s)
        before = pos[char][0] + 1
    else:
        idx = bisect_left(pos[char], before)
        before = pos[char][idx] + 1

if flag:
    print(ans + before)
else:
    print(-1)

Problem: p02937
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from bisect import*
s=input()
t=input()
n=len(s)
d=dict(zip([chr(i+97) for i in range(26)],[[] for _ in range(26)]))
for i,j in enumerate(s,1):
  d[j]+=[i]
ans=0
cnt=0
for i in t:
  if d[i]:
    j=bisect_left(d[i],ans)
    if j==len(d[i]):
      cnt+=1
      ans=d[i][0]
    else:ans=d[i][j]
  else:
    cnt,ans=0,-1
    break
print(cnt*n+ans)

Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
from bisect import*
s=input()
t=input()
n=len(s)
d=dict(zip([chr(i+97) for i in range(26)],[[] for _ in range(26)]))
for i,j in enumerate(s,1):
  d[j]+=[i]
ans=0
cnt=0
for i in t:
  if d[i]:
    j=bisect(d[i],ans)
    if j==len(d[i]):
      cnt+=1
      ans=d[i][0]
    else:ans=d[i][j]
  else:
    cnt,ans=0,-1
    break
print(cnt*n+ans)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
s = input()
t = input()
l = {}
for c in set(t):
    count = s.count(c)
    if count > 0:
        cl = []
        for i in range(count):
            cl.append(s.find(c, (0 if i==0 else cl[i-1] + 1)))
        l[c] = cl
    else:
        print("-1")
        sys.exit()
result = 0
for c in t:
    for i in l[c]:
        if i > result % len(s):
            result += i - (result % len(s))
            break
    else:
        result += len(s) - (result % len(s)) + l[c][0]
print(result+1)

Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
from bisect import bisect
import sys
s = input()
t = input()
l = {}
for c in set(t):
    cl = [s.find(c)]
    if cl[0] == -1:
        print("-1")
        sys.exit()
    while True:
        i = s.find(c, cl[-1] + 1)
        if (i == -1):
            break
        cl.append(i)
    l[c] = cl
ofs = -1
count = 0
for c in t:
    lens = len(s)
    ref = bisect(l[c], ofs)
    if ref < len(l[c]):
        ofs = l[c][ref]
    else:
        ofs = l[c][0]
        count += 1
print(lens * count + ofs + 1)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
t = input()


N = len(s)
next = [dict() for _ in range(2 * N)]
last = dict()
for i, c in enumerate(s + s):
    last_c = last[c] if last.get(c) is not None else -1
    for j in range(last_c + 1, i + 1):
        next[j][c] = i
    last[c] = i

i = 0
for c in t:
    cur = i % N
    if next[cur].get(c) is None:
        print(-1)
        exit(0)
    n = next[cur][c]
    i += n - cur
print(i + 1)

Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
s = input()
t = input()


N = len(s)
next = [dict() for _ in range(N)]
last = dict()
for i, c in enumerate(s + s):
    last_c = last[c] if last.get(c) is not None else -1
    for j in range(last_c + 1, min(i + 1, N)):
        next[j][c] = i % N
    last[c] = i

i = -1
for c in t:
    cur = i % N
    cur1 = (i + 1) % N
    if next[cur1].get(c) is None:
        print(-1)
        exit(0)
    n = next[cur1][c]
    if cur < n:
        i += n - cur
    elif n < cur:
        i += N - (cur - n)
    else:
        i += N
print(i + 1)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()

ct = 0
k = 0
for i in t:
    f = s.find(i, k)
    if f < 0:
        ct += 1
        f = s.find(i)
        if f == -1:
            print(-1)
            break
        else:
            k = f
    else:
        k = f
else:
    print(ct*len(s)+k+1)


Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
s = input()
t = input()

ct = 0
k = 0
for i in t:
    f = s.find(i, k)
    if f < 0:
        ct += 1
        f = s.find(i)
        if f == -1:
            print(-1)
            break
        else:
            k = f+1
    else:
        k = f+1
else:
    print(ct*len(s)+k)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()
t_long = len(t)
position = [0] * t_long
rep = 0

if set(t) <= set(s):
    position[0] = s.find(t[0])
    for i in range(1, t_long):
        if s.find(t[i], position[i - 1] + 1) > -1:
            position[i] = s.find(t[i], position[i - 1] + 1)
        else:
            position[i] = s.find(t[i])
    for k in range(t_long - 1):
        if position[k + 1] < position[k]:
            rep += 1
    print(rep * len(s) + position[t_long - 1] + 1)
else:
    print(-1)

Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
s = input()
t = input()
t_long = len(t)
position = [0] * t_long
rep = 0

if set(t) <= set(s):
    position[0] = s.find(t[0])
    for i in range(1, t_long):
        if s.find(t[i], position[i - 1] + 1) > -1:
            position[i] = s.find(t[i], position[i - 1] + 1)
        else:
            position[i] = s.find(t[i])
    for k in range(t_long - 1):
        if position[k + 1] <= position[k]:
            rep += 1
    print(rep * len(s) + position[t_long - 1] + 1)
else:
    print(-1)

Problem: p02937
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from bisect import bisect_left

S = input()
T = input()

ss = set(list(S))
st = set(list(T))
if not (st <= ss):
    print(-1)
    exit()
alpha = {chr(97+i): [] for i in range(26)}
for i, s in enumerate(S):
    alpha[s].append(i+1)
n = len(S)
now = 0
ans = 0
for t in T:
    if alpha[t][-1] < now:
        ans += (n - now) + alpha[t][0]
        now = alpha[t][0]
    else:
        i = bisect_left(alpha[t], now)
        ans += alpha[t][i] - now
        now = alpha[t][i]
print(ans)


Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
from bisect import bisect_left

S = input()
T = input()

ss = set(list(S))
st = set(list(T))
if not (st <= ss):
    print(-1)
    exit()
alpha = {chr(97+i): [] for i in range(26)}
for i, s in enumerate(S):
    alpha[s].append(i+1)
n = len(S)
now = 0
ans = 0
for t in T:
    if alpha[t][-1] <= now:
        ans += (n - now) + alpha[t][0]
        now = alpha[t][0]
    else:
        i = bisect_left(alpha[t], now+1)
        ans += alpha[t][i] - now
        now = alpha[t][i]
print(ans)
Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect_left
s, t = [ord(c)-ord('a') for c in input()], [ord(c)-ord('a') for c in input()]
cnt = [[] for i in range(26)]
for i in range(len(s)):
    cnt[s[i]].append(i)
    cnt[s[i]].append(i+len(s))
ans = 0
p = 0
for i in range(len(t)):
    c = t[i]
    if (len(cnt[c]) == 0):
        
        exit()
    next = bisect_left(cnt[c], p)
    p = cnt[c][next] + 1
    if (p >= len(s)):
        p -= len(s)
        ans += len(s)
ans += p
print(ans) 


Failing test case input:
tscslme
prhgarmgomp

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
from bisect import bisect_left
s, t = [ord(c)-ord('a') for c in input()], [ord(c)-ord('a') for c in input()]
cnt = [[] for i in range(26)]
for i in range(len(s)):
    cnt[s[i]].append(i)
    cnt[s[i]].append(i+len(s))
for i in range(26):
    cnt[i] = sorted(cnt[i])
ans = 0
p = 0
for i in range(len(t)):
    c = t[i]
    if (len(cnt[c]) == 0):
        print('-1')
        exit()
    next = bisect_left(cnt[c], p)
    p = cnt[c][next] + 1
    if (p >= len(s)):
        p -= len(s)
        ans += len(s)
ans += p
print(ans)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()
T = input()
dic = {}
for i,s in enumerate(S):
  if s not in dic:
    dic[s] = [i]
  else:
    dic[s].append(i)

ind = -1
loop = 0
for t in T:
  if t not in dic:
    ans = -1
    break
  if dic[t][-1]<ind:
    loop += 1
    ind = dic[t][0]
  else:
    for i in dic[t]:
      if i > ind:
        ind = i
        break
  

else:
  ans = len(S)*loop+ind+1
          
print(ans)   




Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
S = input()
T = input()
dic = {}
for i,s in enumerate(S):
  if s not in dic:
    dic[s] = [i]
  else:
    dic[s].append(i)

ind = -1
loop = 0
import bisect
for t in T:
  if t not in dic:
    ans = -1
    break
  if dic[t][-1]<=ind:
    loop += 1
    ind = dic[t][0]
  else:
    i = bisect.bisect_right(dic[t],ind)
    ind = dic[t][i]
  

else:
  ans = len(S)*loop+ind+1
          
print(ans)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
t=input()

ans1=0
ans2=0

ss=s*2

for i in range(len(t)):
    a=ss.find(t[i],ans2)
    if a==-1:
        ans=-1
        break
    if a>=len(s):
        ans1+=1
    ans2=a%(len(s))+1
ans=ans1*len(s)+ans2
print(ans)
        

Failing test case input:
emlscst
pmogmraghrp

Expected output:
-1


Actual output:
0


Fixed submission (verdict: Accepted):
s=input()
t=input()

ans1=0
ans2=0

ss=s*2

for i in range(len(t)):
    a=ss.find(t[i],ans2)
    if a==-1:
        ans=-1
        break
    if a>=len(s):
        ans1+=1
    ans2=a%(len(s))+1
    ans=ans1*len(s)+ans2
print(ans)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import*
from bisect import*

s=input()
t=input()
slen=len(s)
d=defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)

nowplace=0
roop=0
for c in t:
    if not d[c]:
        print(-1)
        exit()
    i=bisect(d[c],nowplace)
    if len(d[c])==i:
        roop+=1
        nowplace=d[c][0]
    else:
        nowplace=d[c][i]

print(roop*slen+nowplace+1)

Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
from collections import*
from bisect import*

s=input()
t=input()
slen=len(s)
d=defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)

nowplace=-1
roop=0
for c in t:
    if not d[c]:
        print(-1)
        exit()
    i=bisect(d[c],nowplace)
    if len(d[c])==i:
        roop+=1
        nowplace=d[c][0]
    else:
        nowplace=d[c][i]

print(roop*slen+nowplace+1)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
s = input()
t = input()
d = { c: [] for c in t }
for i, c in enumerate(s):
  if c in d:
    d[c].append(i)
for dc in d.values():
  dc.sort()

n = -1
ans = 0

for j, c in enumerate(t):
  l = d[c]
  if l:
    i = bisect.bisect_right(l, n)
    if i == len(l):
      ans += len(s)
      n = l[0]
    elif j == len(t) - 1:
      ans += l[i]+1
    else:
      n = l[i]
  else:
    ans = -1
    break

print(ans)


Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
import bisect
s = input()
t = input()
d = { c: [] for c in t }
for i, c in enumerate(s):
  if c in d:
    d[c].append(i)
for dc in d.values():
  dc.sort()

n = -1
ans = 0


for j, c in enumerate(t):
  l = d[c]
  if l:
    i = bisect.bisect_right(l, n)
    if i == len(l):
      ans += len(s)
      n = l[0]
    else:
      n = l[i]
    if j == len(t) - 1:
      if i == len(l):
        ans += l[0] + 1
      else:
        ans += l[i]+1
  else:
    ans = -1
    break

print(ans)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

S = input()
T = input()

SS = S * 2
SSpos = {}
for i in range(len(SS)):
  if SS[i] in SSpos:
    SSpos[SS[i]].append(i)
  else:
    SSpos[SS[i]] = [i]


ans = 1
i = 0
for t in T:
  if t not in SS:
    print(-1)
    exit()
  j = bisect.bisect_left(SSpos[t],i)
  ans += SSpos[t][j] - i
  
  i = SSpos[t][j]
  if i >= len(S):
    i -= len(S)
print(ans)


Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
import bisect

S = input()
T = input()

Sset = set(list(S))
Tset = set(list(T))
if len(Tset-Sset) > 0:
  print(-1)
  exit()

SS = S * 2
SSpos = {}
for i in range(len(SS)):
  if SS[i] in SSpos:
    SSpos[SS[i]].append(i)
  else:
    SSpos[SS[i]] = [i]
for i in SSpos:
  SSpos[i].sort()


ans = 0
i = 0
for t in T:
  j = bisect.bisect_left(SSpos[t],i)
  ans += SSpos[t][j] - i + 1
  
  i = SSpos[t][j] + 1
  if i >= len(S):
    i -= len(S)
print(ans)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_right
s=input()
t=input()
dic={}
n=len(s)
for i in range(n):
	if s[i] in dic:
		dic[s[i]].append(i)
	else:
		dic[s[i]]=[i]
k=0
r=0
for i in t:
	if i in dic:
		a=bisect_right(dic[i],k)
		if a==len(dic[i]):
			r+=1
			k=dic[i][0]
		else:
			k=dic[i][a]
	else:
		print(-1)
		exit()
print(r*n+k+1)


Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
from bisect import bisect_right
s=input()
t=input()
dic={}
n=len(s)
for i in range(n):
	if s[i] in dic:
		dic[s[i]].append(i)
	else:
		dic[s[i]]=[i]
k=-1
r=0
for i in t:
	if i in dic:
		a=bisect_right(dic[i],k)
		if a==len(dic[i]):
			r+=1
			k=dic[i][0]
		else:
			k=dic[i][a]
	else:
		print(-1)
		exit()
print(r*n+k+1)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from string import ascii_lowercase
from bisect import bisect_right
s=input()
t=input()
p={c: [] for c in s}
for x,c in enumerate(s):
    p[c].append(x)
z=0
l=-1
for c in t:
    if c not in p:
        print(-1)
        break
    x=bisect_right(p[c],1)
    if x==len(p[c]):
        x=0
        z+=1
    l=p[c][x]
else:
    print(z*len(s)+l+1)


Failing test case input:
toncest
sentence

Expected output:
33


Actual output:
5


Fixed submission (verdict: Accepted):
from string import ascii_lowercase
from bisect import bisect_right
s = input()
t = input()
p = {c: [] for c in s}
for x, c in enumerate(s):
    p[c].append(x)
z = 0
l = -1
for c in t:
    if c not in p:
        print(-1)
        break
    x = bisect_right(p[c], l)
    if x == len(p[c]):
        x = 0
        z += 1
    l = p[c][x]
else:
    print(z * len(s) + l + 1)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

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

if set(t).issubset(set(s)):
    p = -1
    r = 0
    
    for i in t:
        p = s.find(i, p+1)
        if p == -1:
            r += 1
            p = s.find(i)
        
    print(p + 1 + len(s)*r)
    
else:
    print(-1)

Failing test case input:
csnoett
son

Expected output:
10


Actual output:
16


Fixed submission (verdict: Accepted):
s = str(input())
t = str(input())

if set(t).issubset(set(s)):
    p = -1
    r = 0
    
    for i in t:
        p = s.find(i, p+1)
        if p == -1:
            r += 1
            p = s.find(i)
        
    print(p + 1 + len(s)*r)
    
else:
    print(-1)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

s = input()
t = list(input())

string = s
length = 1

for i in t:
	if s.find(i)==-1:
		print(-1)
		sys.exit()
	if string.find(i)==-1:
		string = string + s
		length += 1
	string = string[string.find(i) : ]
	
print(length*len(s)-len(string)+1)

Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
import sys

s = input()
t = list(input())

string = s
length = 1

for i in range(len(t)):
	if s.find(t[i])==-1:
		print(-1)
		sys.exit()
	if string.find(t[i])==-1:
		string = s
		length += 1
	string = string[string.find(t[i])+1 : ]
	
print(length*len(s)-len(string))

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect_left

s = input()
t = input()

l = len(s)

ss = s * 2
let = [[] for _ in range(26)]
for i, e in enumerate(ss, 1):
    idx = ord(e) - ord("a")
    let[idx].append(i)

for e in t:
    idx = ord(e) - ord("a")
    if not let[idx]:
        print(-1)
        exit()

i = 1
times = 0
for e in t:
    j = ord(e) - ord("a")
    choose = bisect_left(let[j], i)
    q, i = divmod(let[j][choose], l)
    times += q

ans = times * l + i
print(ans)


Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
from bisect import bisect_left

s = input()
t = input()

l = len(s)

ss = s * 2
let = [[] for _ in range(26)]
for i, e in enumerate(ss, 1):
    idx = ord(e) - ord("a")
    let[idx].append(i)

for e in t:
    idx = ord(e) - ord("a")
    if not let[idx]:
        print(-1)
        exit()

i = 1
times = 0
for e in t:
    j = ord(e) - ord("a")
    choose = bisect_left(let[j], i)
    q, r = divmod(let[j][choose], l)
    times += q
    i = r + 1

ans = times * l + i - 1
print(ans)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict as dd
from bisect import bisect_left
s = input()
t = input()

cmap = dd(list)
for i, c in enumerate(s):
    cmap[c].append(i)
cmap = dict(cmap)
a = 0
q = 0
for c in t:
    try:
        j = bisect_left(cmap[c], a % len(s))
    except:
        print(-1)
        exit()
    if j < len(cmap[c]):
        a = cmap[c][j]
    else:
        q += 1
        a = cmap[c][-1]

print(len(s)*q + a + 1)


Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
from collections import defaultdict as dd
from bisect import bisect_right
s = input()
t = input()
n = len(s)
cmap = dd(list)
for i, c in enumerate(s):
    cmap[c].append(i)
for i, c in enumerate(s):
    cmap[c].append(i+n)
cmap = dict(cmap)
a = 0
pos = -1
for c in t:
    try:
        i = bisect_right(cmap[c], pos)
        ind = cmap[c][i]
    except:
        print(-1)
        exit()
    if ind >= n:
        a += n
        pos = ind - n
    else:
        pos = ind
print(a + pos + 1)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(s, t):
    prev = {}
    follow = [{} for _ in range(len(s) + 1)]
    for i, c in enumerate(s, start=1):
        for d, j in prev.items():
            if c not in follow[j]:
                follow[j][c] = i
        if c not in prev:
            follow[0][c] = i
        prev[c] = i
    ans = 0
    i = 0
    for c in t:
        if c not in follow[i]:
            if c not in follow[0]:
                return -1
            ans += len(s)
            i = follow[0][c]
            continue
        i = follow[i][c]
    return ans + i


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


Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
21


Fixed submission (verdict: Accepted):
def solve(s, t):
    ls = len(s)
    nxt = {}
    follow = [{} for _ in range(ls + 1)]
    for i, c in enumerate(s[::-1]):
        i = ls - i
        follow[i] = nxt.copy()
        nxt[c] = i
    follow[0] = nxt.copy()
    ans = 0
    i = 0
    for c in t:
        if c not in follow[i]:
            if c not in follow[0]:
                return -1
            ans += len(s)
            i = follow[0][c]
            continue
        i = follow[i][c]
    return ans + i


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

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
n = len(s)
s *= 2
t = input()
l = [[]for i in range(26)]

for i, c in enumerate(s):
    l[ord(c) - ord('a')].append(i)


from bisect import *

shukai = 0
now = 0
for c in t:
    x = ord(c) - ord('a')
    if len(l[x]) == 0:
        print(-1)
        exit()
    now = l[x][bisect_left(l[x], now)]
    if now >= n:
        now -= n
        shukai += 1


print(shukai * n + now + 1)


Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
s = input()
n = len(s)
l = [[]for i in range(26)]

for i, c in enumerate(s * 2):
    l[ord(c) - ord('a')].append(i)


from bisect import *

shukai = 0
now = 0

t = input()
for c in t:
    x = ord(c) - ord('a')
    if len(l[x]) == 0:
        print(-1)
        exit()
    i = bisect_left(l[x], now)
    now = l[x][i] + 1

    if now >= n:
        now -= n
        shukai += 1


print(shukai * n + now)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_right, bisect_left
s = [ord(i) - ord("a") for i in input()]
t = [ord(i) - ord("a") for i in input()]
index = [[] for _ in range(26)]

for i, x in enumerate(s):
    index[x].append(i)


l_s = len(s)

for x in index:
    if x:
        x.append(x[0] + l_s)

print(index)

cnt = 0
for r in t:
    seq = index[r]
    if not seq:
        cnt = -2
        break
    i = cnt % l_s
    j = bisect_right(seq, i)
    cnt += seq[j] - i

print(cnt+1)




Failing test case input:
ksbttme
pomaorhghrp

Expected output:
-1


Actual output:
[[], [2, 9], [], [], [6, 13], [], [], [], [], [], [0, 7], [], [5, 12], [], [], [], [], [], [1, 8], [3, 4, 10], [], [], [], [], [], []]
-1


Fixed submission (verdict: Accepted):
from bisect import bisect_right, bisect_left
s = [ord(i) - ord("a") for i in input()]
t = [ord(i) - ord("a") for i in input()]
index = [[] for _ in range(26)]

for i, x in enumerate(s):
    index[x].append(i)


l_s = len(s)

for x in index:
    if x:
        x.append(x[0] + l_s)

cnt = -1
for r in t:
    seq = index[r]
    if not seq:
        cnt = -2
        break
    i = cnt % l_s
    j = bisect_right(seq, i)
    cnt += seq[j] - i

print(cnt+1)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
slist = input()
tlist = input()
scounter = 0
slength=len(slist)
slist=slist+slist
preposition=-1
for tchar in tlist:
    preposition=slist.find(tchar, preposition+1)
    if preposition==-1:
        scounter=-1
        break
    elif preposition>slength:
        scounter+=slength
        preposition-=slength
    print(tchar, scounter, preposition)
if (scounter==-1):
    print(scounter)
else:
    print(scounter+preposition+1)

Failing test case input:
bueomtt
oos

Expected output:
-1


Actual output:
o 0 3
o 7 3
-1


Fixed submission (verdict: Accepted):
slist = input()
tlist = input()
scounter = 0
slength=len(slist)
slist=slist+slist
preposition=-1
for tchar in tlist:
    preposition=slist.find(tchar, preposition+1)
    if preposition==-1:
        scounter=-1
        break
    elif preposition>=slength:
        scounter+=slength
        preposition-=slength
    
if (scounter==-1):
    print(scounter)
else:
    print(scounter+preposition+1)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()
idxs = defaultdict(list)

for i, c in enumerate(s):
    idxs[c].append(i)
for i, c in enumerate(s):
    idxs[c].append(len(s) + i)

ans, cur_i = 0, 0
for c in t:
    if c not in idxs: print(-1); break
    a = idxs[c]
    nxt = a[bisect_right(a, cur_i)]
    ans += nxt - cur_i
    cur_i = nxt % len(s)
else: print(ans+1)


Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()
idxs = defaultdict(list)

for i, c in enumerate(s):
    idxs[c].append(i)
for i, c in enumerate(s):
    idxs[c].append(len(s) + i)

ans, cur_i = -1, -1
for c in t:
    if c not in idxs: print(-1); break
    a = idxs[c]
    nxt = a[bisect_right(a, cur_i)]
    ans += nxt - cur_i
    cur_i = nxt % len(s)
else: print(ans+1)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
from bisect import bisect_left

s = input()
n = len(s)
s = s + s
t = input()
if set(t) - set(s):
	print(-1)
	exit()
d = defaultdict(list)
for i in range(2 * n):
	d[s[i]] += [i]
cur = tot = 0
for c in t:
	x = d[c][bisect_left(d[c], cur)]
	if x < n:
		cur = x
	else:
		cur = x - n
		tot += n
tot += cur + 1
print(tot)

Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
from collections import defaultdict
from bisect import bisect_left

s = input()
n = len(s)
s = s + s
t = input()
if set(t) - set(s):
	print(-1)
	exit()
d = defaultdict(list)
for i in range(2 * n):
	d[s[i]] += [i]
cur = tot = 0
for c in t:
	x = d[c][bisect_left(d[c], cur)]
	if x < n:
		cur = x + 1
	else:
		cur = x - n + 1
		tot += n
tot += cur
print(tot)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    S=input()
    T=input()
    if(set(T)-set(S)):
        print(-1)
        return
    n=len(S)
    C=[[] for _ in range(26)]
    for i,s in enumerate(S*2): C[ord(s)-97].append(i)
    from bisect import bisect_left
    ans=0
    for s in T:
        j=bisect_left(C[ord(s)-97],(ans+1)%n)
        ans+=(C[ord(s)-97][j]-(ans+1)%n)+1
    print(ans+1)
resolve()

Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    S=input()
    T=input()
    if(set(T)-set(S)):
        print(-1)
        return
    n=len(S)
    C=[[] for _ in range(26)]
    for i,s in enumerate(S*2): C[ord(s)-97].append(i)
    from bisect import bisect_left
    ans=0
    for s in T:
        j=bisect_left(C[ord(s)-97],ans%n)
        ans+=C[ord(s)-97][j]-ans%n+1
    print(ans)
resolve()
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
from bisect import bisect_left

s = input()
t = input()
idxs = defaultdict(list)

for i, c in enumerate(s):
    idxs[c].extend([len(s) * j + i for j in range(len(t))])

for v in idxs.values(): v.sort()

ans = 0

for c in t:
    if c not in idxs: print(-1); break
    a = idxs[c]
    ans = a[bisect_left(a, ans)]
else: print(ans+1)


Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()
idxs = defaultdict(list)

for i, c in enumerate(s):
    idxs[c].append(i)
for i, c in enumerate(s):
    idxs[c].append(len(s) + i)

ans, cur_i = -1, -1
for c in t:
    if c not in idxs: print(-1); break
    a = idxs[c]
    nxt = a[bisect_right(a, cur_i)]
    ans += nxt - cur_i
    cur_i = nxt % len(s)
else: print(ans+1)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

S = input()
T = input()

idx = {}
for i, s in enumerate(S):
    if s in idx.keys():
        idx[s].append(i + 1)
    else:
        idx[s] = [i + 1]

x = 0
current = 0
impossible = 0
for i, t in enumerate(T):
    if t in idx.keys():
        idx_list = idx[t]
        j = bisect.bisect_left(idx_list, current)
        if j < len(idx_list):
            current = idx_list[j]
        else:
            x += 1
            current = idx_list[0]
    else:
        impossible = 1
        break

if impossible:
    print(-1)
else:
    print(x * len(S) + current)


Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
import bisect

S = input()
T = input()

idx = {}
for i, s in enumerate(S):
    if s in idx.keys():
        idx[s].append(i + 1)
    else:
        idx[s] = [i + 1]

x = 0
current = 0
impossible = 0
for i, t in enumerate(T):
    if t in idx.keys():
        idx_list = idx[t]
        j = bisect.bisect_right(idx_list, current)
        if j < len(idx_list):
            current = idx_list[j]
        else:
            x += 1
            current = idx_list[0]
    else:
        impossible = 1
        break

if impossible:
    print(-1)
else:
    print(x * len(S) + current)
Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
S = list(input())
T = list(input())
s_dict = {}

for s in S:
    s_dict[s] = []
for i, s in enumerate(S+S):
    bisect.insort_right(s_dict[s], i)

print(s_dict)
N = len(S)
try:
    ret = 0
    cnt = 0
    pre_t_idx = -1
    for t in T:
        t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)]
        if t_idx > N-1:
            cnt += 1
            t_idx -= N
        ret = t_idx+1
        pre_t_idx = t_idx

    print(cnt*N+ret)
except Exception as e:
    print(-1)


Failing test case input:
ttenosc
npr

Expected output:
-1


Actual output:
{'t': [0, 1, 7, 8], 'e': [2, 9], 'n': [3, 10], 'o': [4, 11], 's': [5, 12], 'c': [6, 13]}
-1


Fixed submission (verdict: Accepted):
import bisect
S = list(input())
T = list(input())
s_dict = {}

for s in S:
    s_dict[s] = []
for i, s in enumerate(S+S):
    bisect.insort_right(s_dict[s], i)

N = len(S)
try:
    ret = 0
    cnt = 0
    pre_t_idx = -1
    for t in T:
        t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)]
        if t_idx > N-1:
            cnt += 1
            t_idx -= N
        ret = t_idx+1
        pre_t_idx = t_idx

    print(cnt*N+ret)
except Exception as e:
    print(-1)

Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
import bisect
S = input()
E = {S[i]:[] for i in range(len(S)-1)}
for i in range(len(S)-1):
  E[S[i]].append(i)
T = input()
print(E)
a = len(S)-1
ans=0
now = -1
for i in range(len(T)-1):
  if not T[i] in E.keys():
    print(-1)
    exit()
  s=E[T[i]]
  b= bisect.bisect_right(s,now)
  
  if b==len(s):
    ans+=s[0]+1+a-1-now
    now=s[0]
  else:
    ans+=s[b]-now
    now=s[b]
print(ans)


Failing test case input:
sostenc
gbmdtner

Expected output:
-1


Actual output:
{'s': [0, 2], 'o': [1], 't': [3], 'e': [4], 'n': [5], 'c': [6]}
-1


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
import bisect
S = input()
E = {S[i]:[] for i in range(len(S)-1)}
for i in range(len(S)-1):
  E[S[i]].append(i)
T = input()
a = len(S)-1
ans=0
now = -1
for i in range(len(T)-1):
  if not T[i] in E.keys():
    print(-1)
    exit()
  s=E[T[i]]
  b= bisect.bisect_right(s,now)
  
  if b==len(s):
    ans+=s[0]+1+a-1-now
    now=s[0]
  else:
    ans+=s[b]-now
    now=s[b]
print(ans)
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(int(1e6))

s = input()
t = input()

len_s = len(s)
n = [0] * len_s
set_s = set(s)
ss = s + s
for i in range(len_s):
    n[i] = {}
    for c in set_s:
        n[i][c] = ss[i+1:].find(c) + 1

ans = 0
for c in t:
    i = ans % len_s
    if c in n[i]:
        ans += n[i][c]
    else:
        ans = -2
        break

print(ans+1)


Failing test case input:
mlstvdc
msm

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(int(1e6))

s = input()
t = input()

len_s = len(s)
set_s = set(s)
set_t = set(t)

if len(set_t - set_s) != 0:
    print(-1)
    sys.exit()

n = {}
ss = s + s
ans = 0
for c in t:
    i = ans % len_s
    if not c in n:
        n[c] = [0] * len_s
    if n[c][i] == 0:
        n[c][i] = ss[i:].find(c) + 1
    ans += n[c][i]

print(ans)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

s = input()
t = input()





results = {}
for i in range(len(s)):
    results.setdefault(s[i], []).append(i+1)



ans = 0
cnt = 0
num = 1

for i in range(len(t)):
    
    if not t[i] in results.keys():
        print(-1)
        exit()
    else:
        idx = bisect.bisect_right(results[t[i]],cnt)
        
        if len(results[t[i]]) <= idx:
            cnt = results[t[i]][0]
            ans = len(s)*num + cnt
            num += 1
        else:
            
            cnt = results[t[i]][idx] - cnt
            ans += cnt
            
print(ans)

Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
9


Fixed submission (verdict: Accepted):
import bisect

s = input()
t = input()





results = {}
for i in range(len(s)):
    results.setdefault(s[i], []).append(i+1)



ans = 0
cnt = 0
num = 1

for i in range(len(t)):
    
    if not t[i] in results.keys():
        print(-1)
        exit()
    else:
        idx = bisect.bisect_right(results[t[i]],cnt)
        
        if len(results[t[i]]) <= idx:
            cnt = results[t[i]][0]
            ans = len(s)*num + cnt
            num += 1
        else:
            
            ans += results[t[i]][idx] - cnt
            cnt = results[t[i]][idx]
            
print(ans)
Problem: p02937
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
s=list(input())
t=list(input())
N=len(s)
sd={x:[] for x in sorted(set(s))}
td={x:[] for x in sorted(set(t))}
if not set(td.keys()) <= set(sd.keys()):
    print(-1)
    exit()

for i,c in enumerate(s):
    sd[c].append(i)
index=0
ans=0
for c in t:
    i=bisect.bisect_left(sd[c],index)
    if i==len(sd[c]):
        ans+=1
        i=bisect.bisect_left(sd[c],0)
    index=sd[c][i]
print(ans*N+index+1)


Failing test case input:
vtaletn
tnn

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
import bisect
s=list(input())
t=list(input())
N=len(s)
sd={x:[] for x in sorted(set(s))}
if not set(t) <= set(sd.keys()):
    print(-1)
    exit()

for i,c in enumerate(s):
    sd[c].append(i)
index=-1
ans=0
for c in t:
    i=bisect.bisect_left(sd[c],index+1)

    if i==len(sd[c]):
        ans+=1
        i=bisect.bisect_left(sd[c],0)
    index=sd[c][i]
print(ans*N+index+1)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import bisect

s=list(map(lambda x : ord(x)-97,list(input())))
t=list(map(lambda x : ord(x)-97,list(input())))


alpha=[[] for i in range(26)]


for index,item in enumerate(s):
    alpha[item].append(index)
    

loc=-1
count=0

for index,item in enumerate(t):
    temp=bisect.bisect_left(alpha[item],loc)
    if len(alpha[item])==0:
        print(-1)
        exit()
    if temp==len(alpha[item]):
        count+=1
        loc=alpha[item][0]
    else:
        loc=alpha[item][temp]
    
print(loc+1+count*len(s))





Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):


import bisect

s=list(map(lambda x : ord(x)-97,list(input())))
t=list(map(lambda x : ord(x)-97,list(input())))


alpha=[[] for i in range(26)]


for index,item in enumerate(s):
    alpha[item].append(index)
    

loc=-1
count=0

for index,item in enumerate(t):
    temp=bisect.bisect(alpha[item],loc)
    if len(alpha[item])==0:
        print(-1)
        exit()
    if temp==len(alpha[item]):
        count+=1
        loc=alpha[item][0]
    else:
        loc=alpha[item][temp]
    
print(loc+1+count*len(s))
Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
import bisect
s = input()
t = input()
ls = len(s)
dbls = s*2
idx = 0
ans = 0
dic = defaultdict(list)

for i, c in enumerate(dbls):
    dic[c] += [i+1]

print(dbls)

for c in t:
    if not c in dic.keys():
        print(-1)
        exit()
    lst = dic[c]
    i = bisect.bisect_right(lst, idx)
    idx = lst[i]
    if idx > ls:
        ans += ls
        idx -= ls
    else:
        idx = lst[i]

if not idx == 0:
    ans += idx
print(ans)


Failing test case input:
emtscsl
pmogmraghrp

Expected output:
-1


Actual output:
emtscslemtscsl
-1


Fixed submission (verdict: Accepted):
from collections import defaultdict
import bisect
s = input()
t = input()
ls = len(s)
dbls = s*2
idx = 0
ans = 0
dic = defaultdict(list)

for i, c in enumerate(dbls):
    dic[c] += [i+1]

for c in t:
    if not c in dic.keys():
        print(-1)
        exit()
    lst = dic[c]
    i = bisect.bisect_right(lst, idx)
    idx = lst[i]
    if idx > ls:
        ans += ls
        idx -= ls
    else:
        idx = lst[i]

if not idx == 0:
    ans += idx
print(ans)

Problem: p02937
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()

x = len(s)
y = len(t)

a = 0
b = x
c = 0
a0 = 0


for i in range(0,y):
  while True:
    
    a=s.find(t[i:i+1])+1
    if a <= 0:
      print("-1")
      exit()
    
    if a<a0:
      c=c+a+b
    else:
      c=c+a-a0
    b=x-a
    a0=a
    break
    
print(c)


Failing test case input:
ntelatv
tnn

Expected output:
15


Actual output:
8


Fixed submission (verdict: Accepted):
s = input()
t = input()

x = len(s)
y = len(t)

a = 0
b = x
c = 0
a0 = 0


for i in range(0,y):
  while True:
    
    a=s.find(t[i:i+1],a0)+1
    if a <= 0:
      a=s.find(t[i:i+1])+1
    if a <= 0:
      print("-1")
      exit()
    
    if a<=a0:
      c=c+a+b
    else:
      c=c+a-a0
    b=x-a
    a0=a
    break
    
print(c)
Problem: p03382
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect

    ans = A[-1]
    b = bisect.bisect_left(A,ans)

    if abs(ans-A[b])<abs(A[max(0,b-1)]):
        print(A[-1],A[b])
    else:
        print(A[-1],A[b-1])

if __name__=='__main__':
    main()

Failing test case input:
5
6 9 4 2 11

Expected output:
11 6

Actual output:
11 11


Fixed submission (verdict: Accepted):
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect

    ans = A[-1]/2
    b = bisect.bisect_left(A,ans)

    if abs(ans-A[b])<abs(ans-A[max(0,b-1)]):
        print(A[-1],A[b])
    else:
        print(A[-1],A[b-1])

if __name__=='__main__':
    main()

Problem: p03382
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
input()
a=list(map(int,input().split()))
m=max(a)
d=max(a,key=lambda d:abs(m-2*d)if m!=d else-1)
print(m,d)

Failing test case input:
5
6 9 4 2 11

Expected output:
11 6

Actual output:
11 9


Fixed submission (verdict: Accepted):
input()
a=list(map(int,input().split()))
m=max(a)
d=min(a,key=lambda d:abs(m-2*d)if m!=d else 1e18)
print(m,d)

Problem: p03382
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect

    ans = A[-1]
    b = bisect.bisect_left(A,ans)

    if abs(ans-A[b])<abs(ans-A[max(0,b-1)]):
        print(A[-1],A[b])
    else:
        print(A[-1],A[b-1])

if __name__=='__main__':
    main()

Failing test case input:
5
6 9 4 2 11

Expected output:
11 6

Actual output:
11 11


Fixed submission (verdict: Accepted):
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect

    ans = A[-1]/2
    b = bisect.bisect_left(A,ans)

    if abs(ans-A[b])<abs(ans-A[max(0,b-1)]):
        print(A[-1],A[b])
    else:
        print(A[-1],A[b-1])

if __name__=='__main__':
    main()

Problem: p03382
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
l, r = 0, 0
l = max(a)
a.remove(l)
j = bisect.bisect_left(a, l/2)
print(a[min(j, len(a)-1)])

Failing test case input:
5
6 9 4 2 11

Expected output:
11 6

Actual output:
6


Fixed submission (verdict: Accepted):
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
l, r = 0, 0
l = max(a)
a.remove(l)
j = bisect.bisect_left(a, l/2)
try:
    if abs((l/2) - a[j-1]) < abs((l/2) - a[j]):
        j -= 1
except:
    pass
print(l, a[min(j, len(a)-1)])