Universal Cup Judging System

Universal Cup

حد الوقت: 1.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

Вам дано рядок $s$ довжини $n$.

Для кожної позиції $i$ ($1 \le i \le n$) позначимо через $t_i$ рядок, отриманий із $s$ видаленням $i$-го символу рядка $s$ (зі збереженням відносного порядку всіх інших символів).

Для двох рядків $x$ і $y$ позначимо через $\operatorname{lcp}(x, y)$ довжину їхнього найбільшого спільного префікса, тобто найбільше ціле число $\ell \ge 0$ таке, що перші $\ell$ символів рядків $x$ і $y$ збігаються (тобто $x_1 = y_1, x_2 = y_2, \dots, x_\ell = y_\ell$).

Ваше завдання — вибрати дві різні позиції $i$ та $j$ так, щоб значення $\operatorname{lcp}(t_i, t_j)$ було якомога більшим, і обчислити це максимально можливе значення.

Формально вам потрібно знайти

$$\max_{1 \le i < j \le n} \operatorname{lcp}(t_i, t_j).$$

Вам не потрібно виводити $i$ або $j$, слід вивести лише максимальне значення $\operatorname{lcp}(t_i, t_j)$.

Вхідні дані

Перший рядок містить одне ціле число $T$ ($1 \le T \le 2 \cdot 10^5$), що позначає кількість наборів вхідних даних.

Кожен набір вхідних даних складається з одного рядка, що містить рядок $s$ ($2 \le |s| \le 5 \cdot 10^5$). Гарантується, що $s$ містить лише малі латинські літери, а сума $|s|$ не перевищує $5 \cdot 10^5$.

Вихідні дані

Для кожного набору вхідних даних виведіть в окремому рядку одне ціле число — максимально можливе значення $\operatorname{lcp}(t_i, t_j)$ за всіма парами індексів $i \ne j$.

Приклади

Вхідні дані 1

5
abac
abbbb
cbacb
babcc
aa

Вихідні дані 1

2
4
3
4
1

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.