/* Problem URL: https://codeforces.com/problemset/problem/2045/M */ #include #include #include using namespace std; using namespace __gnu_pbds; template > using ordered_set = tree; #define V vector #define rmin(a, b) a = min(a, b) #define rmax(a, b) a = max(a, b) #define rep(i, lim) for (int i = 0; i < (lim); i++) #define nrep(i, s, lim) for (int i = s; i < (lim); i++) #define repv(i, v) for (auto &i : (v)) #define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } #define sortv(v) sort(v.begin(), v.end()) #define all(v) (v).begin(), (v).end() using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using ll = long long; using vl = vector; using vvl = vector; using vvvl = vector; using vvvvl = vector; template auto operator<<(ostream &os, const vector &vec)->ostream& { os << vec[0]; for (size_t i = 1; i < vec.size(); i++) { os << ' ' << vec[i]; } os << '\n'; return os; } template auto operator>>(istream &is, vector &vec)->istream& { for (auto &i : vec) { is >> i; } return is; } template auto operator<<(ostream &os, const vector> &vec)->ostream& { for (auto &i : vec) { os << i[0]; for (size_t j = 1; j < i.size(); j++) { os << ' ' << i[j]; } os << '\n'; } return os; } template auto operator>>(istream &is, vector> &vec)->istream& { for (auto &i : vec) { for (auto &j : i) { is >> j; } } return is; } const int oo = INT32_MAX >> 1; const ll OO = INT64_MAX >> 1; void pre() { } #define TEST 0 void solve() { int r, c; cin >> r >> c; V a(r); cin >> a; auto getpos = [&](int i, int j, int k) { return i * c * 4 + j * 4 + k; }; int tot = 0; vvi graph(r * c * 4); vi ty(r * c * 4, -1); rep(i, r) { rep(j, c) { int n = getpos(i, j, 0); int e = getpos(i, j, 1); int s = getpos(i, j, 2); int w = getpos(i, j, 3); if (i > 0) { int ot = getpos(i - 1, j, 2); graph[n].push_back(ot); } if (j > 0) { int ot = getpos(i, j - 1, 1); graph[w].push_back(ot); } if (i < r - 1) { int ot = getpos(i + 1, j, 0); graph[s].push_back(ot); } if (j < c - 1) { int ot = getpos(i, j + 1, 3); graph[e].push_back(ot); } if (a[i][j] == '.') { graph[e].push_back(w); graph[w].push_back(e); graph[s].push_back(n); graph[n].push_back(s); continue; } tot++; ty[n] = i * c + j; ty[e] = i * c + j; ty[s] = i * c + j; ty[w] = i * c + j; if (a[i][j] == '/') { graph[n].push_back(w); graph[w].push_back(n); graph[s].push_back(e); graph[e].push_back(s); continue; } graph[n].push_back(e); graph[e].push_back(n); graph[w].push_back(s); graph[s].push_back(w); } } V vis(r * c * 4); vi sz(r * c * 4, -1); set s; function dfs = [&](int i) { vis[i] = true; if (ty[i] != -1) { s.insert(ty[i]); } repv(j, graph[i]) { if (vis[j]) { continue; } dfs(j); } }; function dfs2 = [&](int i) { sz[i] = s.size(); repv(j, graph[i]) { if (sz[j] != -1) { continue; } dfs2(j); } }; rep(i, r) { rep(j, c) { rep(k, 4) { int ac = getpos(i, j, k); if (vis[ac]) { continue; } dfs(ac); dfs2(ac); s.clear(); } } } V ans; rep(i, r) { int w = getpos(i, 0, 3); if (sz[w] == tot) { ans.emplace_back("W" + to_string(i + 1)); } int e = getpos(i, c - 1, 1); if (sz[e] == tot) { ans.emplace_back("E" + to_string(i + 1)); } } rep(i, c) { int n = getpos(0, i, 0); if (sz[n] == tot) { ans.emplace_back("N" + to_string(i + 1)); } int s = getpos(r - 1, i, 2); if (sz[s] == tot) { ans.emplace_back("S" + to_string(i + 1)); } } cout << ans.size() << '\n'; repv(i, ans) { cout << i << ' '; } cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); pre(); int t; (TEST && cin >> t) || (t = 1); while (t--) { solve(); } }