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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
    using System.IO;
#endif

public class Program {
    public static void Main() {
        #region SetAutoFlushIsFalse
#if !DEBUG
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
#endif
        #endregion
        var s = Console.ReadLine();

        var nN = s.Where(c => c == 'N').Count();
        var nW = s.Where(c => c == 'W').Count();
        var nS = s.Where(c => c == 'S').Count();
        var nE = s.Where(c => c == 'E').Count();

        Console.WriteLine(msg(nN, nW, nS, nE));
        #region Flush
#if !DEBUG
        Console.Out.Flush();
        sw.Close();
#endif
        #endregion
    }

    private static string msg(int nN, int nW, int nS, int nE) {
        if (nN > 0 && nW > 0 && nS > 0 && nE > 0) {
            return "YES";
        }
        if (nN == 0 && nW == 0 || nS == 0 && nE == 0) {
            return "YES";
        }

        return "NO";
    }
}

static class ReadLib {
    public static long ReadAsLong() {
        return long.Parse(Console.ReadLine());
    }

    public static int ReadAsInt() {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadAsIntArray() {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    public static long[] ReadAsLongArray() {
        return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    public static ulong[] ReadAsULongArray() {
        return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
    }

    public static string[] ReadAsStringArray() {
        return Console.ReadLine().Split(' ');
    }

    public static int[] ReadNTimesAsInt(int n) {
        return Enumerable.Range(1, n).Select(s => int.Parse(Console.ReadLine())).ToArray();
    }

    public static int[][] ReadNTimesAsIntArray(int n) {
        return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray();
    }

}

static class MyMath {
    /// <summary>階乗</summary>
    public static long Factorial(int n) {
        if (n == 0) {
            return 1;
        }

        return Permutation(n, 0);
    }

    public static long Permutation(int n, int k) {
        return Enumerable.Range(0, n - k).Select(i => n - i).Aggregate(1, (b, i) => b * i);
    }

    /// <summary>nCr, 組み合わせ</summary>
    public static long Combination(int n, int r) {
        if (r == 0) {
            return 1;
        }
        // 分子
        var moleculeArr = Enumerable
            .Range(0, Math.Min(n - r, r))
            .Select(i => n - i)
            .ToArray();
        var moleculeArrLength = moleculeArr.Length;
        // 分母
        var denominatorArr = Enumerable
            .Range(1, Math.Max(n - r, r))
            .ToArray();

        for (var m = 0; m < moleculeArrLength; m++) {
            while (true) {
                var mVal = moleculeArr[m];
                var gcds = denominatorArr.Select(b => Gcd(mVal, b));
                var maxGcd = gcds.Max();
                var maxI = gcds.ToList().IndexOf(maxGcd);

                if (maxGcd == 1) {
                    break;
                }

                denominatorArr[maxI] /= maxGcd;
                moleculeArr[m] /= maxGcd;
            }
        }

        return FullPower(moleculeArr);
    }

    #region FullPower
    /// <summary>総乗、π</summary>
    public static long FullPower(IEnumerable<long> vs) {
        return vs.Aggregate(1L, (a, b) => a * b);
    }

    public static long FullPower(IEnumerable<int> vs) {
        return vs.Aggregate(1L, (a, b) => a * b);
    }
    #endregion

    /// <summary>最大公約数</summary>
    public static int Gcd(long item1, long item2) {
        var a = Math.Max(item1, item2);
        var b = Math.Min(item1, item2);

        while (true) {
            var mod = a % b;
            if (mod == 0) {
                break;
            }

            a = b;
            b = mod;
        }
        return (int)b;
    }

    /// <summary>約分。最大公約数で割ったものを返す。</summary>
    public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
        var gcd = Gcd(item1, item2);
        return new Tuple<long, long>(item1 / gcd, item2 / gcd);
    }
}

//static class IEnumerableExtention {
//    public static int IndexOfMax<T>(this IEnumerable<T> ts) {
//        var max = ts.Max();
//        return ts.ToList().IndexOf(max);
//    }

//    public static int IndexOfMax<T>(this IEnumerable<T> ts, Func<T, int> func) {
//        var funced = ts.Select(i => func(i));
//        var max = ts.Max(func);
//        return funced.ToList().IndexOf(max);
//    }

//    public static int IndexOfMax<T>(this IEnumerable<T> ts, Func<T, long> func) {
//        var funced = ts.Select(i => func(i));
//        var max = ts.Max(func);
//        return funced.ToList().IndexOf(max);
//    }
//}