TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
#include <math.h>

#include <algorithm>

#include <map>
#include <string>


using namespace std;

int main() {
  int N;
  cin >> N;
  vector<double> V(N);
  for (size_t i = 0; i < N; i++) {
    cin >> V[i];
  }

  while (V.size() != 1) {
    sort(V.rbegin(), V.rend());
    int a = V.back();
    V.pop_back();
    int b = V.back();
    V.pop_back();
    V.push_back((double)(a + b) / (double)2.0);
  }

  printf("%lf\n", V[0]);

  return 0;
}


#include <math.h>

#include <algorithm>

#include <map>
#include <string>


using namespace std;

int main() {
  int N;
  cin >> N;
  vector<double> V(N);
  for (size_t i = 0; i < N; i++) {
    cin >> V[i];
  }

  while (V.size() != 1) {
    sort(V.rbegin(), V.rend());
    int a = V.back();
    V.pop_back();
    int b = V.back();
    V.pop_back();
    V.push_back((double)(a + b) / (double)2.0);
  }

  printf("%lf\n", V[0]);

  return 0;
}


#include <math.h>

#include <algorithm>

#include <map>
#include <string>


using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long double> V(N);
  for (size_t i = 0; i < N; i++) {
    cin >> V[i];
  }

  while (V.size() != 1) {
    sort(V.rbegin(), V.rend());
    int a = V.back();
    V.pop_back();
    int b = V.back();
    V.pop_back();
    V.push_back((long double)(a + b) / (long double)2.0);
  }

  printf("%lf\n", V[0]);

  return 0;
}


#coding: utf-8

N = int(input())
V = [int(v) for v in input().split()]

while len(V) != 1:
    V.sort()
    V.append((V[0]+V[1])/2)
    V = V[2:]

print (V[0])


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
N = int(input())
V = list(map(int, input().split()))

V = sorted(V)

ans = 0.0

for v in V:
  ans += v
  ans /=2.0
  
print(ans)

N = int(input())
V = list(map(int, input().split()))

V = sorted(V)

ans = V[0]

for v in V[1:]:
  ans += v
  ans /=2.0
  
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
n = int(input())
v = sorted(list(map(int,input().split())))

for _ in range(n-1):
    x = v[0]
    y = v[1]
    num = (x+y)/2
    del v[0]
    v[0] = num

print(int(v[0]))

n = int(input())
v = sorted(list(map(int,input().split())))

for _ in range(n-1):
    x = v[0]
    y = v[1]
    num = (x+y)/2
    del v[0]
    v[0] = num

print(v[0])

Verdicts: Wrong Answer

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
total_num = int(input())
materials = input().split()

for key,value in enumerate(materials):
  materials[key] = int(value)

materials.sort()
total_value = materials[0] + materials[1] / 2


materials.pop(0)
materials.pop(0)

for index,value in enumerate(materials):
  if(index + 1 <= total_num - 2):
    total_value = total_value + materials[index] / 2
  else:
    break;
print(total_value)

total_num = int(input())
materials = input().split()

for key,value in enumerate(materials):
  materials[key] = int(value)

materials.sort()
total_value = (materials[0] + materials[1]) / 2


materials.pop(0)
materials.pop(0)

for index,value in enumerate(materials):
  if(index + 1 <= total_num - 2):
    total_value = (total_value + materials[index]) / 2
  else:
    break;

print(int(total_value))

total_num = int(input())
materials = input().split()

for key,value in enumerate(materials):
  materials[key] = int(value)

materials.sort()
total_value = (materials[0] + materials[1]) / 2


materials.pop(0)
materials.pop(0)

for index,value in enumerate(materials):
  if(index + 1 <= total_num - 2):
    total_value = (total_value + materials[index]) / 2
  else:
    break;

print(total_value)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
N = int(input())
A = sorted(list(map(int, input().split())))

for i in range N-1
	A[i+1] = A[i] + A[i+1]

 print(A[N-1])

N = int(input())
A = sorted(list(map(int, input().split())))

for i in range(N-1):
    A[i+1] = (A[i] + A[i+1])/2

 print(A[N-1])

N = int(input())
A = sorted(list(map(int, input().split())))

for i in range N-1:
	A[i+1] = (A[i] + A[i+1])/2

 print(A[N-1])

N = int(input())
A = sorted(list(map(int, input().split())))

