Under construction

Still being built. Things may change

Comets

Time limit1sMemory limit1024 MB

Summary
Find the top-left cell for a KxK station in an NxM grid of moving comets so the first hit happens as late as possible, breaking ties by row, then column.
Level

Medium7 of 10

Topics
Sliding window, Matrix, Dynamic programming
Solved
No attempts yet

Problem

NASA wants to place a new station in space. For this problem, space is shown as a matrix of N×MN \times M cells arranged in NN rows and MM columns. The station is square, with KK rows and KK columns. Its sides must be parallel to the sides of the space, and it must lie entirely inside the space.

Comets are in space. Each comet moves in one of four directions: up, down, left, or right. Each cell can initially hold at most one comet. Each comet moves one cell per second. Comets never change direction.

If a comet is on a cell occupied by the station at some moment, we say the comet hit the station. If a comet leaves the matrix, it disappears. At any moment after the start, several comets may share a cell, and they pass through each other.

The station cannot be placed so that a cell holds both the station and a comet. It is guaranteed that the station can be placed at least at one position. The position of the station is defined by the cell occupied by its upper left corner.

NASA wants the best position. They want the first comet hit to happen as late as possible (or never). If several positions are equally good, choose the one with the smallest row index, and among those, the smallest column index.

Input

The first line contains two natural numbers NN and MM (1≤N,M≤10001 \le N, M \le 1000).

The second line contains a natural number KK (1≤K≤min⁡(N,M)1 \le K \le \min(N, M)).

Each of the next NN lines contains MM characters describing the initial state. The character '.' means the cell has no comet. The characters 'U', 'D', 'L', and 'R' mean a comet is on that cell moving up, down, left, or right.

Output

Print one line with two natural numbers separated by a space: the row and column of the cell where the upper left corner of the station should be placed.

Hints

In the first sample, the station placed at row 3, column 2 is never hit by a comet.

In the third sample, placing the station at row 2, column 3 or at row 3, column 2 makes the first comet hit after three seconds. Every other valid cell gives an earlier hit. Since we want the topmost and then leftmost cell, we choose row 2, column 3.

Examples3

  1. Example 1

    Input
    4 4
    2
    R...
    .L..
    ...R
    L...
    
    Expected output
    3 2
    
  2. Example 2

    Input
    5 3
    1
    .DL
    R..
    ..D
    ...
    U..
    
    Expected output
    5 2
    
  3. Example 3

    Input
    9 7
    4
    R.....D
    .L.....
    .......
    L......
    .......
    .......
    .......
    .....U.
    .U.....
    
    Expected output
    2 3