QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#6218. Twisting Palindrome

統計

While researching palindromes, JYY accidentally discovered an interesting type of "twisted palindrome."

JYY has two strings, $A$ and $B$, both of length $N$.

A "twisted string" $S(i, j, k)$ is formed by concatenating the substring of $A$ from the $i$-th character to the $j$-th character with the substring of $B$ from the $j$-th character to the $k$-th character.

For example, if $A = \text{'XYZ'}$ and $B = \text{'UVW'}$, then the twisted string $S(1, 2, 3) = \text{'XYVW'}$.

JYY defines a "twisted palindrome" as one of the following:

  1. A palindrome in $A$;
  2. A palindrome in $B$;
  3. A palindromic twisted string $S(i, j, k)$.

JYY now wants to find the length of the longest twisted palindrome.

Input

The first line contains a positive integer $N$. The second line contains a string $A$ of length $N$ consisting of uppercase letters. The third line contains a string $B$ of length $N$ consisting of uppercase letters.

Output

The first line contains a single integer, representing the length of the longest twisted palindrome.

Examples

Input 1

5
ABCDE
BAECB

Output 1

5

Note

The best twisted palindrome is shown below (characters not in the palindrome are represented by '.'):

.BC..
..ECB

Constraints

For 10% of the data, $N \le 30$. For 30% of the data, $N \le 200$. For 50% of the data, $N \le 2000$. For 100% of the data, $1 \le N \le 10^5$.

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.