for i in range(N-1):
	A[i+1] = (A[i] + A[i+1])/2

 print(A[N-1])

n = int(input())
v = sorted(list(map(int, input().split())))

for i in range(n - 1):
    v[i + 1] = (v[i] + v[i + 1]) / 2

print(v[n - 1])

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
n = int(input())
v = list(map(int, input().split()))

v.sort()

mean = v[0]
for i in v:
  mean = (mean + v)/2

  
print(mean)

n = int(input())
v = list(map(int, input().split()))

v.sort()

mean = v[0]
for i in v:
  mean = (mean + i)/2

  
print(mean)

Verdicts: Runtime Error

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
import math

N = int(input())
v = list(map(int, input().split()))

v.sort(reverse=True)

while len(v) > 1:
    v.append((v.pop() + v.pop())/2)

print(v)








import math

N = int(input())
v = list(map(int, input().split()))

v.sort(reverse=True)

while len(v) > 1:
    v.append((v.pop() + v.pop())/2)

print(v[0])








Verdicts: Wrong Answer

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
N = int(input())
L = list(map(int, input()))
L.sorted
ans = reduce(lambda x, y: (x + y)/2, L)
print(ans)

from functools import reduce
N = int(input())
L = list(map(int, input().split()))
L.sort()
print(reduce(lambda x, y: (x + y)/2, L))

Verdicts: Runtime Error

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
n = int(input())
v = list(map(int,input().split()))

v.sort()

value = v[0]

for i in range(1,n):
    value = (value+v[i])//2

print(value)

n = int(input())
v = list(map(int,input().split()))

v.sort()
ans = v[0]

for i in range(1,n):
    ans = (ans+v[i])/2

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
n = int(input())
v = list(map(int,input().split()))

v = sorted(v)
print(v)
def dfs (l):
    if len(l)==1:
         return l[0]
    num = (l[0]+l[1])/2.0
    l = l[2:]
    # print(l)
    l.append(num)
    # print(l)
    l = sorted(l)
    return dfs(l)



print(dfs(v))

import sys
sys.setrecursionlimit(10**6)
n,q = map(int,input().split())
a=[[] for i in range(n)]
p=[]*n
l=[0]*n

def dfs(parent,current):
    for i in a[current-1]:
        if i != parent:
            l[i-1] += l[current-1]
            dfs(current,i)


for i in range(n-1):
    t1,t2 = map(int,input().split())
    a[t1-1].append(t2)
    a[t2-1].append(t1)
    
for i in range(q):
    t1,t2 = map(int,input().split())
    l[t1-1]+=t2
dfs(-1,1)

print(" ".join(map(str,l)))

n = int(input())
v = list(map(int,input().split()))

v = sorted(v)
# print(v)
def dfs (l):
    if len(l)==1:
         return l[0]
    num = (l[0]+l[1])/2.0
    l = l[2:]
    # print(l)
    l.append(num)
    # print(l)
    l = sorted(l)
    return dfs(l)



print(dfs(v))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
n = int(input())
v = map(int, input().split())

v.sort()

value = v[0]
for i in range(1, len(v)):
  value = (value + v[i]) / 2

print(value)             
  

n = int(input())
v = list(map(int, input().split()))

v.sort()

value = v[0]
for i in range(1, len(v)):
  value = (value + v[i]) / 2

print(value)


Verdicts: Runtime Error

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
N = int(input())
L = sorted(list(map(int, input().split())))

print(L)

for i in range(0,N - 1):
  L [i+1] = (L[i] + L[i+1]) / 2

print(L[N-1])



N = int(input())
L = sorted(list(map(int, input().split())))

for i in range(0,N - 1):
  L [i+1] = (L[i] + L[i+1]) / 2

print(L[N-1])

Verdicts: Wrong Answer

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
N = int(input())
a = list(map(int,input().split()))

def ave(c1,c2):
  av = (c1 + c2)/2
  return av

for i in range(N-1):
  for j in range(i+1,N):
    if a[j] <= a[i]:
      tmp = a[i]
      a[i] = a[j]
      a[j] =tmp
print(a)

for i in range(N-1):
  average = ave(a[0],a[1])
  a.pop(0)
  a.pop(0)
  a.insert(0,average)

print(int(a[0]))


N = int(input())
a = list(map(int,input().split()))

def ave(c1,c2):
  av = (c1 + c2)/2
  return av

