#include #include #include #include #include namespace { constexpr std::size_t IO_BUFFER_SIZE = 1u << 20; class FastInput { std::unique_ptr buffer_ = std::make_unique(IO_BUFFER_SIZE); std::size_t position_ = 0; std::size_t length_ = 0; int get_char() { if (position_ == length_) { length_ = std::fread(buffer_.get(), 1, IO_BUFFER_SIZE, stdin); position_ = 0; if (length_ == 0) return -1; } return buffer_[position_++]; } public: bool read_u32(std::uint32_t& value) { int c; do { c = get_char(); } while (c >= 0 && c <= ' '); if (c < '0' || c > '9') return false; std::uint32_t x = 0; do { x = x * 10u + static_cast(c - '0'); c = get_char(); } while (c >= '0' && c <= '9'); value = x; return true; } }; class FastOutput { std::unique_ptr buffer_ = std::make_unique(IO_BUFFER_SIZE); std::size_t position_ = 0; public: ~FastOutput() { flush(); } void flush() { if (position_ != 0) { std::fwrite(buffer_.get(), 1, position_, stdout); position_ = 0; } } void write_u32(std::uint32_t x) { char digits[10]; int length = 0; do { digits[length++] = static_cast('0' + x % 10u); x /= 10u; } while (x != 0); if (position_ + static_cast(length) + 1 > IO_BUFFER_SIZE) { flush(); } while (length != 0) buffer_[position_++] = digits[--length]; buffer_[position_++] = '\n'; } }; } // namespace int main() { FastInput input; std::uint32_t H, W; if (!input.read_u32(H) || !input.read_u32(W)) return 1; std::vector row_sum(H); std::uint32_t total = 0; for (std::uint32_t i = 0; i < H; ++i) { std::uint32_t sum = 0; for (std::uint32_t j = 0; j < W; ++j) { std::uint32_t x; if (!input.read_u32(x)) return 1; sum += x; } row_sum[i] = sum; total += sum; } FastOutput output; for (std::uint32_t sum : row_sum) { output.write_u32(sum + total); } }