Problem p02937 (python)

Fixed submission:
def f():
    s,t=input(),input()
    n,m=len(s),len(t)
    table=[[]for i in  range(26)]
    d={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

    for j in range(n):
        table[d[s[j]]].append(j)
    now=0
    ind=0
    if set(list(t))-set(list(s)):print(-1);exit()
    from bisect import bisect_left as bl
    for p in t:
        if ind>table[d[p]][-1]:now+=1;ind=0
        ind=table[d[p]][bl(table[d[p]],ind)]+1

    print(now*n+ind)
if __name__ == "__main__":
    f()

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
l=list()
for _ in list(t):
  if [i for i,x in enumerate(list(s)) if x==_] != list():
    l.append([i for i,x in enumerate(list(s)) if x==_])
  else:
    print(-1)
    exit()
if len(t)==1:
  print(s.index(t)+1)
  exit()
ed=l[0][0]
cd=0
for i in range(len(t))[1:-1]:
  k=l[i]
  if max(k+[ed])==ed :
    cd+=1
    ed=k[0]
  else:
    ex=sorted(k+[ed])
    exex=ex.index()
    ed=k[exex]
k=l[len(t)-1]
if max(k+[ed])==ed :
  print((cd+1)*len(s)+min(k)+1)
else:
  ex=sorted(k+[ed])
  exex=ex.index(ed)
  ed=k[exex]
  print((cd)*len(s)+ed+1)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
l=list()
for _ in list(t):
  if [i for i,x in enumerate(list(s)) if x==_] != list():
    l.append([i for i,x in enumerate(list(s)) if x==_])
  else:
    print(-1)
    exit()
if len(t)==1:
  print(s.index(t)+1)
  exit()
ed=l[0][0]
for i in range(len(t))[1:-1]:
  k=l[i]
  if max(k+[ed])==ed :
    cd+=1
    ed=k[0]
  else:
    ex=sorted(k+[ed])
    exex=ex.index()
    ed=k[exex]
k=l[len(t)-1]
if max(k+[ed])==ed :
  print((cd+1)*len(s)+min(k)+1)
else:
  ex=sorted(k+[ed])
  exex=ex.index(ed)
  ed=k[exex]
  print((cd)*len(s)+ed+1)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
if len(t)==1:
  try:
    print(s.index(t)+1)
  except ValueError:
    print(-1)
    exit()
  l=list()
  for _ in list(t):
    l.append([i for i,x in enumerate(list(s)) if x==_]) if [i for i,x in enumerate(list(s)) if x==_]!=[] else print(-1) and exit()
  ed=l[0][0]
  for i in range(len(t))[1:-1]:
    k=l[i]
    if max(k+[ed])==ed :
      cd+=1
    else:
      ex=list(sorted(k+[ed])).index(ed)
      ed=k[ex]
k=l[len(t)-1]
if max(k+[ed])==ed :
  print((cd+1)*len(s)+min(k)+1)
else:
  ex=list(sorted(k+[ed])).index(ed)
  ed=k[ex]
  print((cd)*len(s)+ed+1)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
if len(t)==1:
  try:
    print(s.index(t)+1)
  except ValueError:
    print(-1)
    exit()
else:
  cd=0
  def cdcd():
    print(-1)
    exit()


  l=list()
  for _ in list(t):
    l.append([i for i,x in enumerate(list(s)) if x==_]) if [i for i,x in enumerate(list(s)) if x==_]!=[] else cdcd
  ed=l[0][0]
  for i in range(len(t))[1:-1]:
    k=l[i]
    if max(k+[ed])==ed :
      cd+=1
    else:
      ex=list(sorted(k+[ed])).index(ed)
      ed=k[ex]
k=l[len(t)-1]
if max(k+[ed])==ed :
  print((cd+1)*len(s)+min(k)+1)
else:
  ex=list(sorted(k+[ed])).index(ed)
  ed=k[ex]
  print((cd)*len(s)+ed+1)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
if len(t)==1:
  try:
    print(s.index(t)+1)
  except ValueError:
    print(-1)
    exit()
else:
  cd=0
  l=list()
  for _ in list(t):
    l.append([i for i,x in enumerate(list(s)) if x==_])
  try:
    ed=l[0][0]
  except IndexError:
    print(-1)
    exit()
  for i in range(len(t))[1:]:
    k=l[i]
    if k==[]:
      print(-1)
      exit()
    if max(k+[ed])==ed :
      cd+=1
      if i==len(t)-1:
        print((cd)*len(s)+ed+1)
        exit()
      else:
        ed=min(k)
    else:
      ex=list(sorted(k+[ed])).index(ed)
      ed=k[ex]
print((cd)*len(s)+ed+1)