#P6090. [CEOI 2019] 立方填词
[CEOI 2019] 立方填词
Description
Cube word filling is a special kind of word-filling game. Before filling, you need to choose the edge length of a cube, and then you can build a cube consisting of unit cubes. This large cube has edges. Then, you remove all unit cubes that do not touch any edge of the large cube. The figure below shows the final cube when .

Finally, you need to fill a letter into each remaining unit cube. After filling, the word along each edge of the large cube should be meaningful. Each edge can be read in both directions; it is enough if it forms a meaningful word in at least one direction.
The figure below shows a cube when . Some unit cubes have already been filled with letters. You can already read three words along three edges of the large cube: SUBMIT, ACCEPT, and TURING.

Given a list of meaningful words, each word may appear on any edge of a valid cube. Find how many different cubes can be constructed, modulo .
Even if one cube can be transformed into another by rotations and reflections, they are still considered different.
Input Format
The first line contains an integer , the number of words.
The next lines each contain one word, indicating a word that may appear on an edge of the large cube. The word length is at least and at most .
It is guaranteed that all words are distinct.
Output Format
Output one integer, the number of different cubes that can be constructed modulo .
1
radar
1
1
robot
2
2
FLOW
WOLF
2
2
baobab
bob
4097
3
TURING
SUBMIT
ACCEPT
162
3
MAN1LA
MAN6OS
AN4NAS
114
Hint
Sample Explanation #1
In the first sample, the only possibility is that the word on every edge of the cube is radar.
Sample Explanation #2
In the second sample, there are two cubes, and one can be obtained from the other by rotation. The words on all edges are robot. The difference between the two cubes is whether the letter in the bottom-left corner is r or t.
Sample Explanation #3
The third sample is similar to the second one. Note that the reading direction does not affect the answer.
Sample Explanation #4
In the fourth sample, if you fill bob on every edge of the cube, there is one cube. There are also cubes where every edge is filled with baobab (for each of the edges, there are two possible reading directions).
Constraints
For all testdata, .
The detailed subtask constraints and scores are shown in the table below:
| Subtask ID | Constraint | Score |
|---|---|---|
| 1 | Words contain only lowercase a to f |
|
| 2 | Words contain only lowercase a to p |
|
| 3 | Words contain lowercase a to p and uppercase A to P |
|
| 4 | Words contain lowercase a to z, uppercase A to Z, and digits 0 to 9 |
Translated by ChatGPT 5
京公网安备 11011102002149号