E - アナグラム 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 7

注意

この問題に対する言及は、2020/11/8 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

長さ N の文字列 S が与えられます。
文字列 T であって、次の条件をすべて満たすものが存在するか判定し、存在するなら一つ求めてください。

  • TS の文字を並び変えて作ることができる
  • TS は異なる
  • T を逆から読んだものと S は異なる

制約

  • 1 \le N \le 5
  • N は整数
  • S は英小文字からなる長さ N の文字列

入力

入力は以下の形式で標準入力から与えられる。

N
S

出力

条件を満たす T が存在する場合、そのような T のうち一つを、存在しない場合 None を出力せよ。


入力例 1

3
cba

出力例 1

acb

acbcba を並び変えて得られ、そのままでも逆から読んでも cba と異なるので条件を満たします。
他にも bac など条件を満たすものはありますが、xyzcbaabc などは条件を満たしません。


入力例 2

2
aa

出力例 2

None

条件を満たすようなものがありません。

Score : 7 points

Warning

Do not make any mention of this problem until November 8, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Given is a string S. Determine whether there is a string T that satisfies all of the following conditions, and find one such string if it exists.

  • T is a permutation of characters of S.
  • T is different from S.
  • The reversal of T is different from S.

Constraints

  • 1 \le N \le 5
  • N is an integer.
  • S is a string of length N consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

If there is a string T that satisfies the conditions, print one such string; otherwise, print None.


Sample Input 1

3
cba

Sample Output 1

acb

acb is a permutation of cba, and both itself and its reversal differ from cba, so it satisfies the conditions. Other strings such as bac also satisfy the conditions, but strings such as xyz, cba, and abc do not.


Sample Input 2

2
aa

Sample Output 2

None

No string satisfies the conditions.