#P5799. Restore the Circular String

    ID: 19027 Type: Default 1000ms 256MiB

Restore the Circular String

Restore the Circular String

A master wizard gave Alice and Bob a circular string of length \(2n\). In the original circular string, if we consider every contiguous substring of length \(n\) (where the character following \(s_i\) is \(s_{i+1}\) and \(s_1\) follows \(s_{2n}\)), no such substring appears more than once. It can be shown that this condition is equivalent to:

[ \forall, 1 \le i \le n,\quad s_i \neq s_{i+n} ]

Unfortunately, a demon scrambled the order of the characters in the string. Your task is to help Alice and Bob recover any ordering of the characters (a permutation of the scrambled string) that restores these properties.

Note: It is guaranteed that the input is a permutation of a valid original string so that a solution exists.

inputFormat

The input consists of a single line containing a string of length \(2n\) (\(n \ge 1\)).

outputFormat

Output a restored string meeting the condition that when considered as a circular string, every contiguous substring of length \(n\) is distinct. (Equivalently, for every \(1 \le i \le n\), the character at position \(i\) is not equal to the character at position \(i+n\)).

sample

ab
ab