QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#4224. String

统计

To help you better understand the problem, here are some definitions regarding strings:

  • For a string $S = s_1 s_2 \cdots s_n$, its length is defined as $\lvert S \rvert = n$.
  • For two strings $S = s_1 s_2 \cdots s_n$ and $T = t_1 t_2 \cdots t_m$, $T$ is called a substring of $S$ if $m = 0$ (i.e., $T$ is an empty string) or $\exists 1 \le i \le j \le n$ such that $T = s_i s_{i + 1} \cdots s_j$. If $m = 0$ or if $i$ can be $1$ in the condition above, $T$ is called a prefix of $S$; if $m = 0$ or if $j$ can be $n$ in the condition above, $T$ is called a suffix of $S$.

Given a string $S$ consisting of lowercase English letters, you need to find the longest possible sequence of strings $(T_0, T_1, \ldots, T_l)$ such that:

  • $T_0$ is a substring of $S$;
  • $\forall 1 \le i \le l$, $\lvert T_i \rvert - \lvert T_{i - 1} \rvert = 1$;
  • $\forall 1 \le i \le l$, there exists a substring $S'_i$ of $S$ with length $\lvert T_i \rvert + 1$ such that the prefix of $S'_i$ of length $\lvert T_{i - 1} \rvert$ is $T_{i - 1}$, and the suffix of $S'_i$ of length $\lvert T_i \rvert$ is $T_i$.

Output the maximum length of such a string sequence (i.e., the maximum value of $l$).

Input

This problem contains multiple test cases.

The first line of input contains an integer $T$, representing the number of test cases. For each test case, the input consists of a single line containing a string $S$ composed of lowercase English letters.

Output

For each test case, output a single integer representing the maximum length of the string sequence as described in the problem.

Examples

Input 1

3
abcd
abab
a

Output 1

2
3
0

Note 1

In the following, the symbol $\epsilon$ is used to denote the empty string.

For the first test case, one possible string sequence is: $T_0 = \epsilon, T_1 = \texttt{b}, T_2 = \texttt{cd}$, where $S'_1 = \texttt{ab}, S'_2 = \texttt{bcd}$.

For the second test case, one possible string sequence is: $T_0 = \epsilon, T_1 = \texttt{b}, T_2 = \texttt{ab}, T_3 = \texttt{bab}$, where $S'_1 = \texttt{ab}, S'_2 = \texttt{bab}, S'_3 = \texttt{abab}$.

For the third test case, one possible string sequence is: $T_0 = \epsilon$.

Examples 2

See the provided files.

The strings in this sample have a certain gradient in length; you can use this sample to check your program.

Examples 3

See the provided files.

This sample satisfies special property A.

Subtasks

Let $\sum |S|$ denote the sum of the lengths of the strings across all test cases in a test set.

For $100 \%$ of the test data, $T \ge 1$, $1 \le \lvert S \rvert \le 5 \times {10}^5$, $1 \le \sum \lvert S \rvert \le 1.5 \times {10}^6$.

Test Case ID $\lvert S \rvert \le$ $\sum \lvert S \rvert \le$ Special Property
$1 \sim 2$ $30$ $150$ None
$3 \sim 5$ $200$ $800$ None
$6 \sim 8$ $1000$ $3000$ None
$9 \sim 11$ $5 \times {10}^5$ $1.5 \times {10}^6$ A
$12 \sim 15$ $6 \times {10}^4$ $3 \times {10}^5$ None
$16 \sim 20$ $5 \times {10}^5$ $1.5 \times {10}^6$ None

Special property A: Each character in the string is generated independently and uniformly at random from the lowercase English alphabet.

Note

The input and output volume for this problem is large; please use efficient input and output methods.

For example, if your code uses cin and cout, you may choose to add the following statements after your input/output redirection statements (freopen, fopen, etc.) to accelerate input and output:

ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

It is not recommended to mix cin, cout with other input/output methods after adding these statements.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.