Under construction

Still being built. Things may change

Treasure Hunt

Time limit1sMemory limit256 MB

Summary
Starting at (1, 1), follow the letters of S through adjacent grid tiles, and report the maximum number of full repetitions K and the final tile, or -1 if none exists.
Level

Medium4 of 10

Topics
Graph, DFS, Simulation
Solved
No attempts yet

Problem

Geonggus found a treasure map with NN rows and MM columns. On the back of the map is a string of LL uppercase letters and a note: "If you follow the written string KK times, the treasure is buried on the tile with the last character of the string."

Geonggus lives by the saying "effort never betrays," so he believes the treasure is buried where the value of KK is maximal. Follow the given string and find the place where Geonggus thinks the treasure is buried. Geonggus starts at (1,1)(1, 1), and he can move only to the adjacent tiles above, below, left, or right.

Input

The first line contains NN, MM, and LL, the length of the string SS, separated by spaces. The top-left coordinate is (1,1)(1, 1), and the bottom-right coordinate is (N,M)(N, M).

The second line contains the string SS. SS consists of uppercase letters, and no letter appears more than once in SS.

The next NN lines give the map. Each line consists of uppercase letters. The tile where Geonggus stands has the same letter as the first character of SS.

Output

If Geonggus believes a treasure location exists, print the number of times KK he follows the string, followed by the coordinates of the treasure.

If Geonggus decides there is no treasure, or the treasure can never be found, print only −1-1.

Print the maximum value of KK and the treasure location that corresponds to it. There are never two or more places where KK is maximal.

Constraints

1≤N,M≤1001 \le N, M \le 100

1≤L≤261 \le L \le 26

Examples2

  1. Example 1

    Input
    4 4 3
    ABC
    ABCA
    FGEB
    CBBC
    CABA
    
    Expected output
    2
    3 4
    
  2. Example 2

    Input
    2 2 4
    ABCD
    AB
    DC
    
    Expected output
    -1