Problem:
Score : 200 points

Problem Statement

Snuke lives on an infinite two-dimensional plane. He is going on an N-day trip.
At the beginning of Day 1, he is at home. His plan is described in a string S of length N.
On Day i(1 ≦ i ≦ N), he will travel a positive distance in the following direction:

North if the i-th letter of S is N

West if the i-th letter of S is W

South if the i-th letter of S is S

East if the i-th letter of S is E

He has not decided each day's travel distance. Determine whether it is possible to set each day's travel distance so that he will be back at home at the end of Day N.

Constraints

1 ≦ | S | ≦ 1000

S consists of the letters N, W, S, E.

Input

The input is given from Standard Input in the following format:

S

Output

Print Yes if it is possible to set each day's travel distance so that he will be back at home at the end of Day N. Otherwise, print No.

Sample Input 1

SENW

Sample Output 1

Yes

If Snuke travels a distance of 1 on each day, he will be back at home at the end of day 4.

Sample Input 2

NSNNSNSN

Sample Output 2

Yes

Sample Input 3

NNEW

Sample Output 3

No

Sample Input 4

W

Sample Output 4

No

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 3 * 1000 + 47;
const int MAX1 = 1000 * 100 + 47;

__int128 ccc;
LL A[MAX1];
int P[MAX];
LL L[MAX];
int sz;

map<LL, int> mapp;

void norm(LL& a)
{
	FOR(i, 0, sz)
	{
		LL l = L[i] * L[i] * L[i];
		while (a % l == 0)
		{
			a /= l;
		}
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	FOR(i, 2, MAX)
	{
		if (!P[i])
		{
			L[sz++] = i;
			int j = i + i;
			while (j < MAX)
			{
				P[j] = 1;
				j += i;
			}
		}
	}

	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		cin >> A[i];
		norm(A[i]);
		mapp[A[i]]++;
	}

	int ans = 0;
	FOR(i, 0, n)
	{
		LL a = A[i];
		LL b = a * a;
		norm(b);

		//cout << a << ": " << b << endl;
		if (mapp[a] == 0 && mapp[b] == 0) continue;

		if (a == 1)
		{
			ans++;
			mapp[a] = 0;
			continue;
		}


		int cnt1 = mapp[a];
		int cnt2 = mapp[b];
		if (cnt1 >= cnt2)
		{
			ans += cnt1;
			mapp[a] = mapp[b] = 0;
			continue;
		}
	}

	cout << ans << endl;
}