problems / 251

Suki's Sunniest Nap Spot

easy matrix brute-force arrays 1000 ms · 256 MB

Suki's Sunniest Nap Spot

Every afternoon Suki, a curly black dog with a grey beard and white paws, drags her favourite blanket onto the patio for a nap. The patio is a grid of R rows and C columns of square tiles, and the sun has warmed each tile by a different amount: the tile in row i and column j has warmth w_{i,j}. Rows are numbered 1 to R from top to bottom and columns 1 to C from left to right.

The blanket always covers exactly a k × k square of whole tiles, lying fully on the patio. The warmth of a spot is the sum of the warmths of the k·k tiles under the blanket. Suki wants the warmest spot. If several spots are equally warm, she picks the one whose top-left tile is in the smallest row, and among those the one whose top-left tile is in the smallest column.

Input

The first line contains three integers R, C and k (1 ≤ R, C ≤ 50, 1 ≤ k ≤ min(R, C)).

Each of the next R lines contains C integers: the i-th of these lines holds w_{i,1}, w_{i,2}, ..., w_{i,C} (0 ≤ w_{i,j} ≤ 100).

Output

Print three integers: the row and the column of the top-left tile of the chosen spot, and its total warmth.

Notes

In the first example the 2 × 2 square with top-left tile (2, 2) covers warmths 9, 8, 7 and 9, for a total of 33, more than any other spot.

In the second example two spots both have warmth 6: the one starting at (1, 3) and the one starting at (2, 1). The first one is higher up, so Suki chooses it even though the other is further left.

Example 1

Input

3 4 2
1 2 0 3
4 9 8 1
0 7 9 2

Output

2 2 33

Example 2

Input

3 4 2
0 0 1 2
1 1 2 1
2 2 0 0

Output

1 3 6

Hints · reveal one at a time if you're stuck

Hint 1

The patio is at most 50 × 50, so there are at most 2500 places to put the blanket. Can you simply try them all?

Hint 2

For each possible top-left tile, add up the k × k tiles under the blanket and keep the best total. Think about the order you try the corners in, and whether a later spot with the same warmth should replace the one you already have (the second example).

report an issue Prefer your own editor? sooks prep 251 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.