P30006 [洛谷] [CERC2019] ABB
提高
题目描述

Problem Description

Fernando is employed by the University of Waterloo to complete a development project that the university recently started. Outside the campus, the university wishes to build a representative bungalow street for important foreign visitors and collaborators.

Currently, the street is only partially built, starting from the lakeshore and extending to the edge of the forest. Fernando's task is to complete the street by constructing more bungalows at the edge of the forest. All existing bungalows are situated on one side of the street, and new bungalows should be built on the same side. These bungalows come in various types and are painted in a variety of colors.

In Fernando's view, the layout of the entire street is somewhat chaotic. He is concerned that adding new bungalows will make it look even more chaotic. Therefore, he wants to add some order by choosing appropriate colors for the new bungalows. When the project is completed, the entire color sequence of the bungalows will be symmetrical, meaning that the color sequence is the same when observed from both ends of the street.

Among other things, Fernando wants to know the minimum number of new bungalows he needs to construct and appropriately color to complete the project while meeting the color restrictions.

Brief Problem Statement

Determine the minimum number of letters that need to be appended to the end of a given lowercase letter string to make it a palindrome.

Input Format

The first line contains an integer $N\ (1\le N\le 4\times 10^5)$, representing the number of existing bungalows on the street.

The second line contains a string of $N$ lowercase letters (from a to z), representing the existing bungalow color sequence on the street starting from the lakeshore, where different letters denote different colors.

Output Format

Output a single integer representing the minimum number of new bungalows required to meet Fernando's requirements.

Sample Input and Output

Sample Input #1

3
abb

Sample Output #1

1

Sample Input #2

12
recakjenecep

Sample Output #2

11

Sample Input #3

15
murderforajarof

Sample Output #3

6
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 abb
样例输出
1