for i in range(N-1):
  for j in range(i+1,N):
    if a[j] <= a[i]:
      tmp = a[i]
      a[i] = a[j]
      a[j] =tmp


for i in range(N-1):
  average = ave(a[0],a[1])
  a.pop(0)
  a.pop(0)
  a.insert(0,average)

print(int(a[0]))

import random

N = int(input())
a = list(map(int,input().split()))

def ave(c1,c2):
  av = (c1 + c2)/2
  return av

for i in range(N-1):
  for j in range(i+1,N):
    if a[j] >= a[i]:
      tmp = a[i]
      a[i] = a[j]
      a[j] =tmp
print(a)

for i in range(N-1):
  average = ave(a[0],a[1])
  a.pop(0)
  a.pop(0)
  a.insert(0,average)

print(a[0])



N = int(input())
a = list(map(int,input().split()))

def ave(c1,c2):
  av = (c1 + c2)/2
  return av

for i in range(N-1):
  for j in range(i+1,N):
    if a[j] <= a[i]:
      tmp = a[i]
      a[i] = a[j]
      a[j] =tmp
print(a)

for i in range(N-1):
  average = ave(a[0],a[1])
  a.pop(0)
  a.pop(0)
  a.insert(0,average)

print(a[0])





N = int(input())
a = list(map(int,input().split()))

def ave(c1,c2):
  av = (c1 + c2)/2
  return av

for i in range(N-1):
  for j in range(i+1,N):
    if a[j] <= a[i]:
      tmp = a[i]
      a[i] = a[j]
      a[j] =tmp
for i in range(N-1):
  average = ave(a[0],a[1])
  a.pop(0)
  a.pop(0)
  a.insert(0,average)

print(int(a[0]))

n = int(input())
v = [ int(_) for _ in input().split() ]
 
v.sort()
 
x = ( v[0] + v[1] ) /2 
 
for i in range(1, len(v)-1):
	x = ( x + v[i+1] ) /2 
    
print(x)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: You have a pot and N ingredients. Each ingredient has a real number parameter called _value_ , and the value of the i-th ingredient (1 \leq i \leq N) is v_i.  When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.  After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Submission attempts (in order):
n = int(input())
s = list(map(int,input().split()))
min_ave = 100000
for i, val in enumerate(s):
    for j, val2 in enumerate(s):
        if i == j:
            continue
        ave = (val + val2) / 2
        if min_ave > ave:
            min_ave = ave 
print((max(s) + min_ave)/2)

n = int(input())
lis = sorted(map(int, input().split()))
ans = lis[0]
for i in lis[1:]:
    ans += i
    ans /= 2
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
s = input()
t = input()
ls,lt = len(s),len(t)
i = j = 0
si = lp = 0
while True:
    tc = t[i]
    si = s.find(tc)
    if si == -1:
        print(-1)
        exit(0)
    else:
        if i == lt-1:
            print(lp*ls + si+1)
            exit(0)
        else:
            while True:
                if t[i+1] in s[si+1:]:
                    si = s.find(t[i+1])
                    if i+1 == lt-1:
                        #print(lp*ls + si+1)
                        exit(0)
                    else:
                        i += 1
                else:
                    i+=1
                    break
    lp += 1
    if i >= lt:
        print(-1)
        break

s = input()
t = input()
ls,lt = len(s),len(t)
i = j = 0
si = lp = 0
while True:
    tc = t[i]
    si = s.find(tc)
    if si == -1:
        print(-1)
        exit(0)
    else:
        if i == lt-1:
            print(lp*ls + si+1)
            exit(0)
        else:
            while True:
                if t[i+1] in s[si+1:]:
                    si = s[si+1:].find(t[i+1]) + si
                    if i+1 == lt-1:
                        print(lp*ls + si+1)
                        exit(0)
                    else:
                        i+=1
                else:
                    i+=1
                    break
    lp += 1
    if i >= lt:
        print(-1)
        break

s = input()
t = input()
ls,lt = len(s),len(t)
i = j = 0
si = lp = 0
while True:
    tc = t[i]
    si = s.find(tc)
    if si == -1:
        print(-1)
        exit(0)
    else:
        if i == lt-1:
            print(lp*ls + si+1)
            exit(0)
        else:
            while True:
                if t[i+1] in s[si+1:]:
                    si = s[si+1:].find(t[i+1]) + si +1
                    if i+1 == lt-1:
                        print(lp*ls + si+1)
                        exit(0)
                    else:
                        i+=1
                else:
                    i+=1
                    break
    lp += 1
    if i >= lt:
        print(-1)
        break

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
import itertools

