题目描述
Problem Description
We take a character matrix of $M$ rows and $N$ columns and replicate it infinitely to create an infinite character matrix. For example, given the following matrix:
$$\begin{aligned} & \verb!honi! \\ & \verb!hsin! \\ \end{aligned}$$
we can replicate it infinitely to produce the matrix:
$$\begin{aligned} & \verb!...honihonihonihoni...! \\ & \verb!...hsinhsinhsinhsin...! \\ & \verb!...honihonihonihoni...! \\ & \verb!...hsinhsinhsinhsin...! \\ \end{aligned}$$
The matrix is considered eight-connected. Eight-connected means that each position in the matrix is adjacent to its up, down, left, right, and four diagonal (upper-left, upper-right, lower-left, lower-right) positions. Therefore, starting from any position in the matrix, one can extend infinitely in any of the eight directions.
If we randomly select a position and a direction, we can form a string of $K$ consecutive characters starting from this position in the chosen direction. The question is, what is the probability that two such operations yield the same string? (Assume that all positions and directions are equally likely when chosen randomly.)
Input Format
The first line contains three integers $M$, $N$, and $K$.
The next $M$ lines each contain a string of lowercase English letters of length $N$, representing the $M \times N$ character matrix. It is guaranteed that the matrix contains at least two different characters.
Output Format
Output a single line with a simplified fraction representing the probability.
Sample Input and Output
Sample Input #1
1 2 2
ab
Sample Output #1
5/16
Sample Input #2
3 3 10
ban
ana
nab
Sample Output #2
2/27
Notes
[Sample Explanation]
In Sample #1, there are 16 possible outcomes for one operation, with the probability of obtaining $\verb!aa!$ being $1/8$, $\verb!ab!$ being $3/8$, $\verb!bb!$ being $1/8$, and $\verb!ba!$ being $3/8$. The probability that two operations yield the same result is $5/16$.
[Data Range and Constraints]
- For 30% of the test cases: $M, N \leq 10$, $K \leq 100$.
- For 50% of the test cases: $M = N$.
- For 100% of the test cases: $1 \leq M, N \leq 500$, $2 \leq K \leq 10^9$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分