#include using namespace std; #include using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; templateinline bool chmax(T& a,T b){if(a # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif int main() { int h, w; cin >> h >> w; vector> a(h, vector(w)); rep(i,h)rep(j,w) cin >> a[i][j]; ll ans = 0; vector> vs; rep(i,w) vs.emplace_back(0,i); rep(i,w) vs.emplace_back(h-1,i); rep(j,h) vs.emplace_back(j,0); rep(j,h) vs.emplace_back(j,w-1); sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()), vs.end()); for(auto [x_1, y_1] : vs){ for(auto [x_2,y_2] : vs){ for(int dx=-1;dx<=1;dx++){ for(int dy=-1;dy<=1;dy++){ for(int ex=-1;ex<=1;ex++){ for(int ey=-1;ey<=1;ey++){ if(dx==0 && dy==0) continue; if(ex==0 && ey==0) continue; ll sum = 0; set> st; int x1 = x_1; int y1 = y_1; int x2 = x_2; int y2 = y_2; while(true){ if(x1<0 || x1>=h || y1<0 || y1>=w) break; if(!st.count(make_pair(x1,y1))) sum += a[x1][y1]; st.emplace(x1,y1); x1 += dx; y1 += dy; } while(true){ if(x2<0 || x2>=h || y2<0 || y2>=w) break; if(!st.count(make_pair(x2,y2))) sum += a[x2][y2]; st.emplace(x2,y2); x2 += ex; y2 += ey; } ans = max(ans, sum); } } } } } } cout << ans << endl; return 0; }