#pragma GCC optimize("O3") #include #include #include #include using u32 = uint32_t; // H <= 10^6 static u32 S[1000000]; class FastInput { static constexpr size_t SZ = 1u << 16; char buf[SZ + 32]; char* p = buf; char* e = buf; __attribute__((noinline)) void refill() { const size_t rem = static_cast(e - p); if (rem) { std::memmove(buf, p, rem); } p = buf; e = buf + rem; // 次の整数を安全に読める程度までは確保する do { const ssize_t n = ::read(0, e, SZ - static_cast(e - buf)); if (n <= 0) break; e += n; } while (e - p < 16); // look-ahead 用 std::memset(e, 0, 16); } public: __attribute__((always_inline)) inline u32 next() { if (__builtin_expect(e - p < 16, 0)) { refill(); } // 入力は非負整数のみ while (*p <= ' ') ++p; u32 x = static_cast(*p++ - '0'); if (*p <= ' ') return x; x = x * 10 + static_cast(*p++ - '0'); if (*p <= ' ') return x; x = x * 10 + static_cast(*p++ - '0'); if (*p <= ' ') return x; x = x * 10 + static_cast(*p++ - '0'); if (*p <= ' ') return x; x = x * 10 + static_cast(*p++ - '0'); if (*p <= ' ') return x; x = x * 10 + static_cast(*p++ - '0'); if (*p <= ' ') return x; x = x * 10 + static_cast(*p++ - '0'); if (*p <= ' ') return x; x = x * 10 + static_cast(*p++ - '0'); if (*p <= ' ') return x; // A_{i,j} < 10^9 なので A はここで必ず終了する。 // H, W もこれより小さいので入力中の全整数に使える。 x = x * 10 + static_cast(*p++ - '0'); return x; } }; // 00, 01, ..., 99 static constexpr char DIG2[] = "00010203040506070809" "10111213141516171819" "20212223242526272829" "30313233343536373839" "40414243444546474849" "50515253545556575859" "60616263646566676869" "70717273747576777879" "80818283848586878889" "90919293949596979899"; __attribute__((always_inline)) static inline char* put2(char* p, u32 x) { const char* q = DIG2 + x * 2; *p++ = q[0]; *p++ = q[1]; return p; } __attribute__((always_inline)) static inline char* put4(char* p, u32 x) { const u32 hi = x / 100; p = put2(p, hi); return put2(p, x - hi * 100); } __attribute__((always_inline)) static inline char* put1to4(char* p, u32 x) { if (x < 10) { *p++ = static_cast('0' + x); return p; } if (x < 100) { return put2(p, x); } if (x < 1000) { const u32 hi = x / 100; *p++ = static_cast('0' + hi); return put2(p, x - hi * 100); } return put4(p, x); } __attribute__((always_inline)) static inline char* putU32(char* p, u32 x) { if (x < 10000) { return put1to4(p, x); } if (x < 100000000u) { const u32 hi = x / 10000u; const u32 lo = x - hi * 10000u; p = put1to4(p, hi); return put4(p, lo); } // uint32_t <= 4294967295 なので hi は 1..42 const u32 hi = x / 100000000u; const u32 lo = x - hi * 100000000u; p = put1to4(p, hi); const u32 mid = lo / 10000u; p = put4(p, mid); return put4(p, lo - mid * 10000u); } class FastOutput { static constexpr size_t SZ = 1u << 16; char buf[SZ + 16]; size_t pos = 0; public: ~FastOutput() { flush(); } __attribute__((noinline)) void flush() { size_t done = 0; while (done < pos) { const ssize_t n = ::write(1, buf + done, pos - done); if (n <= 0) break; done += static_cast(n); } pos = 0; } __attribute__((always_inline)) inline void writeU32(u32 x) { if (__builtin_expect(pos + 11 > SZ, 0)) { flush(); } char* q = putU32(buf + pos, x); *q++ = '\n'; pos = static_cast(q - buf); } }; int main() { FastInput in; FastOutput out; const u32 H = in.next(); const u32 W = in.next(); u32 T = 0; for (u32 i = 0; i < H; ++i) { u32 s = 0; for (u32 j = 0; j < W; ++j) { s += in.next(); } S[i] = s; T += s; } for (u32 i = 0; i < H; ++i) { out.writeU32(S[i] + T); } }