#pragma GCC optimize("O3") #include #include #include using u32 = uint32_t; using u64 = uint64_t; static u32 S[1000000]; // 8桁のASCII数字を一気に整数化 // 例: "12345678" -> 12345678 static inline __attribute__((always_inline)) u32 parse8(u64 x) { x = ((x & 0x0F0F0F0F0F0F0F0FULL) * 2561ULL) >> 8; x = ((x & 0x00FF00FF00FF00FFULL) * 6553601ULL) >> 16; return static_cast( ((x & 0x0000FFFF0000FFFFULL) * 42949672960001ULL) >> 32 ); } // 8 byte 中に '0' 未満の文字、つまり空白・改行があるか static inline __attribute__((always_inline)) bool hasSeparator8(u64 x) { constexpr u64 ONE = 0x0101010101010101ULL; constexpr u64 HIGH = 0x8080808080808080ULL; return ((x - ONE * '0') & ~x & HIGH) != 0; } class FastInput { static constexpr size_t BUF_SIZE = 1 << 20; char buf[BUF_SIZE + 32]; char* p = buf; char* e = buf; __attribute__((noinline)) void refill() { const size_t remain = static_cast(e - p); if (remain) { std::memmove(buf, p, remain); } p = buf; e = buf + remain; e += std::fread( e, 1, BUF_SIZE - remain, stdin ); // 16 byte look-ahead を安全にする std::memset(e, 0, 16); } public: inline __attribute__((always_inline)) u32 next() { if (__builtin_expect(e - p < 16, 0)) { refill(); } // 通常は前の next() が区切り文字まで消費しているので通らない while (__builtin_expect(*p < '0', 0)) { ++p; } u64 x; std::memcpy(&x, p, sizeof(x)); // 最初の8文字がすべて数字 if (__builtin_expect(!hasSeparator8(x), 1)) { // 9桁 // A < 10^9 なので10桁は絶対に存在しない if (p[8] >= '0') { u64 y; std::memcpy(&y, p + 1, sizeof(y)); const u32 res = static_cast(p[0] - '0') * 100000000u + parse8(y); // 9桁 + 区切り文字 p += 10; return res; } // 8桁 const u32 res = parse8(x); // 8桁 + 区切り文字 p += 9; return res; } // 1~7桁 u32 res = static_cast(*p++ - '0'); while (*p >= '0') { res = res * 10 + static_cast(*p++ - '0'); } // 空白または改行を消費 ++p; return res; } }; static constexpr char DIG2[] = "00010203040506070809" "10111213141516171819" "20212223242526272829" "30313233343536373839" "40414243444546474849" "50515253545556575859" "60616263646566676869" "70717273747576777879" "80818283848586878889" "90919293949596979899"; static inline __attribute__((always_inline)) char* put2(char* p, u32 x) { const char* q = DIG2 + x * 2; *p++ = q[0]; *p++ = q[1]; return p; } static inline __attribute__((always_inline)) char* put4(char* p, u32 x) { const u32 hi = x / 100; p = put2(p, hi); return put2(p, x - hi * 100); } static inline __attribute__((always_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); } static inline __attribute__((always_inline)) char* putU32(char* p, u32 x) { if (x < 10000u) { 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 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 BUF_SIZE = 1 << 20; char buf[BUF_SIZE + 16]; char* p = buf; public: ~FastOutput() { flush(); } __attribute__((noinline)) void flush() { std::fwrite( buf, 1, static_cast(p - buf), stdout ); p = buf; } inline __attribute__((always_inline)) void write(u32 x) { if (__builtin_expect(p > buf + BUF_SIZE - 16, 0)) { flush(); } p = putU32(p, x); *p++ = '\n'; } }; 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.write(S[i] + T); } return 0; }