#include using namespace std; using ll = long long; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 2; void solve(){ int h, w; cin >> h >> w; vector s(h); for(int i=0; i> s[i]; int di[4] = {0, 0, 1, -1}, dj[4] = {1, -1, 0, 0}; vector>> dist(h, vector>(w, {IINF, IINF})); dist[0][0] = {0, 0}; queue> que; que.push({0, 0}); while(!que.empty()){ auto [now_i, now_j] = que.front(); que.pop(); for(int k=0; k<4; k++){ int nxt_i = now_i + di[k]; int nxt_j = now_j + dj[k]; if(nxt_i<0||nxt_j<0||h<=nxt_i||w<=nxt_j) continue; if(s[nxt_i][nxt_j]=='#') continue; pair nxt; nxt.fi = dist[now_i][now_j].fi + abs(di[k]), nxt.se = dist[now_i][now_j].se + abs(dj[k]); if(nxt < dist[nxt_i][nxt_j]){ dist[nxt_i][nxt_j] = nxt; que.push({nxt_i, nxt_j}); } } } if(dist[h-1][w-1]==make_pair(IINF, IINF)) cout << "No\n"; else{ cout << "Yes\n"; cout << dist[h-1][w-1].fi << ' ' << dist[h-1][w-1].se << '\n'; } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }