import java.io.*; public class Main { private static final byte[] INPUT = new byte[40_000_032]; private static int position; private static int nextInt() { int c; do c = INPUT[position++] & 255; while (c <= 32); int value = 0; while (c >= '0' && c <= '9') { value = value * 10 + c - '0'; c = INPUT[position++] & 255; } return value; } private static int decimalLength(long value) { if (value < 10L) return 1; if (value < 100L) return 2; if (value < 1_000L) return 3; if (value < 10_000L) return 4; if (value < 100_000L) return 5; if (value < 1_000_000L) return 6; if (value < 10_000_000L) return 7; if (value < 100_000_000L) return 8; if (value < 1_000_000_000L) return 9; return 10; } private static int appendUnsigned(byte[] output, int start, int signedValue) { long value = Integer.toUnsignedLong(signedValue); int end = start + decimalLength(value); int next = end + 1; output[end] = '\n'; int p = end; while (value >= 100) { int pair = (int)(value % 100); value /= 100; output[--p] = (byte)('0' + pair % 10); output[--p] = (byte)('0' + pair / 10); } if (value < 10) { output[--p] = (byte)('0' + value); } else { output[--p] = (byte)('0' + value % 10); output[--p] = (byte)('0' + value / 10); } return next; } public static void main(String[] args) throws Exception { int inputLength = 0; while (inputLength < INPUT.length) { int count = System.in.read(INPUT, inputLength, INPUT.length - inputLength); if (count < 0) break; inputLength += count; } int h = nextInt(); int w = nextInt(); int[] rowSum = new int[h]; int total = 0; for (int i = 0; i < h; ++i) { int sum = 0; for (int j = 0; j < w; ++j) sum += nextInt(); rowSum[i] = sum; total += sum; } byte[] output = new byte[h * 11]; int outputPosition = 0; for (int sum : rowSum) { outputPosition = appendUnsigned(output, outputPosition, sum + total); } System.out.write(output, 0, outputPosition); } }