#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin >> H >> W; vector> A(H,vector(W)); for(auto &h : A) for(auto &w : h) cin >> w; if(H == 1 && W == 1){cout << A.at(0).at(0) << endl; return 0;} vector>,int>> beam; for(int i=0; i> visit; while(true){ p += A.at(x).at(y); visit.insert({x,y}); x += a; y += b; if(x < 0 || x >= H || y < 0 || y >= W) break; } if(!one && visit.size() == 1) continue; if(one && visit.size() == 1) one = false; beam.push_back({visit,p}); } } } int bs = beam.size(),answer = 0; for(int i=0; i