#include <iostream>
#include <set>
#include <utility>
#include <iomanip>
using namespace std;

bool isPathCrossing(string s) {
    set <pair <int, int>> st;
    int x = 0, y = 0;
    st.insert(make_pair(x,y));
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'N') y++;
        else if(s[i] == 'W') x--;
        else if(s[i] == 'S') y--;
        else x++;
        pair <int, int> pr = make_pair(x, y);
        if(st.find(pr) != st.end()) return true;
        st.insert(pr);
    } 
    return false;
}  

int main() {
	cout << boolalpha;
	cout << isPathCrossing("NES") << endl;
	cout << isPathCrossing("NESWW") << endl;
	return 0;
}