Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
len_s = len(s)
a = ord('a')
dictionary = {chr(a + i): [] for i in range(26)}
for i in range(len_s):
  dictionary[s[i]].append(i)
repeat = 0
cur_index = -1
for c in t:
  indices = dictionary[c]
  if not indices:
    repeat = 0
    cur_index = -2
    break
  next_index = indices[0]
  for index in indices:
    if index > cur_index:
      next_index = index
      break
  else:
    repeat += 1
  cur_index = next_index
print(len_s * repeat + cur_index + 1)

Fixed submission:
s = input()
t = input()
len_s = len(s)
a = ord('a')
dictionary = {chr(a + i): [[], 0] for i in range(26)}
for i in range(len_s):
  dictionary[s[i]][0].append(i)
  dictionary[s[i]][1] += 1
repeat = 0
cur_index = -1
for c in t:
  indices, len_indices = dictionary[c]
  if len_indices == 0:
    repeat = 0
    cur_index = -2
    break
  inf = -1
  sup = len_indices
  while sup - inf > 1:
    x = (inf + sup) // 2
    if indices[x] > cur_index:
      sup = x
    else:
      inf = x
  if sup == len_indices:
    repeat += 1
    cur_index = indices[0]
  else:
    cur_index = indices[sup]
print(len_s * repeat + cur_index + 1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
len_s = len(s)

a = ord('a')
alph = [[] for _ in range(ord('z')-a+1)]
for i, c in enumerate(s):
  alph[ord(c)-a].append(i)

tmp = alph[ord(t[0])-a]
if tmp:
  idx = min(tmp)
  for c in t[1:]:
    tmp = alph[ord(c)-a]
    if tmp:
      idx += min(map(lambda x: (x - idx - 1) % len_s + 1, tmp))
    else:
      idx = -2
      break
  print(idx + 1)
else:
  print(-1)

Fixed submission:
s = input()
t = input()
len_s = len(s)
a = ord('a')
dictionary = {chr(a + i): [[], 0] for i in range(26)}
for i in range(len_s):
  dictionary[s[i]][0].append(i)
  dictionary[s[i]][1] += 1
repeat = 0
cur_index = -1
for c in t:
  indices, len_indices = dictionary[c]
  if len_indices == 0:
    repeat = 0
    cur_index = -2
    break
  inf = -1
  sup = len_indices
  while sup - inf > 1:
    x = (inf + sup) // 2
    if indices[x] > cur_index:
      sup = x
    else:
      inf = x
  if sup == len_indices:
    repeat += 1
    cur_index = indices[0]
  else:
    cur_index = indices[sup]
print(len_s * repeat + cur_index + 1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
len_s = len(s)

a = ord('a')
alph = [[] for _ in range(ord('z')-a+1)]
for i, c in enumerate(s):
  alph[ord(c)-a].append(i)

tmp = alph[ord(t[0])-a]
if tmp:
  idx = min(tmp)
  for c in t[1:]:
    tmp = alph[ord(c)-a]
    if tmp:
      position = idx % len_s
      delta = len_s
      for i in tmp:
        delta = min(delta, (i - idx - 1) % len_s + 1)
      idx += delta
    else:
      idx = -2
      break
  print(idx + 1)
else:
  print(-1)

Fixed submission:
s = input()
t = input()
len_s = len(s)
a = ord('a')
dictionary = {chr(a + i): [[], 0] for i in range(26)}
for i in range(len_s):
  dictionary[s[i]][0].append(i)
  dictionary[s[i]][1] += 1
repeat = 0
cur_index = -1
for c in t:
  indices, len_indices = dictionary[c]
  if len_indices == 0:
    repeat = 0
    cur_index = -2
    break
  inf = -1
  sup = len_indices
  while sup - inf > 1:
    x = (inf + sup) // 2
    if indices[x] > cur_index:
      sup = x
    else:
      inf = x
  if sup == len_indices:
    repeat += 1
    cur_index = indices[0]
  else:
    cur_index = indices[sup]
print(len_s * repeat + cur_index + 1)