output_description: Print the maximum length of a non-empty string that occurs twice or more in S
  as contiguous substrings without overlapping. If there is no such non-empty
  string, print 0 instead.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      S
attempt: N = int(input())
  S = input()
  
  sa = [i for i in range(N + 1)]
  rank = [ord(c) for c in S] + [-1]
  
  k = -1
  key = lambda i: (rank[i], rank[i + k] if i + k <= N else -1)
  
  
  def construct_sa():
      global k, rank
      k = 1
      tmp = [0] * (N + 1)
      while k <= N:
          sa.sort(key=key)
          tmp[sa[0]] = 0
          for i in range(1, N + 1):
              tmp[sa[i]] = tmp[sa[i - 1]] + (key(sa[i - 1]) < key(sa[i]))
          rank = [r for r in tmp]
          k *= 2
  
  
  construct_sa()
  
  
  def exist_twice(s):
      n = len(s)
      if n * 2 > N:
          return False
      l, r = 0, N
      while r - l > 1:
          m = (l + r) // 2
          if S[sa[m] : sa[m] + n] < s:
              l = m
          else:
              r = m
      return r + 1 <= N and S[sa[r] : sa[r] + n] == S[sa[r + 1] : sa[r + 1] + n] == s
  
  
  for l in range(N // 2, 0, -1):
      for i in range(N - l - 1):
          if exist_twice(S[i : i + l]):
              print(l)
              exit()
  print(0)
  
problem_description: Statement
  
  Given is a string S of length N.
  
  Find the maximum length of a non-empty string that occurs twice or more in S
  as contiguous substrings without overlapping.
  
  More formally, find the maximum positive integer len such that there exist
  integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the
  following:
  
    * l_1 + len \leq l_2
  
    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)
  
  If there is no such integer len, print 0.
samples: [{"input": "5\n    ababa", "output": "2\n    \n\nThe strings satisfying the conditions are: `a`, `b`, `ab`, and `ba`. The\nmaximum length among them is 2, which is the answer. Note that `aba` occurs\ntwice in S as contiguous substrings, but there is no pair of integers l_1 and\nl_2 mentioned in the statement such that l_1 + len \\leq l_2.\n\n* * *"}, {"input": "2\n    xy", "output": "0\n    \n\nNo non-empty string satisfies the conditions.\n\n* * *"}, {"input": "13\n    strangeorange", "output": "5"}]