Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

path=[-1]*len(s)
for i in range(len(s)):
  if match_list[i]:
    path[i]=(i+len(t))%len(s)
#print(path)

dist=[-1]*len(s)
for i in range(len(s)):
  d=0
  ii=i
  while path[ii]!=-1:
    if d>len(s):
      print(-1)
      sys.exit(0)
    elif dist[ii]!=-1:
      d+=dist[ii]
      break
    ii=path[ii]
    d+=1
  dist[i]=d
    
#print(dist)
print(max(dist))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

path=[-1]*len(s)
for i in range(len(s)):
  if match_list[i]:
    path[i]=(i+len(t))%len(s)
#print(path)

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]!=-1:
    continue
    
  d=0
  offset=0
  stack=[i]
  ii=i
  while path[ii]!=-1:
    if d>len(s):
      print(-1)
      sys.exit(0)
    elif dist[ii]!=-1:
      offset=dist[ii]
      break    
    ii=path[ii]
    stack.append(ii)
    d+=1
  
  cnt=0
  while stack:
    p=stack.pop()
    dist[p]=offset+cnt
    cnt+=1
    
#print(dist)
print(max(dist))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

graph=[[] for _ in range(len(s))]
for i in range(len(s)):
  if match_list[i]:
    graph[i].append((i+len(t))%len(s))
#print(graph)

def dfs(u,i):
  if dist[u]!=-1:
    return dist[u]
  elif not graph[u]:
    dist[u]=0
    return 0
  else:
    if i>len(s):
      print(-1)
      sys.exit(0)
    v=graph[u][0]
    res=dfs(v,i+1)
    dist[u]=1+res
    return 1+res

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]==-1:
    dfs(i,0)
    
#print(dist)
print(max(dist))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

path=[-1]*len(s)
for i in range(len(s)):
  if match_list[i]:
    path[i]=(i+len(t))%len(s)
#print(path)

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]!=-1:
    continue
    
  d=0
  offset=0
  stack=[i]
  ii=i
  while path[ii]!=-1:
    if d>len(s):
      print(-1)
      sys.exit(0)
    elif dist[ii]!=-1:
      offset=dist[ii]
      break    
    ii=path[ii]
    stack.append(ii)
    d+=1
  
  cnt=0
  while stack:
    p=stack.pop()
    dist[p]=offset+cnt
    cnt+=1
    
#print(dist)
print(max(dist))

Buggy python submission (verdict: Runtime Error):
import sys
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

graph=[[] for _ in range(len(s))]
for i in range(len(s)):
  if match_list[i]:
    graph[i].append((i+len(t))%len(s))
#print(graph)

def dfs(u,i):
  if dist[u]!=-1:
    return dist[u]
  elif not graph[u]:
    dist[u]=0
    return 0
  else:
    if i>len(s):
      print(-1)
      sys.exit(0)
    v=graph[u][0]
    res=dfs(v,i+1)
    dist[u]=1+res
    return 1+res

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]==-1:
    dfs(i,0)
    
#print(dist)
print(max(dist))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

path=[-1]*len(s)
for i in range(len(s)):
  if match_list[i]:
    path[i]=(i+len(t))%len(s)
#print(path)

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]!=-1:
    continue
    
  d=0
  offset=0
  stack=[i]
  ii=i
  while path[ii]!=-1:
    if d>len(s):
      print(-1)
      sys.exit(0)
    elif dist[ii]!=-1:
      offset=dist[ii]
      break    
    ii=path[ii]
    stack.append(ii)
    d+=1
  
  cnt=0
  while stack:
    p=stack.pop()
    dist[p]=offset+cnt
    cnt+=1
    
#print(dist)
print(max(dist))