s = input()
t = input()
obj = {}

loop_num = 0
temp_num = -1

for i in range(len(s)):
    char = s[i]
    if not (char in obj):
        obj[char] = [i]
    else:
        obj[char].append(i)

for i in range(len(t)):
    char = t[i]
    if not (char in obj):
        loop_num = -1
        break
    else:
        next_num = next(itertools.ifilter(lambda x: x >= temp_num, obj[char]), None)
        if next_num == None:
            loop_num += 1
            temp_num = obj[char][0]
        else:
            temp_num = next_num

if(loop_num == -1):
    print(-1)
else:
    print(loop_num * len(s) + temp_num + 1)

from bisect import bisect_right

s = input()
t = input()
obj = {}

loop_num = 0
temp_num = -1

for i in range(len(s)):
    char = s[i]
    if not (char in obj):
        obj[char] = [i]
    else:
        obj[char].append(i)

for i in range(len(t)):
    char = t[i]
    if not (char in obj):
        loop_num = -1
        break
    else:
        next_index = bisect_right(obj[char], temp_num)
        if next_index == len(obj[char]):
            loop_num += 1
            temp_num = obj[char][0]
        else:
            temp_num = obj[char][next_index]

if(loop_num == -1):
    print(-1)
else:
    print(loop_num * len(s) + temp_num + 1)

Verdicts: Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
s = input()
t = input()

for i in range(len(t)):
  if not t[i] in s:
    print(-1)
    break
else:
  j = 0
  for i in rane(len(t)):
    j = s[j:].find(t[i])
    if j == -1:
      counter += 1
      j = s.find(t[i])
  print(counter * len(s) + j + 1)

s = input()
t = input()

for i in range(len(t)):
  if not t[i] in s:
    print(-1)
    break
else:
  j = -1
  counter = 0
  for i in range(len(t)):
    if t[i] in s[j+1:]:
      j = s[j+1:].find(t[i]) + j + 1
    else:
      counter += 1
      j = s.find(t[i])
  print(counter * len(s) + j + 1)


Verdicts: Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
#!/usr/bin/env python3
 
import sys

from heapq import heappush, heappop, heappushpop
from collections import defaultdict


input = sys.stdin.readline
 
S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()
 
ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1
 
print(ans)

#!/usr/bin/env python3
 
import sys

from heapq import heappushpop, heapify, heapreplace
from collections import defaultdict

 
S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()
 
ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1
 
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
s = input()
t = input()

s_ = s[:]

ti = 0
ans = 0
flag = True

while ti < len(t):
    si = s_.find(t[ti])
    
    if si != -1:
        ans += si + 1
        s_ = s_[si+1:]
        ti += 1
        flag = False
    else:
        if flag:
            print(-1)
            flag = False
            break
        ans += len(s_)
        s_ = s[:]
        flag = True

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

s = input()
t = input()

s_ = s[:]

ti = 0
ans = 0
flag = True

while ti < len(t):
    si = s_.find(t[ti])
    
    if si != -1:
        ans += si + 1
        s_ = s_[si+1:]
        ti += 1
        flag = False
    else:
        if flag:
            print(-1)
            exit(0)
        ans += len(s_)
        s_ = s[:]
        flag = True
        
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
# ABC138E - Strings of Impurity
import sys
input = sys.stdin.readline

def main():
    S = input()
    T = input()
    if set(T) <= set(S):
        lim_s, lim_t = len(S) - 1, len(T)
        ans, cur, idx = 1, 0, -1
        while cur < lim_t:
            x = S[idx + 1 :].find(T[cur])
            if x == -1:
                ans += 1
                idx = -1
            else:
                idx += x + 1
                cur += 1
        ans = (ans - 1) * (lim_s + 1) + idx + 1
        print(ans)
    else:  # corner case
        print(-1)


if __name__ == "__main__":
    main()

# ABC138E - Strings of Impurity
import sys
input = sys.stdin.readline

