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.