#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]



sys.setrecursionlimit(1000000)

mod = 1000000007



def solve():

    def Z_algorithm(s):

        n = len(s)

        z = [0]*n

        z[0] = n

        j = 0

        for i in range(1,n):

            while i+j < n and s[j] == s[i+j]:

                j += 1

            z[i] = j

            if j == 0:

                i += 1

                continue

            k = 1

            while i+k < n and k+z[k] < j:

                z[i+k] = z[k]

                k += 1

            i += k

            j -= k

        return z

    n = I()

    s = eval(input())

    ans = 0

    for i in range(n):

        z = Z_algorithm(s[i:])

        for j in range(i,n):

            l = min(j-i,z[j-i])

            if ans < l:

                ans = l

    print(ans)

    return



#Solve

if __name__ == "__main__":

    solve()

#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]



sys.setrecursionlimit(1000000)

mod = 1000000007



def solve():

    def Z_algorithm(s):

        n = len(s)

        z = [0]*n

        z[0] = n

        c = 1

        for i in range(1,n):

            if i+z[i-c] < c+z[c]:

                z[i] = z[i-c]

            else:

                j = max(0,c+z[c]-i)

                while i+j < n and s[j] == s[i+j]:

                    j += 1

                z[i] = j

                c = i

        return z

    n = I()

    s = eval(input())

    ans = 0

    for i in range(n):

        z = Z_algorithm(s[i:])

        for j in range(i,n):

            l = min(j-i,z[j-i])

            if ans < l:

                ans = l

    print(ans)

    return



#Solve

if __name__ == "__main__":

    solve()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def I():
    return int(sys.stdin.readline())


def LS():
    return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    def Z_algorithm(s):
        n = len(s)
        z = [0] * n
        z[0] = n
        j = 0
        for i in range(1, n):
            while i + j < n and s[j] == s[i + j]:
                j += 1
            z[i] = j
            if j == 0:
                i += 1
                continue
            k = 1
            while i + k < n and k + z[k] < j:
                z[i + k] = z[k]
                k += 1
            i += k
            j -= k
        return z

    n = I()
    s = eval(input())
    ans = 0
    for i in range(n):
        z = Z_algorithm(s[i:])
        for j in range(i, n):
            l = min(j - i, z[j - i])
            if ans < l:
                ans = l
    print(ans)
    return


# Solve
if __name__ == "__main__":
    solve()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def I():
    return int(sys.stdin.readline())


def LS():
    return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    def Z_algorithm(s):
        n = len(s)
        z = [0] * n
        z[0] = n
        c = 1
        for i in range(1, n):
            if i + z[i - c] < c + z[c]:
                z[i] = z[i - c]
            else:
                j = max(0, c + z[c] - i)
                while i + j < n and s[j] == s[i + j]:
                    j += 1
                z[i] = j
                c = i
        return z

    n = I()
    s = eval(input())
    ans = 0
    for i in range(n):
        z = Z_algorithm(s[i:])
        for j in range(i, n):
            l = min(j - i, z[j - i])
            if ans < l:
                ans = l
    print(ans)
    return


# Solve
if __name__ == "__main__":
    solve()

-        j = 0 +        c = 1 -            while i + j < n and s[j] == s[i + j]: -                j += 1 -            z[i] = j -            if j == 0: -                i += 1 -                continue -            k = 1 -            while i + k < n and k + z[k] < j: -                z[i + k] = z[k] -                k += 1 -            i += k -            j -= k +            if i + z[i - c] < c + z[c]: +                z[i] = z[i - c] +            else: +                j = max(0, c + z[c] - i) +                while i + j < n and s[j] == s[i + j]: +                    j += 1 +                z[i] = j +                c = i