def main():
    S, T = tuple(input() for _ in range(2))
    if not set(T) <= set(S):  # corner case
        print(-1)
        return
    lim_s, lim_t = len(S) - 1, len(T)
    ans, cur, idx = 1, 0, -1
    while cur < lim_t:
        find = S[idx + 1:].find(T[cur])
        if find == -1:
            ans += 1
            idx = -1
        else:
            idx += find + 1
            cur += 1
    print((ans - 1) * len(S) + idx + 1)


if __name__ == "__main__":
    main()

# ABC138E - Strings of Impurity
from bisect import bisect_left as bs
from collections import defaultdict


def main():
    S = input()
    T = input()
    # idx[c] := indices at which character c appears in S
    idx, ls = defaultdict(list), len(S)
    for i, s in enumerate(S):
        idx[s] += [i]
    roop, cur = 0, -1
    for t in T:  # binary search to find t's index > cur
        tgt = idx[t]  # sorted list of indices of t
        if tgt == []:  # t not in S
            print(-1)
            return
        x = bs(tgt, cur + 1)
        if x < len(tgt):  # find in current roop
            cur = tgt[x]
        else:  # move to next roop and pick up the first one
            cur = tgt[0]
            roop += 1
    print(roop * ls + cur + 1)


if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
s=input()
t=input()

ans=0
s_inx=0
t_inx=0
s_l=len(s)
t_l=len(t)

c=0
while t_inx<=t_l-1:
  try:
    temp_inx=s[s_inx:].index(t[t_inx])
    s_inx+=temp_inx+1
    t_inx+=1
    c=0
  except:
    c+=1
    s_inx=0
    ans+=s_l

  if c==2:
    print(-1)
    exit()
else:
  ans+=s_inx+1

print(ans)

s=input()
t=input()

ans=0
s_inx=0
t_inx=0
s_l=len(s)
t_l=len(t)

c=0
while t_inx<=t_l-1:
  try:
    temp_inx=s[s_inx:].index(t[t_inx])
    s_inx+=temp_inx+1
    t_inx+=1
    c=0
  except:
    c+=1
    s_inx=0
    ans+=s_l

  if c==2:
    print(-1)
    exit()
else:
  ans+=s_inx

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
s = input()
t = input()

including = True
for x in t:
    if x  not in s:
        including = False
        break
if not including:
    print(-1)
    return


x = 0
y = 0
while True:
    index = x % len(s)
    if s[index] == t[y]:
        y += 1
        if y == len(t):
            break
    x += 1

print(x + 1)

import bisect

S = input().strip()
T = input().strip()

x = [[] for j in range(26)]

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

sett = list(set(T))

for t in sett:
    if len(x[ord(t) - ord('a')]) == 0:
        print(-1)
        exit()

c = 0
z = 0

for t in T:
    y = bisect.bisect_left(x[ord(t) - ord('a')], c)
    if y == len(x[ord(t) - ord('a')]):
        z += 1
        c = x[ord(t) - ord('a')][0] + 1
    else:
        c = x[ord(t) - ord('a')][y] + 1

print(z * len(S) + c)


Verdicts: Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
import bisect

s = input()
t = input()
T = set(t)
s_num = len(s)
t_num = len(T)

# make a dictonary whose keys are the alphabets in t
dict = {}
appearing_times = {}

# when each alphabet in t appears in s
for w in T:
    dict[w] = []
    appearing_times[w] = 0
    index = -1
    while True:
        index = s.find(w, index + 1)
        if index == -1 and appearing_times[w] == 0:
            print(-1)
            exit()
        elif index == -1:
            break
        else:
            dict[w].append(index)
            appearing_times[w] += 1

# how many times s is repeated
count = 0

s_index = 0
check = 0

for w in t:
    idx = bisect.bisect_left(dict[w], s_index)
    if check == 'done' and s_index == dict[w][idx]:
        idx = idx + 1

    if idx < appearing_times[w]:
        s_index = dict[w][idx]
    else:
        count += 1
        s_index = dict[w][0]

    check = 'done'
print(count * s_num + s_index + 1)


import bisect

s = input()
t = input()
T = set(t)
s_num = len(s)
t_num = len(T)

# make a dictonary whose keys are the alphabets in t
dict = {}
appearing_times = {}

# when each alphabet in t appears in s
for w in T:
    dict[w] = []
    appearing_times[w] = 0
    index = -1
    while True:
        index = s.find(w, index + 1)
        if index == -1 and appearing_times[w] == 0:
            print(-1)
            exit()
        elif index == -1:
            break
        else:
            dict[w].append(index)
            appearing_times[w] += 1

