P27350 [AtCoder] Anagram
提高+
题目描述

Problem Description

You are given a string $ S $ of length $ N $.
Determine if there exists a string $ T $ that satisfies all of the following conditions, and if so, find one such $ T $.

  • $ T $ can be created by rearranging the characters of $ S $
  • $ T $ is different from $ S $
  • Reading $ T $ backwards is different from $ S $

Input Format

The input is given from the standard input in the following format:

$ N $ $ S $

Output Format

If a $ T $ that satisfies the conditions exists, output one such $ T $. If no such $ T $ exists, output None.

Sample Input and Output

Sample Input #1

3
cba

Sample Output #1

acb

Sample Input #2

2
aa

Sample Output #2

None

Notes/Hints

Constraints

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

Sample Explanation 1

acb can be obtained by rearranging cba, and it is different from cba both as it is and when read backwards, so it satisfies the conditions. There are other strings that satisfy the conditions, such as bac, but not xyz, cba, or abc.

Sample Explanation 2

No such string exists that satisfies the conditions.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 cba
样例输出
acb