n = gets.to_i
word = gets.chomp.split("")
ar = Array.new(n+1).map{Array.new(n+1,0)}
ans = 0
for i in 1..n
  for j in 1..n
    if (i < j - ar[i-1][j-1] || i > j + ar[i-1][j-1]) && word[i-1] == word[j-1]
      ar[i][j] += 1 + ar[i-1][j-1]
      if ans < ar[i][j]
        ans = ar[i][j]
      end
    end
  end
end
puts ans