# how many times s is repeated
count = 0

s_index = 0
w_pre = 'none'

for w in t:
    idx = bisect.bisect_left(dict[w], s_index)
    if w == w_pre:
        idx += 1
        if idx == appearing_times[w]:
            count += 1
            idx = 0

    if idx < appearing_times[w]:
        s_index = dict[w][idx]
    else:
        count += 1
        s_index = dict[w][0]
    w_pre = w

print(count * s_num + s_index + 1)


Verdicts: Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
#138_E
from bisect import bisect_left, bisect_right

s = input()
t = input()
if set(s) >= set(t):
    al_idx = [[] for _ in range(26)]
    ss = s * 2
    alp = 'abcdefghijklmnopqrstuvwxyz'
    for i in range(len(ss)):
        al_idx[alp.index(ss[i])].append(i)
    
    tmp = -1
    ans = 0
    for j in range(len(t)):
        idx = alp.index(t[j])
        cur = bisect_right(al_idx[idx], tmp)
        ans += al_idx[idx][cur] - tmp
        print(ans)
        tmp = al_idx[idx][cur] % len(s)
        
    print(ans)
else:
    print(-1)

#138_E
from bisect import bisect_left, bisect_right

s = input()
t = input()
if set(s) >= set(t):
    al_idx = [[] for _ in range(26)]
    ss = s * 2
    alp = 'abcdefghijklmnopqrstuvwxyz'
    for i in range(len(ss)):
        al_idx[alp.index(ss[i])].append(i)
    
    tmp = -1
    ans = 0
    for j in range(len(t)):
        idx = alp.index(t[j])
        cur = bisect_right(al_idx[idx], tmp)
        ans += al_idx[idx][cur] - tmp
        tmp = al_idx[idx][cur] % len(s)
        
    print(ans)
else:
    print(-1)

Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
from collections import defaultdict as dd
from bisect import bisect_left as bl
s = input()
t = input()
ind = dd(list)
res = 0
for i in range(len(s)):
  ind[s[i]].append(i)
#print(ind)
for i in range(len(t)):
  if len(ind[t[i]]) == 0:
    print(-1)
    exit(0)
  temp = bl(ind[t[i]], res % len(s))
  #print(temp, res, t[i])
  if res % len(s) == ind[t[i]][temp]:
    temp += 1
  if temp == len(ind[t[i]]):
    res += (len(s) - res % len(s)) + ind[t[i]][0]
  else:
    res += ind[t[i]][temp] - res % len(s)
print(res + 1)

S=input();T=input();p=0;e=1
for s in T:
  q=p%len(S)
  if not s in S:e=0;break
  if s in S[q:]:p+=S[q:].index(s)+1
  else:p+=S.index(s)+len(S[q:])+1
print((p+1)*e-1)

Verdicts: Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
from bisect import bisect_left
def main():
  s=input()
  t=input()
  n=len(t)
  m=len(s)
  lindex=[[] for _ in range(26)]
  for i in range(m):
    if s[i] in t:
      lindex[ord(s[i])-97].append(i)
  for i in range(n):
    if len(lindex[ord(t[i])-97])==0:
      print(-1)
      exit()
  cnt=0
  for i in range(n-1):
    if l==bisect_left(lindex[ord(t[i+1])-97],lindex[ord(t[i])-97][0]):
      cnt+=1
  k=lindex[ord(t[n-1])-97][0]
  return print(m*cnt+k+1)
if __name__=='__main__':
  main()

from bisect import bisect_right
def main():
  s=input()
  t=input()
  n=len(t)
  m=len(s)
  lindex=[[] for _ in range(26)]
  for i in range(m):
    if s[i] in t:
      lindex[ord(s[i])-97].append(i)
  for i in range(n):
    if len(lindex[ord(t[i])-97])==0:
      print(-1)
      exit()
  cnt=0
  inde=-1
  for i in range(n):
    l=len(lindex[ord(t[i])-97])
    idx=bisect_right(lindex[ord(t[i])-97],inde)
    if l==idx:
      cnt+=1
      inde=lindex[ord(t[i])-97][0]
    else:
      inde=lindex[ord(t[i])-97][idx]
  return print(m*cnt+inde+1)
if __name__=='__main__':
  main()

Verdicts: Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
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)  

from collections import defaultdict
from bisect import bisect_left
 
