#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int h, w; cin >> h >> w; vector s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } const int INF = 1e9; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; auto is_in = [&](int x, int y) { return 0 <= x && x < h && 0 <= y && y < w; }; vector>> dist(h, vector>(w, {INF, INF})); dist[0][0] = {0, 0}; using P = tuple; priority_queue, greater

> pq; pq.push({0, 0, 0, 0}); while (!pq.empty()) { auto [dh, dv, x, y] = pq.top(); pq.pop(); if (dist[x][y] < make_pair(dh, dv)) { continue; } for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (!is_in(nx, ny) || s[nx][ny] == '#') { continue; } int ndh = dh + (i >= 2); int ndv = dv + (i < 2); if (dist[nx][ny] > make_pair(ndh, ndv)) { dist[nx][ny] = {ndh, ndv}; pq.push({ndh, ndv, nx, ny}); } } } if (dist[h - 1][w - 1] == make_pair(INF, INF)) { cout << "No" << endl; } else { cout << "Yes" << endl; cout << dist[h - 1][w - 1].first << " " << dist[h - 1][w - 1].second << endl; } }