n = gets.strip.to_i
ss = gets.strip.split('')

dp = Array.new(n) { [] }

result = 0
n.times do |ii|
  n.times do |jj|
    i = n-1-ii
    j = n-1-jj
    if ss[i]==ss[j] && dp[i+1] && dp[i+1][j+1]
      dp[i][j] = dp[i+1][j+1] + 1
    else
      dp[i][j]=0
    end
  end
end

result = 0
n.times do |i|
  n.times do |j|
    next if i>=j
    result = [dp[i][j], result].max
  end
end
#p dp
p result

