#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; template std::ostream& operator<<(std::ostream& os, const atcoder::static_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} int main(){ int h, w; cin >> h >> w; vector> a(h, vi(w)); rep(y, h) cin >> a[y]; int ans = 0; int n = h + w + (h + w - 1) + (h + w - 1); vi v(2); for(v[0] = 0; v[0] < n; v[0]++){ for(v[1] = 0; v[1] < n; v[1]++){ unordered_set se; rep(i, 2){ if(v[i] < h){ int y = v[i]; rep(x, w) se.insert(y * w + x); }else if(v[i] < h + w){ int x = v[i] - h; rep(y, h) se.insert(y * w + x); }else if(v[i] < h + w + (h + w - 1)){ int s = v[i] - (h + w); rep(y, h){ int x = s - y; if(x >= 0 and x < w) se.insert(y * w + x); } }else{ int d = v[i] - (h + w + (h + w - 1)) - (w - 1); rep(y, h){ int x = y - d; if(x >= 0 and x < w) se.insert(y * w + x); } } } int tmp = 0; for(auto z : se){ int y = z / w; int x = z % w; tmp += a[y][x]; } ans = max(ans, tmp); } } cout << ans; return 0; }