Codeforces Round 124 (Div. 1)
D
The Next Good String
Codeforces
2800
原题
← CE →
翻译中…

In problems on strings one often has to find a string with some particular properties. The problem authors were reluctant to waste time on thinking of a name for some string so they called it good. A string is good if it doesn't have palindrome substrings longer than or equal to $*d*$.

翻译中…

You are given string $*s*$, consisting only of lowercase English letters. Find a good string $*t*$ with length $|*s*|$, consisting of lowercase English letters, which is lexicographically larger than $*s*$. Of all such strings string $*t*$ must be lexicographically minimum.

翻译中…

We will call a non-empty string $*s*[*a* ... *b*] = *s*_{*a*}*s*_{*a* + 1}... *s*_{*b*}$ $(1 ≤ *a* ≤ *b* ≤ |*s*|)$ a substring of string $*s* = *s*_{1}*s*_{2}... *s*_{|*s*|}$.

翻译中…

A non-empty string $*s* = *s*_{1}*s*_{2}... *s*_{*n*}$ is called a palindrome if for all $*i*$ from $1$ to $*n*$ the following fulfills: $*s*_{*i*} = *s*_{*n* - *i* + 1}$. In other words, palindrome read the same in both directions.

翻译中…

String $*x* = *x*_{1}*x*_{2}... *x*_{|*x*|}$ is lexicographically larger than string $*y* = *y*_{1}*y*_{2}... *y*_{|*y*|}$, if either $|*x*| > |*y*|$ and $*x*_{1} = *y*_{1}, *x*_{2} = *y*_{2}, ... , *x*_{|*y*|} = *y*_{|*y*|}$, or there exists such number $*r*$ $(*r* < |*x*|, *r* < |*y*|)$, that $*x*_{1} = *y*_{1}, *x*_{2} = *y*_{2}, ... , *x*_{*r*} = *y*_{*r*}$ and $*x*_{*r* + 1} > *y*_{*r* + 1}$. Characters in such strings are compared like their ASCII codes.

翻译中…

Input

翻译中…

The first line contains integer $*d*$ ($1 ≤ *d* ≤ |*s*|$).

翻译中…

The second line contains a non-empty string $*s*$, its length is no more than $4·10^{5}$ characters. The string consists of lowercase English letters.

翻译中…

Output

翻译中…

Print the good string that lexicographically follows $*s*$, has the same length and consists of only lowercase English letters. If such string does not exist, print "Impossible" (without the quotes).

翻译中…

样例

Input #1
3
aaaaaaa
Output #1
aabbcaa
InputCopy OutputCopy
Input #2
3
zzyzzzz
Output #2
Impossible
InputCopy OutputCopy
Input #3
4
abbabbbabbb
Output #3
abbbcaaabab
InputCopy OutputCopy
题目信息
题号
196D
时间限制
2 s
内存限制
256 MB
标签
数据结构
贪心
哈希
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。