Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer)

Fixed submission:
import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
S=input()

def search_k(k):
  if k==0:
    return True
  elif k in search_dic:
    return search_dic[k]
  
  for i in range(N-2*k+1):
    for j in range(i+k,N-k+1):
      for kk in range(k):
        if S[i+kk]!=S[j+kk]:
          break
      else:
        search_dic[k]=True
        return True
      
  search_dic[k]=False
  return False

search_dic={}
l,r=0,N//2
while(l<=r):
  mid=(l+r)//2
  
  res1=search_k(mid)
  res2=search_k(mid+1)
  if res1 and not res2:
    print(mid)
    sys.exit(0)
  elif res1:
    l=mid+1
  else:
    r=mid-1

Fixed submission:
import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
S=input()

def search_k(k):
  for i in range(N-2*k+1):
    for j in range(i+k,N-k+1):
      for kk in range(k):
        if S[i+kk]!=S[j+kk]:
          break
      else:
        return True
      
  return False

for k in reversed(range(1,N//2+1)):
  if search_k(k):
    print(k)
    break
else:
  print(0)

Fixed submission:
import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
S=input()

for k in reversed(range(1,N//2+1)):
  for i in range(N-2*k+1):
    S1=S[i:i+k]
    for j in range(i+k,N-k+1):
      S2=S[j:j+k]
      #print(k,S1,S2)
      if S1==S2:
        print(k)
        sys.exit(0)
print(0)

Fixed submission:
import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer)