N=gets.to_i
S=gets.chomp.codepoints
dp=Array.new(N+1,0)
next_dp=Array.new(N+1,0)
ans=0
(1..N-1).to_a.reverse.each do |j|
    if j==N-1
        (0..j-1).to_a.reverse.each do |i|
            next_dp[i]+=1 if S[i]==S[j]
        end
    else
        (0..j-1).to_a.reverse.each do |i|
            next_dp[i]=[dp[i+1]+1,j-i].min if S[i]==S[j]
        end
    end
    dp=next_dp.clone
    next_dp=Array.new(N+1,0)
    cnt=dp.max
    ans = ans < cnt ? cnt : ans
end
p ans
