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: from sys import stdout
  
  printn = lambda x: stdout.write(str(x))
  inn = lambda: int(input())
  inl = lambda: list(map(int, input().split()))
  inm = lambda: map(int, input().split())
  ins = lambda: input().strip()
  DBG = True  # and False
  BIG = 999999999
  R = 10**9 + 7
  from collections import defaultdict
  
  
  def ddprint(x):
      if DBG:
          print(x)
  
  
  n = inn()
  s = ins()
  h = defaultdict(list)
  for i in range(n):
      for j in range(i + 1, min(n + 1, i + 100)):
          t = s[i:j]
          h[t].append((i, j))
  mx = mx2 = 0
  for t in h:
      if len(t) < mx or len(h[t]) < 2:
          continue
      m = len(h[t])
      for x in range(m - 1):
          for y in range(x + 1, m):
              if h[t][x][1] <= h[t][y][0] or h[t][y][1] <= h[t][x][0]:
                  mx = max(mx, len(t))
                  if len(t) == 100:
                      z = h[t][x][1]
                      u = h[t][y][1]
                      k = abs(z - u) - 100
                      for j in range(k):
                          if z + j >= n or u + j >= n or s[z + j] != s[u + j]:
                              break
                          mx2 = max(mx2, 100 + j + 1)
  print(max(mx, mx2))
  
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"}]