import sys
import math
import copy
import random
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

dic = dict()

def zalg(s):
    n = len(s)
    ret = [0] * n
    ret[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        ret[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1

        i += k
        j -= k

    return ret

def solve(n=None, s1=None, s2=None):
    n = getN()
    s = list(getS())
    ans = 0
    for i in range(n):
        ps = s[i:]
        z = zalg(ps)
        for i, zz in enumerate(z):
            if i >= zz:
                ans = max(ans, zz)
    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
    return


if __name__ == "__main__":
    # main()
    solve()
 import sys sys import math math import copy copy import random random import itertools itertools from heapq import heappush, heappop, heapify from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline getS = lambda: input().strip() getS lambda: input().strip() input().strip() ().strip () input strip getN = lambda: int(input()) getN lambda: int(input()) int(input()) int input() input getList = lambda: list(map(int, input().split())) getList lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split int(x) - 1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) - 1 int(x) int x 1 getZList = lambda: [int(x) - 1 for x in input().split()] getZList lambda: [int(x) - 1 for x in input().split()] [int(x) - 1 for x in input().split()] INF = float("inf") INF float("inf") float "inf" MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 divide = lambda x: pow(x, MOD-2, MOD) divide lambda x: pow(x, MOD-2, MOD) pow(x, MOD-2, MOD) pow x MOD-2 MOD 2 MOD x dic = dict() dic dict() dict def zalg(s):
    n = len(s)
    ret = [0] * n
    ret[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        ret[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1

        i += k
        j -= k

    return ret zalg n = len(s) n len(s) len s ret = [0] * n ret [0] * n [0] 0 n ret[0] = n ret[0] ret 0 n i, j = 1, 0 i 1 j 0 while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        ret[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1

        i += k
        j -= k

     i < n i n while i + j < n and s[j] == s[i+j]:
            j += 1
         i + j < n and s[j] == s[i+j] i + j < n i + j i j n s[j] == s[i+j] s[j] s j s[i+j] s i+j i j j += 1 j 1 ret[i] = j ret[i] ret i j if j == 0:
            i += 1
            continue

         j == 0 j 0 i += 1 i 1 continue k = 1 k 1 while k < j and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1

         k < j and k + ret[k] < j k < j k j k + ret[k] < j k + ret[k] k ret[k] ret k j ret[i + k] = ret[k] ret[i + k] ret i + k i k ret[k] ret k k += 1 k 1 i += k i k j -= k j k return ret ret s s def solve(n=None, s1=None, s2=None):
    n = getN()
    s = list(getS())
    ans = 0
    for i in range(n):
        ps = s[i:]
        z = zalg(ps)
        for i, zz in enumerate(z):
            if i >= zz:
                ans = max(ans, zz)
    print(ans) solve n = getN() n getN() getN s = list(getS()) s list(getS()) list getS() getS ans = 0 ans 0 for i in range(n):
        ps = s[i:]
        z = zalg(ps)
        for i, zz in enumerate(z):
            if i >= zz:
                ans = max(ans, zz)
     i range(n) range n ps = s[i:] ps s[i:] s i: i z = zalg(ps) z zalg(ps) zalg ps for i, zz in enumerate(z):
            if i >= zz:
                ans = max(ans, zz)
     i zz enumerate(z) enumerate z if i >= zz:
                ans = max(ans, zz)
     i >= zz i zz ans = max(ans, zz) ans max(ans, zz) max ans zz print(ans) print ans n=None n None s1=None s1 None s2=None s2 None def main():
    n = getN()
    for _ in range(n):
        solve()
    return main n = getN() n getN() getN for _ in range(n):
        solve()
     _ range(n) range n solve() solve return if __name__ == "__main__":
    # main()
    solve() __name__ == "__main__" __name__ "__main__" solve() solve getN = lambda: int(input()) lambda: int(input()) getN getZList = lambda: [int(x) - 1 for x in input().split()] lambda: [int(x) - 1 for x in input().split()] getZList divide = lambda x: pow(x, MOD-2, MOD) lambda x: pow(x, MOD-2, MOD) divide input = sys.stdin.readline sys.stdin.readline input MOD = 10**9 + 7 10**9 + 7 MOD getS = lambda: input().strip() lambda: input().strip() getS def solve(n=None, s1=None, s2=None):
    n = getN()
    s = list(getS())
    ans = 0
    for i in range(n):
        ps = s[i:]
        z = zalg(ps)
        for i, zz in enumerate(z):
            if i >= zz:
                ans = max(ans, zz)
    print(ans) def solve(n=None, s1=None, s2=None):
    n = getN()
    s = list(getS())
    ans = 0
    for i in range(n):
        ps = s[i:]
        z = zalg(ps)
        for i, zz in enumerate(z):
            if i >= zz:
                ans = max(ans, zz)
    print(ans) solve def zalg(s):
    n = len(s)
    ret = [0] * n
    ret[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        ret[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1

        i += k
        j -= k

    return ret def zalg(s):
    n = len(s)
    ret = [0] * n
    ret[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        ret[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1

        i += k
        j -= k

    return ret zalg getList = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) getList def main():
    n = getN()
    for _ in range(n):
        solve()
    return def main():
    n = getN()
    for _ in range(n):
        solve()
    return main dic = dict() dict() dic INF = float("inf") float("inf") INF
import sys
import math
import copy
import random
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

dic = dict()

def zalg(s):
    n = len(s)
    ret = [0] * n
    ret[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        ret[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1

        i += k
        j -= k

    return ret

def solve(n=None, s1=None, s2=None):
    n = getN()
    s = list(getS())
    ans = 0
    for i in range(n):
        ps = s[i:]
        z = zalg(ps)
        for i, zz in enumerate(z):
            if i >= zz:
                ans = max(ans, zz)
    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
    return


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

