P26466 [AtCoder] Level K Palindrome
提高
题目描述

Problem Statement

As a token of his gratitude, Takahashi has decided to give Snuke a level-K palindrome. A level-L palindrome, where L is a non-negative integer, is defined as follows:

  • Let $\mathrm{rev}(s)$ denote the reversal of a string s.
  • A string s is said to be a palindrome when $s = \mathrm{rev}(s)$.
  • The empty string and a string that is not a palindrome are level-0 palindromes.
  • For any non-empty level-(L-1) palindrome t, the concatenation of $t, \mathrm{rev}(t)$ in this order is a level-L palindrome.
  • For any level-(L-1) palindrome t and any character c, the concatenation of $t, c, \mathrm{rev}(t)$ in this order is a level-L palindrome.

Now, Takahashi has a string S.
Determine whether it is possible to make S an exactly level-K palindrome by doing the following action zero or more times: choose a character in S and change it to another lowercase English letter. If it is possible, find the minimum number of changes needed to make S a level-K palindrome.

Input

Input is given from Standard Input in the following format:
K
S

Output

If it is possible to get an exactly level-K palindrome, print the minimum number of changes needed.
If it is impossible, print impossible.

Constraints

  • K is an integer.
  • 0 ≤ K ≤ $5 \times 10^5$
  • S consists of lowercase English letters.
  • 1 ≤ |S| ≤ $5 \times 10^5$

Sample Input 1

4
aabaaaabaa

Sample Output 1

0

We can find the level of aabaaaabaa as follows:

  • the empty string is a level-0 palindrome;
  • a is a concatenation of (empty string), a, (empty string) in this order, so it is a level-1 palindrome;
  • aa is a concatenation of a, a in this order, so it is a level-2 palindrome;
  • aabaa is a concatenation of aa, b, aa in this order, so it is a level-3 palindrome;
  • aabaaaabaa is a concatenation of aabaa, aabaa in this order, so it is a level-4 palindrome.

Thus, aabaaaabaa is already a level-4 palindrome and needs no changes.

Sample Input 2

2
aabaaaabaa

Sample Output 2

4

We can, for example, change aabaaaabaa to acbcaacbca to get a level-2 palindrome.
Note that aabaaaabaa is not a level-2 palindrome.

Sample Input 3

3
aabaaaabaa

Sample Output 3

impossible

Sample Input 4

5
aabaaaabaa

Sample Output 4

impossible

Sample Input 5

2
acaabcbababaaac

Sample Output 5

6

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 aabaaaabaa
样例输出
0