using System; using System.IO; class Solution { static byte[] input = new byte[40000032]; static int inputLength; static int position; static uint NextUInt() { int c; do c = input[position++]; while (c <= 32); uint value = 0; while (c >= '0' && c <= '9') { value = unchecked(value * 10u + (uint)(c - '0')); c = input[position++]; } return value; } static void Main() { using (Stream stream = Console.OpenStandardInput()) { while (inputLength < input.Length) { int count = stream.Read(input, inputLength, input.Length - inputLength); if (count == 0) break; inputLength += count; } } int h = (int)NextUInt(); int w = (int)NextUInt(); uint[] rowSum = new uint[h]; uint total = 0; for (int i = 0; i < h; ++i) { uint sum = 0; for (int j = 0; j < w; ++j) sum = unchecked(sum + NextUInt()); rowSum[i] = sum; total = unchecked(total + sum); } byte[] output = new byte[h * 11]; byte[] reversed = new byte[10]; int outputPosition = 0; foreach (uint sum in rowSum) { uint value = unchecked(sum + total); int length = 0; do { reversed[length++] = (byte)('0' + value % 10); value /= 10; } while (value != 0); while (length != 0) output[outputPosition++] = reversed[--length]; output[outputPosition++] = (byte)'\n'; } using (Stream stream = Console.OpenStandardOutput()) { stream.Write(output, 0, outputPosition); } } }