#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; int main(){ int h, w; cin >> h >> w; vector> a(h-2, vector(w)); for (int i=0; i> a[i][j]; } } vector>>> ikeru(h-2, vector>>(w, vector>(0))); vector> go = { pair(0,-1), pair(0,1), pair(-1,-1), pair(-1,0), pair(-1,1), pair(1,-1), pair(1,0), pair(1,1) }; for (int i=0; i> d(h-2, vector(w, 1e9)); priority_queue> pq; for (int i=0; i(pq.top()); int i = get<1>(pq.top()); int j = get<2>(pq.top()); pq.pop(); if (t > d[i][j]) continue; for (auto [x, y]: ikeru[i][j]){ if (t + a[x][y] < d[x][y]){ d[x][y] = t + a[x][y]; pq.push(make_tuple(-d[x][y], x, y)); } } } int ans = 1e9; for (int i=0; i