import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    dp = [0] * (N + 1)
    ans = 0

    for i in range(N - 1, -1, -1):
        for j in range(i + 1, N):
            dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0
            if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

    print(ans)
    return


if __name__ == '__main__':
    main() import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 1 << 60 INF 1 << 60 1 60 MOD = 1000000007 MOD 1000000007 def main():
    N = int(readline())
    S = readline().strip()

    dp = [0] * (N + 1)
    ans = 0

    for i in range(N - 1, -1, -1):
        for j in range(i + 1, N):
            dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0
            if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

    print(ans)
    return main N = int(readline()) N int(readline()) int readline() readline S = readline().strip() S readline().strip() ().strip () readline strip dp = [0] * (N + 1) dp [0] * (N + 1) [0] 0 N + 1 N 1 ans = 0 ans 0 for i in range(N - 1, -1, -1):
        for j in range(i + 1, N):
            dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0
            if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

     i range(N - 1, -1, -1) range N - 1 N 1 -1 -1 for j in range(i + 1, N):
            dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0
            if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

     j range(i + 1, N) range i + 1 i 1 N dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0 dp[j] dp j dp[j + 1] + 1 if S[i] == S[j] else 0 S[i] == S[j] S[i] S i S[j] S j dp[j + 1] + 1 dp[j + 1] dp j + 1 j 1 1 0 if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

     ans < min(dp[j], j - i) ans min(dp[j], j - i) min dp[j] dp j j - i j i ans = min(dp[j], j - i) ans min(dp[j], j - i) min dp[j] dp j j - i j i print(ans) print ans return if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main readline = sys.stdin.readline sys.stdin.readline readline read = sys.stdin.read sys.stdin.read read INF = 1 << 60 1 << 60 INF def main():
    N = int(readline())
    S = readline().strip()

    dp = [0] * (N + 1)
    ans = 0

    for i in range(N - 1, -1, -1):
        for j in range(i + 1, N):
            dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0
            if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

    print(ans)
    return def main():
    N = int(readline())
    S = readline().strip()

    dp = [0] * (N + 1)
    ans = 0

    for i in range(N - 1, -1, -1):
        for j in range(i + 1, N):
            dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0
            if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

    print(ans)
    return main readlines = sys.stdin.readlines sys.stdin.readlines readlines MOD = 1000000007 1000000007 MOD
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    dp = [0] * (N + 1)
    ans = 0

    for i in range(N - 1, -1, -1):
        for j in range(i + 1, N):
            dp[j] = dp[j + 1] + 1 if S[i] == S[j] else 0
            if ans < min(dp[j], j - i):
                ans = min(dp[j], j - i)

    print(ans)
    return


if __name__ == '__main__':
    main()