s = input()
t = input()
s_len = len(s)
t_len = len(t)
if not set(t) <= set(s):
  print(-1)
else: 
  idx = defaultdict(list)
  for i in range(s_len):
    idx[s[i]].append(i)
  
  loop_num = 0
  current_position = -1
  for i in range(t_len):
    char = t[i]
    tmp_idx = idx[char]
    n = bisect_left(tmp_idx, current_position+1)
    if n < len(tmp_idx):
      current_position = tmp_idx[n]
    else:
      current_position = tmp_idx[0]
      loop_num += 1
  print(s_len * loop_num + current_position + 1)

Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
import bisect

s = input()
t = input()
n = len(s)
s0 = {}
for i in range(n):
    s0.setdefault(s[i], [])
    s0[s[i]].append(i)
print(s0)
num1 = 0
num2 = -1
flag = True
for i in t:
    if i not in s:
        flag = False
        break
    num = bisect.bisect_right(s0[i], num2)
    if num == len(s0[i]):
        num1 += 1
        num2 = s0[i][0]
    else:
        num2 = s0[i][num]
    print(num1, num2)
if flag == True:
    print(num1 * n + num2 + 1)
else:
    print(-1)

import bisect

s = input()
t = input()
n = len(s)
s0 = {}
for i in range(n):
    s0.setdefault(s[i], [])
    s0[s[i]].append(i)
num1 = 0
num2 = -1
flag = True
for i in t:
    if i not in s:
        flag = False
        break
    num = bisect.bisect_right(s0[i], num2)
    if num == len(s0[i]):
        num1 += 1
        num2 = s0[i][0]
    else:
        num2 = s0[i][num]
if flag == True:
    print(num1 * n + num2 + 1)
else:
    print(-1)

Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
print(-1)

from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

alp = defaultdict(list)
for i, si in enumerate(s):
    alp[si].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)


Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
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)


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)


Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
import sys
from bisect import bisect_left as bi_l
from collections import defaultdict


def main():
    s, t = sys.stdin.read().split()
    print(s, t)
    if set(t) - set(s):
        print(-1)
        sys.exit()

    n = len(s)
    s *= 2
    c = defaultdict(list)
    for i in range(n * 2):
        c[s[i]].append(i)

    i = 0
    l = 0 # left_most
    for ch in t:
        b = c[ch][bi_l(c[ch], l)]
        if b < n:
            l = b + 1
        else:
            l = b - n + 1
            i += n

    print(i+(l-1)+1) 

if __name__ == '__main__':
    main()

import sys
from bisect import bisect_left as bi_l
from collections import defaultdict

s, t = sys.stdin.read().split()
l = len(s)
s *= 2

def main():
    for c in t:
        try:
            s.index(c)
        except:
            return -1
    
    d = defaultdict(list)
    for i in range(l*2):
        d[s[i]].append(i)
    
    for c in d:
        d[c].sort()
    
    j = 0
    cnt = 0
    for c in t:
        k = bi_l(d[c], j)
        j = d[c][k]
        if j >= l:
            j -= l
            cnt += 1
        j += 1
    ans = l * cnt + j

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

Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
s=input() 
t=input()  
sa=list(s)
ta=list(t)
#print(set(sa))
#print(set(ta))

if len(set(ta)-set(sa))>0:
    print(-1)



s=input() 
t=input()  
sa=list(s)
ta=list(t)
ans2=0
x=0
y=0
ans= [[] for i in range(26)]
for i in range(len(s)):
    ans[ord(sa[i])-96-1].append(i)
print(ans)
for i in range(len(t)):
    if len(ans[ord(ta[i])-97])==0:
        ans2=-1
        break;
    else:
        x_old=x
        for j in range(len(ans[ord(ta[i])-97])):
            if ans[ord(ta[i])-97][j]>x:
                x=ans[ord(ta[i])-97][j]
                break
        if x_old==x:
            x=0
            y+=1
            for j in range(len(ans[ord(ta[i])-97])):
                if ans[ord(ta[i])-97][j]>x:
                    x=ans[ord(ta[i])-97][j]
                    break
    print(ta[i],x,y)
if ans2==-1:
    print(-1)
else:
    print(y*len(s)+x+1)



s=input() 
t=input()  
sa=list(s)
ta=list(t)
ans2
x=0
y=0
ans= [[] for i in range(26)]
for i in range(len(s)):
    ans[ord(sa[i])-96-1].append(i)
