#C2811. Deranged Text Transformation
Deranged Text Transformation
Deranged Text Transformation
Given an integer n and a string text of length n, your task is to produce a new string by rearranging the characters of text so that no character remains in its original position. In other words, if you denote the output string as s, then for every index i (0-indexed), it must hold that \( s_i \neq text_i \).
If \( n = 1 \), output the original string. You are guaranteed that for \( n > 1 \) the input is chosen such that a valid derangement exists.
Note: There may be more than one valid derangement. You only need to output one of them. A simple strategy is to try cyclic shifts until you find one that meets the requirements.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer \( n \) denoting the length of the string.
- The second line contains the string \( text \) of length \( n \).
outputFormat
Output a single line containing the transformed string which is a derangement of the original string: for every index \( i \), the \( i\)-th character of the output must differ from the \( i\)-th character of the input.
## sample6
abcdef
bcdefa
</p>