P10992 [Lanqiao Cup 2023 National Python A] Longest Same-Type Substring

Description

For two strings $A, B$ of the same length, if for any $i, j$, the two conditions $A_i = A_j$ and $B_i = B_j$ are either both true or both false at the same time, then we call $A, B$ a pair of same-type strings. For example, `aabab` and `xxkxk` are a pair of same-type strings, while `abcde` and `abcdd` are not. Given $S, T$, find the largest possible $k$ such that $S, T$ each contain a substring of length $k$, denoted $S', T'$, and $S', T'$ are a pair of same-type strings.

Input Format

The input consists of two lines. Each line contains a string, representing $S$ and $T$.

Output Format

Output one line containing an integer $k$, representing the answer.

Explanation/Hint

For $40\%$ of the testdata, $|S|, |T| \le 500$. For $50\%$ of the testdata, $|S|, |T| \le 2000$. For all testdata, $1 \le |S|, |T| \le 10^5$, and $S, T$ contain only lowercase English letters. Translated by ChatGPT 5