print(ans)
for i in range(len(t)):
    if len(ans[ord(ta[i])-97])==0:
        ans2=-1
        break;
    else:
        x_old=x
        for j in ans[ord(ta[i])-97]:
            if j>x:
                x=j
        if x_old==x:
            x=0
            y+=1
            for j in ans[ord(ta[i])-97]:
                if j>x:
                    x=j
print(y*len(s)+x+1)



import bisect

s,t=input(),input()
ls=len(s)
lt=len(t)
A=[[] for i in range(26+1)]
L=[0 for i in range(26+1)]

for i in range(ls):
  A[ord(s[i])-96].append(i+1)
  L[ord(s[i])-96]+=1
#print(A)

tmp=0
ans=0
for i in range(lt):
  ii=ord(t[i])-96

  if L[ii]==0:
    print(-1)
    exit()
  else:
    iii=bisect.bisect(A[ii],tmp)
    #print(t[i],A[ii],tmp,iii,ans)
    if iii==L[ii]:
      ans+=ls-tmp+A[ii][0]
      tmp=A[ii][0]
    else:
      ans+=A[ii][iii]-tmp
      tmp=A[ii][iii]
print(ans)  

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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').

Submission attempts (in order):
from bisect import bisect_left, bisect_right
import sys

def solve():
    numChar = 26
    ordA = ord('a')

    Ss = input().rstrip()
    Ts = input().rstrip()

    lenS = len(Ss)
    Ss = [ord(S)-ordA for S in Ss]
    Ts = [ord(T)-ordA for T in Ts]

    setS, setT = set(Ss), set(Ts)
    for T in setT:
        if T not in setS:
            print(-1)
            sys.exit()

    posChs = [[] for _ in range(numChar)]
    for i, S in enumerate(Ss+Ss):
        posChs[S].append(i)
    for ch in range(numChar):
        print(ch, posChs[ch])

    ans = 0
    i = -1
    for T in Ts:
        iPos = bisect_right(posChs[T], i)
        i2 = posChs[T][iPos]
        ans += i2 - i
        i = i2 % lenS

    print(ans)


solve()


from bisect import bisect_left, bisect_right
import sys

def solve():
    numChar = 26
    ordA = ord('a')

    Ss = input().rstrip()
    Ts = input().rstrip()

    lenS = len(Ss)
    Ss = [ord(S)-ordA for S in Ss]
    Ts = [ord(T)-ordA for T in Ts]

    setS, setT = set(Ss), set(Ts)
    for T in setT:
        if T not in setS:
            print(-1)
            sys.exit()

    posChs = [[] for _ in range(numChar)]
    for i, S in enumerate(Ss+Ss):
        posChs[S].append(i)

    ans = 0
    i = -1
    for T in Ts:
        iPos = bisect_right(posChs[T], i)
        i2 = posChs[T][iPos]
        ans += i2 - i
        i = i2 % lenS

    print(ans)


solve()


Verdicts: Wrong Answer

Accepted
Problem: 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').

Submission attempts (in order):
import bisect
s = input()
t = input()
lens=len(s)
lent=len(t)
d = {}

for i in range(lens):
    if s[i] in d:
        d[s[i]].append(i)
    else:
        d[s[i]] = [i]

tmp=0
r=0
snum=0
for i in range(lent):
    if d.get(t[i],None)==None:
        print("-1")
        exit()
    else:
        lis=d[t[i]]
        lis.sort()
        r = bisect.bisect_left(lis,tmp)
        if(len(lis) <= r):
            snum+=lens
            tmp=lis[0]
        else:
            tmp=lis[r]+1
print(snum+tmp+1)




import bisect
s = input()
t = input()
lens=len(s)
lent=len(t)
d = {}
s2=s+s
lens2=len(s2)

for i in range(lens2):
    if s2[i] in d:
        d[s2[i]].append(i)
    else:
        d[s2[i]] = [i]

tmp=0
r=0
snum=0
for i in range(lent):
    if(lens<tmp):
        snum+=lens
        tmp-=lens
        
    if d.get(t[i],None)==None:
        print("-1")
        exit()
    else:
        lis=d[t[i]]
        r = bisect.bisect_left(lis,tmp)
        tmp=lis[r]+1
print(snum+tmp)




Verdicts: Wrong Answer

Accepted