Problem p02937 (python)

Fixed submission:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

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

s = set(S)
t = set(T)
f = True
for v in t:
    if v not in s:
        f = False
        break
if f == False:
    print(-1)
    exit()

m = defaultdict(list)
for i in range(len(S)):
    m[S[i]].append(i)

counter = 0
before = -1
for v in T:
    c = m[v]
    index = bisect.bisect_left(c, before+1)
    if index >= len(c):
        before = -1
        index = bisect.bisect_left(c, before+1)
        before = c[index]
        counter += 1
    else:
        before = c[index]

print(counter * len(S) + before + 1)

Buggy submission (verdict: Runtime Error):
import sys
import bisect
sys.setrecursionlimit(200000)
input = sys.stdin.readline

S = input().strip()
S = S * 100000
T = input().strip()
l = len(S)

m = {}
for i in range(l):
    c = S[i]
    if m.get(c) == None:
        m[c] = []
    m[c].append(i)

a = [None] * len(T)
for i in range(len(T)):
    if m.get(T[i]) == None:
        print(-1)
        exit()
    a[i] = m[T[i]]

before = min(a[0])
bl = 0
for v in a[1:]:
    index = bisect.bisect_right(v, before)
    if before >= bl * len(S) + v[index]:
        bl += 1
    before = bl * len(S) + v[index] 

print(before + 1)

Buggy submission (verdict: Runtime Error):
use std::io::stdin;
use std::time::SystemTime;
use std::collections::HashMap;

#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read<T>() -> T
where T: std::str::FromStr
{
    read_line().parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T>() -> Vec<T>
where T: std::str::FromStr
{
    read_line().split(" ").map(|n| n.parse::<T>().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn read_chars() -> Vec<char>
{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn print_time() -> () {
    println!("{:?}", SystemTime::now());
}

trait BinarySearchLeft<T> {
    fn binary_search_left(&self, x: &T) -> Result<usize, usize>;
}

impl<T> BinarySearchLeft<T> for Vec<T>
where T: std::cmp::Ord + std::fmt::Debug
{
    fn binary_search_left(&self, x: &T) -> Result<usize, usize> {
        let index = self.binary_search(x);
        match index {
            Ok(index) => {
                for i in (1..index+1).rev() {
                    if self[i] != self[i - 1] {
                        return Ok(i - 1)
                    }
                }
                
                Ok(index)
            },
            _ => index,
        }
    }
}

#[allow(unused_variables)]
fn main() {
    let s = read_chars();
    let t = read_chars();

    for p in t.iter() {
        if !s.contains(p) {
            println!("-1");
            return
        }
    }

    let mut index = 0;
    let mut counter = 0;
    let mut ff = false;
    let mut it = t.iter();
    let mut c = it.next();
    while true {
        if ff {
            ff = false;
            c = it.next();
        }

        if let Some(c) = c {
            let mut f = true;
            for v in s.iter().skip(index) {
                index += 1;
                if c == v {
                    f = false;
                    ff = true;
                    break;
                }
            }
            if f {
                index = 0;
                counter += 1;
            }
        } else {
            break;
        }
    }

    println!("{}", counter * s.len() + index);
}