题库练习 String Journey
← 上一题 下一题 →

A12074 | String Journey

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

We call a sequence of strings $t_{1},...,t_{k}$ a journey of length $k$ , if for each $i>1$ $t_{i}$ is a substring of $t_{i-1}$ and length of $t_{i}$ is strictly less than length of $t_{i-1}$ . For example, ${ab,b}$ is a journey, but ${ab,c}$ and ${a,a}$ are not.

Define a journey on string $s$ as journey $t_{1},...,t_{k}$ , such that all its parts can be nested inside $s$ in such a way that there exists a sequence of strings $u_{1},...,u_{k+1}$ (each of these strings can be empty) and $s=u_{1}t_{1}u_{2}t_{2}...\ u_{k}t_{k}u_{k+1}$ . As an example, ${ab,b}$ is a journey on string $abb$ , but not on $bab$ because the journey strings $t_{i}$ should appear from the left to the right.

The length of a journey on a string is the number of strings in it. Determine the maximum possible length of a journey on the given string $s$ .

输入格式

The first line contains a single integer $n$ ( $1<=n<=500000$ ) — the length of string $s$ .

The second line contains the string $s$ itself, consisting of $n$ lowercase Latin letters.

输出格式

Print one number — the maximum possible length of string journey on $s$ .

输入输出样例

输入 #1
7
abcdbcc
输出 #1
3
输入 #2
4
bbcb
输出 #2
2
C++ 编辑器
输入
输出