#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pi; #define all(x) begin(x),end(x) #define rep(i,a,b) for(int i=a;i pt; #define X real() #define Y imag() const pt dir4[] = {{1,0},{0,1},{-1,0},{0,-1}}; int r,c; bool inside(pt p) { return 0<=p.X and p.X> ans; void output() { cout << "YES\n"; cout << ans.size() << '\n'; for(auto [p,q] : ans) { cout << p.X+1 << ' ' << p.Y+1 << ' ' << q.X+1 << ' ' << q.Y+1 << '\n'; } exit(0); } void simulate(vector& g, pt nw, pt no) { if(nw==no) { return; } ans.push_back({no,nw}); g[nw.X][nw.Y]='*'; g[no.X][no.Y]='.'; } auto findCh(vector> vis,const vector& g) { vector> used(r,vector(c)); pt ans = {-1,-1}; auto dfs = [&](auto&& self, pt at) -> void { used[at.X][at.Y]=1; bool leaf=1; for(auto to : dir4) { to+=at; if(inside(to) and !vis[to.X][to.Y] and !used[to.X][to.Y] and g[to.X][to.Y]=='*') { leaf=0; self(self,to); } } if(leaf and !vis[at.X][at.Y]) { ans = at; } }; for(int i=0;i g, vector eg, pt s ) { vector> vis(r,vector(c)); auto dfs = [&](auto&& self, pt at) -> void { vis[at.X][at.Y]=1; for(auto to : dir4) { to+=at; if(!inside(to) or vis[to.X][to.Y]) { continue; } if(eg[to.X][to.Y]=='*') { if(g[to.X][to.Y]!='*') { auto ch = findCh(vis,g); simulate(g,to,ch); } self(self,to); } } }; dfs(dfs,s); } int main() { cin.tie(NULL); cin.sync_with_stdio(false); cin >> r >> c; vector g(r); for(auto& i : g) cin >> i; vector eg(r); for(auto& i : eg) cin >> i; for(int i=0;i p; vector res; vector> vis(r,vector(c)); auto dfs = [&](auto&& self, pt at) -> void { vis[at.X][at.Y]=1; p.push_back(at); if(eg[at.X][at.Y]=='*') { res=p; } for(auto to : dir4) { to+=at; if(inside(to) and !vis[to.X][to.Y] and g[to.X][to.Y]!='X') { self(self,to); } } p.pop_back(); }; for(int i=0;i=0) { auto v = p[at]; if(g[v.X][v.Y]=='*') { break; } at--; } for(int j=at+1;j> vis(r,vector(c)); vis[from.X][from.Y]=1; auto use = findCh(vis,g); simulate(g,to,use); } solve(g,eg,{i,j}); output(); } } }