inpl = lambda: list(map(int,input().split()))

N = int(eval(input()))

S = eval(input())



character_pos = [ set() for _ in range(26) ]

for i in range(N):

    character_pos[ord(S[i])-ord('a')].add(i)



ans = 0

continue_list = dict()

for i in range(N):

    s = S[i]

    new_continue_list = dict()

    for p in character_pos[ord(s)-ord('a')]:

        if p < i:

            new_continue_list[p] = 1

    for k, v in list(continue_list.items()):

        if s == S[k+1]  and v + 1 <= i - k - 1:

            new_continue_list[k+1] = v+1

        elif v > ans:

            ans = v

    continue_list = new_continue_list



if len(list(continue_list.values())) > 0:

    ans = max(ans, max(continue_list.values()))

print(ans)
inpl = lambda: list(map(int,input().split()))

N = int(eval(input()))

S = eval(input())

character_pos = [ set() for _ in range(26) ]

ans = 0

continue_list = dict()

for i in range(N):

    s = S[i]

    new_continue_list = dict()

    cpos = character_pos[ord(s)-ord('a')]

    for p in cpos:

        new_continue_list[p] = 1

    cpos.add(i)

    for k, v in list(continue_list.items()):

        if s == S[k+1]  and v + 1 <= i - k - 1:

            new_continue_list[k+1] = v+1

        elif v > ans:

            ans = v

    continue_list = new_continue_list



if len(list(continue_list.values())) > 0:

    ans = max(ans, max(continue_list.values()))

print(ans)
inpl = lambda: list(map(int, input().split()))
N = int(eval(input()))
S = eval(input())
character_pos = [set() for _ in range(26)]
for i in range(N):
    character_pos[ord(S[i]) - ord("a")].add(i)
ans = 0
continue_list = dict()
for i in range(N):
    s = S[i]
    new_continue_list = dict()
    for p in character_pos[ord(s) - ord("a")]:
        if p < i:
            new_continue_list[p] = 1
    for k, v in list(continue_list.items()):
        if s == S[k + 1] and v + 1 <= i - k - 1:
            new_continue_list[k + 1] = v + 1
        elif v > ans:
            ans = v
    continue_list = new_continue_list
if len(list(continue_list.values())) > 0:
    ans = max(ans, max(continue_list.values()))
print(ans)

inpl = lambda: list(map(int, input().split()))
N = int(eval(input()))
S = eval(input())
character_pos = [set() for _ in range(26)]
ans = 0
continue_list = dict()
for i in range(N):
    s = S[i]
    new_continue_list = dict()
    cpos = character_pos[ord(s) - ord("a")]
    for p in cpos:
        new_continue_list[p] = 1
    cpos.add(i)
    for k, v in list(continue_list.items()):
        if s == S[k + 1] and v + 1 <= i - k - 1:
            new_continue_list[k + 1] = v + 1
        elif v > ans:
            ans = v
    continue_list = new_continue_list
if len(list(continue_list.values())) > 0:
    ans = max(ans, max(continue_list.values()))
print(ans)

-for i in range(N): -    character_pos[ord(S[i]) - ord("a")].add(i) -    for p in character_pos[ord(s) - ord("a")]: -        if p < i: -            new_continue_list[p] = 1 +    cpos = character_pos[ord(s) - ord("a")] +    for p in cpos: +        new_continue_list[p] = 1 +    cpos.add(i)