P23594 [AtCoder] Heyho and Replacement
普及-
题目描述

Problem Description

A string that is formed by repeating a certain string twice is called a square. For example, abcabc and abababab are squares, but abc and ababab are not.

Heyho found a string \( S \) consisting of \( N \) lowercase English letters on the street. Being fond of squares, Heyho decided to obtain a square by repeatedly performing the following operation on the string \( S \):

  • Choose an integer \( p \) such that \( 1 \leq p \leq N \) and a lowercase English letter \( c \). Then, replace the \( p \)-th character of \( S \) with \( c \).

Determine the minimum number of operations required for Heyho to obtain a square.

Input Format

The input is given from the standard input in the following format:

\( N \) \( S \)

  • The first line contains an integer \( N \) \( (1 \leq N \leq 100) \), which represents the length of the string Heyho found.
  • The second line contains the string \( S \), which is guaranteed to be a string of \( N \) lowercase English letters.

Output Format

If it is impossible for Heyho to obtain a square, output \(-1\) on a single line. If it is possible to obtain a square, output the minimum number of operations required on a single line. In either case, include a newline at the end of the output.

Sample Input and Output

Sample Input #1

8
abacbabc

Sample Output #1

3

Sample Input #2

8
abababab

Sample Output #2

0

Sample Input #3

5
abcde

Sample Output #3

-1

Sample Input #4

26
codefestivaltwozeroonefive

Sample Output #4

11

Notes/Hints

Sample Explanation 1

By performing the following 3 operations, we can obtain the square aabcaabc:
- Replace the 2nd character with a, resulting in aaacbabc.
- Replace the 3rd character with b, resulting in aabcbabc.
- Replace the 5th character with a, resulting in aabcaabc.

Sample Explanation 2

Since abababab is already a square, no operations are needed.

Sample Explanation 3

No matter what operations are performed, it is impossible to obtain a square.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
8 abacbabc
样例输出
3