QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#8668. 回文路径

统计

给定一个 $2\times n$ 的网格,左上角的格子编号为 $(1, 1)$,右下角为 $(2, n)$。每个格子有一个字符(只包含小写字母),你可以从任意格子开始,每一步向右或向下移动,然后在任意格子停止。容易发现这样走出来的一定是一条简单路径(即经过每个格子一次)。

若将一条路径的字符按走的顺序取出组成的字符串是回文串,则称这条路径是回文路径。定义路径的长度为经过格子的个数,你需要求出最长的回文路径的长度是多少。

Input

第一行一个正整数 $n$。

接下来两行,每行为一个长为 $n$ 的字符串,第一行的第 $i$ 个字符表示格子 $(1,i)$ 里的字符,第二行同理。

Output

一个整数表示最长的回文路径的长度。

Example

Input

5
pkusc
pkukp

Output

6

Scoring

Subtask1 ($30\%$): $n\le 1000$。

Subtask2 ($20\%$): 保证只往右走就能走出最长的回文路径。

Subtask3 ($50\%$): 无特殊限制。

对于所有数据,$1\le n\le 10^5$,字符串只包含小写字母。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.