#include #include using uint = uint32_t; constexpr size_t IN_SIZE = 1 << 26; // 64 MiB constexpr size_t OUT_SIZE = 12'000'000; // 11 MB あれば足りる static char ibuf[IN_SIZE]; static char obuf[OUT_SIZE]; static uint S[1'000'000]; inline uint read_uint(char *&p) { while (*p < '0') { ++p; } uint x = 0; while (*p >= '0') { x = x * 10 + static_cast(*p - '0'); ++p; } return x; } int main() { // 入力を全部読む size_t len = 0; while (true) { ssize_t n = ::read( STDIN_FILENO, ibuf + len, IN_SIZE - len - 1 ); if (n <= 0) break; len += static_cast(n); } ibuf[len] = '\0'; char *p = ibuf; uint H = read_uint(p); uint W = read_uint(p); uint T = 0; for (uint i = 0; i < H; ++i) { uint s = 0; for (uint j = 0; j < W; ++j) { s += read_uint(p); } S[i] = s; T += s; } // 出力も全部メモリ上で作る size_t pos = 0; for (uint i = 0; i < H; ++i) { uint x = S[i] + T; char tmp[10]; int n = 0; do { uint q = x / 10; tmp[n++] = static_cast('0' + (x - q * 10)); x = q; } while (x); while (n) { obuf[pos++] = tmp[--n]; } obuf[pos++] = '\n'; } // 出力 size_t written = 0; while (written < pos) { ssize_t n = ::write( STDOUT_FILENO, obuf + written, pos - written ); if (n <= 0) break; written += static_cast(n); } return 0; }