#codefestival2016finali. [codefestival_2016_final_i]Reverse Grid
[codefestival_2016_final_i]Reverse Grid
Problem Statement
Snuke has a grid with rows and columns. The square at the -th row and -th column contains a character .
He can perform the following two kinds of operation on the grid:
- Row-reverse: Reverse the order of the squares in a selected row.
- Column-reverse: Reverse the order of the squares in a selected column.
For example, reversing the -nd row followed by reversing the -th column will result as follows:
By performing these operations any number of times in any order, how many placements of characters on the grid can be obtained?
Constraints
- is a lowercase English letter (
a
-z
).
Input
The input is given from Standard Input in the following format:
Output
Print the number of placements of characters on the grid that can be obtained, modulo .
Sample Input 1
2 2
cf
cf
Sample Output 1
6
The following placements of characters can be obtained:
Sample Input 2
1 12
codefestival
Sample Output 2
2