#include #include using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) using mint = atcoder::modint1000000007; int main(){ int h,w; cin>>h>>w; vector> a(h,vector(w)); rep(i,h) rep(j,w) cin>>a.at(i).at(j); vector dx={-1,-1,0,1,1,1}; vector dy={0,1,1,1,0,-1}; auto isok=[&](int x,int y){ return 0<=x&&x> &b){ ll res=0; while(isok(x,y)){ res+=b.at(x).at(y); x+=dx.at(i); y+=dy.at(i); } return res; }; auto del=[&](int x,int y,int i){ auto ca=a; while(isok(x,y)){ ca.at(x).at(y)=0; x+=dx.at(i); y+=dy.at(i); } return ca; }; ll tmp=0; vector> xyi; rep(ch1,h+w-1){ int x1=0,y1=0; if(ch1>=h) y1=ch1-h+1; else x1=ch1; rep(i1,6){ ll tp=select(x1,y1,i1,a); if(tmp=h) y=ch1-h+1; else x=ch1; rep(i,6){ ans=max(ans,select(x,y,i,ca)); } } } cout<