P14804 [CCPC 2024 Harbin Site] A Simple String Problem

Description

You are given a character grid with $2$ rows and $n$ columns, where each cell contains a lowercase letter. You can start at any position in the grid and move several steps, with each step either to the right or downward, stopping at any cell. Concatenating the characters from the cells visited in order forms a string. A string $S$ is called a double string if and only if there exists a non-empty string $T$ such that $S = TT$. For example, $\texttt{aa}$ and $\texttt{xyzxyz}$ are double strings, while $\texttt{a}$ and $\texttt{xyzyz}$ are not. Given the character grid, find the length of the longest double string you can obtain.

Input Format

The first line contains an integer $n$ ($1 \le n \le 2 \times 10^5$), representing the number of columns in the character grid. The next two lines contain two strings of length $n$ consisting only of lowercase English letters, representing the character grid.

Output Format

Output a single integer, representing the length of the longest double string you can obtain.

Explanation/Hint

In the first example, the longest double string can be obtained as follows (not unique): $$ \begin{aligned} \underline{\texttt{abc}}\texttt{ab}\\ \texttt{ac}\underline{\texttt{abc}} \end{aligned} $$