Problem p02962 (python)

Fixed submission:
import sys
import random
s = input()
t = input()
sl = len(s)
tl = len(t)

l = 0
r = 1500000//tl + 1
r2 = r
s *= 1499999//sl + 1
n = len(s)

base1 = 1007
mod1 = 10**9+7
modTank1 = [3000012541,3000012553,3000012563,3000012649,3000012683,3000012709]
mod1 = modTank1[random.randint(0,5)]
base1 = 1007
mod1 = 10**9+7
hash1 = [0]*(n+1)
power1 = [1]*(n+1)
for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1

def rolling_hash(i, j):
    return (hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1


while r - l > 1:
    m = l + (r-l)//2
    lt = len(t)*m
    hash2 = [0]*(lt+1)
    power2 = [1]*(lt+1)
    for i,e in enumerate(t*m):
        hash2[i+1] = (hash2[i]*base1 + ord(e))%mod1
        power2[i+1] = (power2[i]*base1)%mod1
    r_hash = hash2[-1]%mod1

    lt = len(t)*m
    flag = 0
    for i in range(len(s)-lt+1):
        if r_hash == rolling_hash(i, i+lt):
            flag = 1
            break

    if flag == 1:
        l = m
    else:
        r = m

if l*tl >= 1000000:
    print(-1)
else:
    print(l)

Buggy submission (verdict: Runtime Error):
import sys
import random
s = input()
t = input()
sl = len(s)
tl = len(t)

l = 0
r = 1000000//tl + 2s
r2 = r
s *= 999999//sl + 1
n = len(s)
base1 = 1007
mod1 = 10**9+7
modTank1 = [3000012541,3000012553,3000012563,3000012649,3000012683,3000012709]
mod1 = modTank1[random.randint(0,5)]
base1 = 1007
mod1 = 10**9+7
hash1 = [0]*(n+1)
power1 = [1]*(n+1)
for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1

def rolling_hash(i, j):
    return (hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1


while r - l > 1:
    m = l + (r-l)//2
    lt = len(t)*m
    hash2 = [0]*(lt+1)
    power2 = [1]*(lt+1)
    for i,e in enumerate(t*m):
        hash2[i+1] = (hash2[i]*base1 + ord(e))%mod1
        power2[i+1] = (power2[i]*base1)%mod1
    r_hash = hash2[-1]%mod1

    lt = len(t)*m
    flag = 0
    for i in range(len(s)-lt+1):
        if r_hash == rolling_hash(i, i+lt):
            flag = 1
            break

    if flag == 1:
        l = m
    else:
        r = m

if r == r2:
    print(-1)
else:
    print(l)

Buggy submission (verdict: Runtime Error):
import sys
import random
s = input()
t = input()
sl = len(s)
tl = len(t)

if s*tl == t*sl:
    print(-1)
    sys.exit()
    
l = 0
r = 1000000//tl + 1
s *= 999999//sl + 1
n = len(s)
base1 = 1007
mod1 = 10**9+7
modTank1 = [3000012541,3000012553,3000012563,3000012649,3000012683,3000012709]
mod1 = modTank1[random.randint(0,5)]
base1 = 1007
mod1 = 10**9+7
hash1 = [0]*(n+1)
power1 = [1]*(n+1)
for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1

def rolling_hash(i, j):
    return (hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1


while r - l > 1:
    m = l + (r-l)//2
    lt = len(t)*m
    hash2 = [0]*(lt+1)
    power2 = [1]*(lt+1)
    for i,e in enumerate(t*m):
        hash2[i+1] = (hash2[i]*base1 + ord(e))%mod1
        power2[i+1] = (power2[i]*base1)%mod1
    r_hash = hash2[-1]%mod1

    lt = len(t)*m
    flag = 0
    for i in range(len(s)-lt+1):
        if r_hash == rolling_hash(i, i+lt):
            flag = 1
            break

    if flag == 1:
        l = m
    else:
        r = m


print(l)

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd

def main():
  s = input()
  t = input()
  sl = len(s)
  tl = len(t)


  def min_circ(a):
      for i in range(1, len(a)+1):
          if len(a) % i == 0:
              if a[:i] * (len(a)//i) == a:
                  return i


  tc = min_circ(t)
  if len(s) % tc == 0:
      if t[:tc]*(len(s)//min_circ(t)) == s:
          print(-1)
          sys.exit()


  s *= tl//sl + 5
  s *= 3

  sl = len(s)
  count = 0
  ans = 0

  r = 0
  while r + tl <= sl-1:
      if s[r:r+tl] == t:
          count += 1
          ans = max(ans, count)
          r += tl
      else:
          count = 0
          r += 1

  print(ans)

if __name__ == "__main__"
  main()

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd

def main():
  s = input()
  t = input()
  sl = len(s)
  tl = len(t)


  def min_circ(a):
      for i in range(1, len(a)+1):
          if len(a) % i == 0:
              if a[:i] * (len(a)//i) == a:
                  return i


  tc = min_circ(t)
  if len(s) % tc == 0:
      if t[:tc]*(len(s)//min_circ(t)) == s:
          print(-1)
          sys.exit()


  s *= tl//sl + 5
  s *= 3

  sl = len(s)
  count = 0
  ans = 0

  r = 0
  while r + tl <= sl-1:
      if s[r:r+tl] == t:
          count += 1
          ans = max(ans, count)
          r += tl
      else:
          count = 0
          r += 1

  print(ans)

if __name__ == "__main__"

Buggy submission (verdict: Runtime Error):
import sys
from math import gcd
s = input()
t = input()
sl = len(s)
tl = len(t)


def min_circ(a):
    for i in range(1, len(a)+1):
        if len(a) % i == 0:
            if a[:i] * (len(a)//i) == a:
                return i


tc = min_circ(t)
if len(s) % tc == 0:
    if t[:tc]*(len(s)//min_circ(t)) == s:
        print(-1)
        sys.exit()


s *= tl//sl + 5
s *= 3

sl = len(s)
count = 0
ans = 0

r = 0
while r + tl <= sl-1:
    if s[r:r+tl] == t:
        count += 1
        ans = max(ans, count)
        r += tl
    else:
        count = 0
        r += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
s = input()
t = input()
sl = len(s)
tl = len(t)

stemp = s * ((tl)//gcd(sl, tl))
ttemp = t * ((sl)//gcd(sl, tl))
if stemp == ttemp:
    print(-1)

else:
    s *= tl//sl + 5
    s *= 3

    sl = len(s)
    count = 0
    ans = 0

    r = 0
    while r + tl <= sl-1:
        if s[r:r+tl] == t:
            count += 1
            ans = max(ans, count)
            r += tl
        else:
            count = 0
            r += 1

    print(ans)