#include #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif template bool chmin(T &a, const U &b){ return (a > b ? a = b, true : false); } template bool chmax(T &a, const U &b){ return (a < b ? a = b, true : false); } template void fill_array(T (&a)[N], const U &v){ std::fill((U*)a, (U*)(a + N), v); } template auto make_vector(int n, int m, const T &value){ return std::vector>(n, std::vector(m, value)); } template std::ostream& operator<<(std::ostream &s, const std::vector &a){ for(auto it = a.begin(); it != a.end(); ++it){ if(it != a.begin()) s << " "; s << *it; } return s; } template std::istream& operator>>(std::istream &s, std::vector &a){ for(auto &x : a) s >> x; return s; } namespace solver{ void init(){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(12); std::cerr << std::fixed << std::setprecision(12); std::cin.exceptions(std::ios_base::failbit); } void solve(){ int N, M; std::cin >> N >> M; auto A = make_vector(N, M, 0); std::cin >> A; std::deque B(N); for(int i = 0; i < N; ++i) B[i] = std::accumulate(A[i].begin(), A[i].end(), 0LL); auto dp = make_vector(2, N + 1, -(1LL << 50)); dp[0][0] = 0; for(int i = 0; i < N; ++i){ chmax(dp[0][i + 1], dp[0][i]); chmax(dp[1][i + 1], dp[0][i] + B[i]); chmax(dp[1][i + 1], dp[1][i]); chmax(dp[0][i + 1], dp[1][i] - B[i]); } int64_t ans = std::max(dp[0][N], dp[1][N]); std::cout << ans << "\n"; } } int main(){ solver::init(); while(true){ try{ solver::solve(); }catch(const std::istream::failure &e){ break; } } return 0; }