problems / 256

Suki Counts the Buried Bones

easy matrix arrays 1000 ms · 256 MB

Suki Counts the Buried Bones

Suki, a black curly-coated dog with a grey beard and white paws, has buried a lot of bones in the garden. To keep track of them she drew a map: the garden is split into R rows and C columns of square patches, and each patch on the map shows how many bones she has buried there. Before winter she wants to know which row of patches is the richest, which column is the richest, and how many bones she has buried in total.

The total of a row is the sum of the numbers in its C patches; the total of a column is the sum of the numbers in its R patches. Find the row with the largest total and the column with the largest total. If several rows share the largest total, choose the one with the smallest index; do the same for columns.

Input

The first line contains two integers R and C (1 ≤ R, C ≤ 1000).

Each of the next R lines contains C integers a_ij (0 ≤ a_ij ≤ 10^9): the number of bones in row i, column j. Rows are numbered from 1 top to bottom and columns from 1 left to right.

Output

Print three integers separated by spaces: the index of the row with the largest total, the index of the column with the largest total (the smallest index on ties, in both cases), and the total number of bones in the whole garden.

Notes

In the first example the row totals are 5, 9 and 6, so row 2 wins, and the column totals are 8, 4 and 8: columns 1 and 3 tie, so the answer is column 1. The garden holds 20 bones.

In the second example every patch holds 10^9 bones. All rows tie, as do all columns, so the answer is row 1 and column 1. A single row's total, and the grand total, can be far larger than 2^31: use 64-bit integers.

Example 1

Input

3 3
2 0 3
4 2 3
2 2 2

Output

2 1 20

Example 2

Input

2 3
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000

Output

1 1 6000000000

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

Hint 1

Each cell belongs to exactly one row and one column. While you read a cell, which running totals should it be added to?

Hint 2

Keep one sum per row and one per column, updated as you read. Afterwards, pick the best row with a strictly-greater comparison so the first of several equal totals wins. How big can a row total get?

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

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