atcoder#AGC023B. [AGC023B] Find Symmetries
[AGC023B] Find Symmetries
Score : points
Problem Statement
Snuke has two boards, each divided into a grid with rows and columns. For both of these boards, the square at the -th row from the top and the -th column from the left is called Square .
There is a lowercase English letter written in each square on the first board. The letter written in Square is . On the second board, nothing is written yet.
Snuke will write letters on the second board, as follows:
- First, choose two integers and ( ).
- Write one letter in each square on the second board. Specifically, write the letter written in Square on the first board into Square on the second board. Here, the -th row is also represented as the -th row, and the -th column is also represented as the -th column.
After this operation, the second board is called a good board when, for every and ( ), the letter in Square and the letter in Square are equal.
Find the number of the ways to choose integers and ( ) such that the second board is a good board.
Constraints
- ( ) is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
Output
Print the number of the ways to choose integers and ( ) such that the second board is a good board.
2
ab
ca
2
For each pair of and , the second board will look as shown below:
The second board is a good board when or , thus the answer is .
4
aaaa
aaaa
aaaa
aaaa
16
Every possible choice of and makes the second board good.
5
abcde
fghij
klmno
pqrst
uvwxy
0
No possible choice of and makes the second board good.