#include // #include using namespace std; using namespace numbers; int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int nr, nc; cin >> nr >> nc; vector> a(nr, vector(nc)); for(auto &x: a | ranges::views::join){ cin >> x; } static const vector> dr8{{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; int res = 0; for(auto [dx0, dy0]: dr8){ for(auto x0 = 0; x0 < nr; ++ x0){ for(auto y0 = 0; y0 < nc; ++ y0){ if(x0 == 0 || x0 == nr - 1 || y0 == 0 || y0 == nc - 1){ vector> vis(nr, vector(nc)); int temp = 0; for(auto x = x0, y = y0; 0 <= min(x, y) && x < nr && y < nc; x += dx0, y += dy0){ vis[x][y] = true; temp += a[x][y]; } for(auto [dx1, dy1]: dr8){ for(auto x1 = 0; x1 < nr; ++ x1){ for(auto y1 = 0; y1 < nc; ++ y1){ if(x1 == 0 || x1 == nr - 1 || y1 == 0 || y1 == nc - 1){ int cur = temp; for(auto x = x1, y = y1; 0 <= min(x, y) && x < nr && y < nc; x += dx1, y += dy1){ if(!vis[x][y]){ cur += a[x][y]; } } if(res < cur){ res = cur; } } } } } } } } } cout << res << "\n"; return 0; } /* */ //////////////////////////////////////////////////////////////////////////////////////// // // // Coded by Aeren // // // ////////////////////////////////////////////////////////////////////////////////////////