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: Time Limit Exceeded)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#define MN 100000
#define ll long long
using namespace std;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,rk[MN+5],num=0,ans=0;
ll s[MN+5],a[MN+5],r[MN+5];
bool cmp(int x,int y){return r[x]<r[y];}
map<ll,int> mp;
inline void Mul(ll&x,ll y){x=(1e18/x<y)?1e18:x*y;};
int main()
{
    n=read();
    for(int i=1;i<=n;++i)
    {
        a[i]=read();s[i]=r[i]=1;rk[i]=i;
        for(int j=2;j<=2160;++j) if(a[i]%j==0)
        {
            int t=0;
            while(a[i]%j==0) a[i]/=j,t=(t+1)%3;
            for(int k=0;k<t;++k) r[i]*=j;
            for(int k=0;k<(3-t)%3;++k) Mul(s[i],j);
        }
        if(a[i]>1)
        {
            int x=int(sqrt(a[i]));
            while(1LL*(x+1)*(x+1)<=a[i]) ++x;
            if(1LL*x*x==a[i]) r[i]*=a[i],Mul(s[i],x);
            else r[i]*=a[i],Mul(s[i],a[i]),Mul(s[i],a[i]);
        }
    }
    sort(rk+1,rk+n+1,cmp);int ans=n;
    for(int i=1,j;i<=n;i=j+1)
    {
        for(j=i;j<=n&&r[rk[j]]==r[rk[i]];++j);--j;
        if(r[rk[i]]==1) ans-=(j-i);
        else if(s[rk[i]]<=1e10&&mp[s[rk[i]]]) ans-=min(mp[s[rk[i]]],j-i+1);
        else mp[r[rk[i]]]=j-i+1;
    }
    printf("%d\n",ans);
    return 0;
}