题目收集
题目列表题单
返回列表

Lyndonization

CodeforcesP0022· 1000ms· 256 MB· ZJU Summer 2026 Contest 2原题链接
构造

创建于 2026/07/16 · 更新于 2026/07/16

题目描述

You are given a string sss of length nnn consisting of lowercase English letters.

You may perform modifications: each modification replaces one position of the string with an arbitrary lowercase English letter. You must, using at most 2⌈n⌉+52\lceil\sqrt{n}\rceil + 52⌈n​⌉+5 modifications, turn sss into a Lyndon word.

A non-empty string www is a Lyndon word if it is strictly smaller (lexicographically) than every one of its proper suffixes. For example, aab\texttt{aab}aab is a Lyndon word: its proper suffixes are ab\texttt{ab}ab and b\texttt{b}b, and aab\texttt{aab}aab is smaller than both. On the other hand, aba\texttt{aba}aba is not: its proper suffix a\texttt{a}a is smaller than aba\texttt{aba}aba.

It can be proven that such a set of modifications always exists. You only have to output any resulting string that satisfies the constraints.

输入格式

The first line contains one integer nnn (1≤n≤106)(1 \le n \le 10^6)(1≤n≤106).

The second line contains a string sss of length nnn consisting of lowercase English letters.

输出格式

Output one line containing a string ttt of length nnn consisting of lowercase English letters, such that:

  • ttt is a Lyndon word;
  • ttt differs from sss in at most 2⌈n⌉+52\lceil\sqrt{n}\rceil + 52⌈n​⌉+5 positions.

If several answers are possible, output any of them.

样例输入 #1

5
liang

样例输出 #1

ailng

样例输入 #2

8
rifleman

样例输出 #2

iillmmnn