#include using namespace std; using ll = long long; using P = pair; using T = tuple; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> h >> w; vector ans(h+w-1,1001001001); vector s(h); rep(i,h) cin >> s[i]; priority_queue pq; pq.push({0,s[0][0],0}); vector> seen(h,vector(w,false)); seen[0][0] = true; while(pq.size()){ int p,x,q; tie(p,x,q) = pq.top(); pq.pop(); if(ans[p]