题目描述
Problem Description
There is a peculiar language called "Two Five Language". Each word in this language consists of each of the 25 letters from A to Y exactly once. However, not every permutation of these letters forms a valid word in the Two Five Language. A word must meet the following condition: when its 25 letters are arranged into a 5x5 matrix, each row and each column must be in ascending order. For example, the word ACEPTBDHQUFJMRWGKNSXILOVY forms the following matrix:
A C E P T
B D H Q U
F J M R W
G K N S X
I L O V Y
Since each row and column is in ascending order, it is a valid word. The word YXWVUTSRQPONMLKJIHGFEDCBA is clearly invalid. Due to the length of the words, it is inconvenient to store them directly. Therefore, each word is assigned a code. The coding method is as follows: from left to right and then from top to bottom, a word can be derived from a matrix, and then the words are sorted in dictionary order. For example, the word ABCDEFGHIJKLMNOPQRSTUVWXY has a code of 1, and the word ABCDEFGHIJKLMNOPQRSUTVWXY has a code of 2.
Now, you need to write a program to convert between words and their codes.
Input Format
The first line is a letter, either N or W. N indicates converting a code to a word, and W indicates converting a word to a code.
If the first line is N, the second line is an integer representing the code of the word. If the first line is W, the second line is a valid word.
Output Format
Each line contains either an integer or a word.
Sample Input and Output
Sample Input #1
N
2
Sample Output #1
ABCDEFGHIJKLMNOPQRSUTVWXY
Sample Input #2
W
ABCDEFGHIJKLMNOPQRSUTVWXY
Sample Output #2
2
Notes
The problem translation is from NOCOW.
USACO Training Section 5.5
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分