Under construction

Still being built. Things may change

Osmosmjerka

Time limit4sMemory limit256 MB

Summary
Given a letter block tiled infinitely in all directions, pick a random start square and one of 8 directions twice, and report the probability that the two read words of length K match, as a reduced fraction.
Level

Hard8 of 10

Topics
Math, String matching, Hash map, Combinatorics
Solved
No attempts yet

Problem

Repeating a block of letters with MM rows and NN columns in every direction gives an infinite eight-direction word search. For example, this block

honi
hsin

builds the crossword

...honihonihonihoni...
...hsinhsinhsinhsin...
...honihonihonihoni...
...hsinhsinhsinhsin...

which runs on forever left, right, up and down.

Pick one square of the crossword at random, and one of the eight directions at random. Start at that square, step one square at a time in that direction, and read KK letters. That gives a word of length KK. Since the crossword is one block repeated, every square of the crossword matches some square of the block, so picking the starting square is the same as drawing one of the M×NM \times N squares of the block uniformly. The direction is drawn uniformly from the eight as well.

Run this trial twice, independently. Compute the probability that the two words are equal.

Input

The first line contains the integers MM, NN, KK (1≤M,N≤5001 \le M, N \le 500, 2≤K≤1092 \le K \le 10^9).

Each of the next MM lines contains NN lowercase letters of the English alphabet and describes one row of the block. The block contains at least two different letters.

Output

Print the probability as a reduced fraction p/q, with no spaces.

Examples3

  1. Example 1

    Input
    1 2 2
    ab
    
    Expected output
    5/16
    
  2. Example 2

    Input
    2 4 3
    honi
    hsin
    
    Expected output
    19/512
    
  3. Example 3

    Input
    3 3 10
    ban
    ana
    nab
    
    Expected output
    2/27