    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            private bool Calc()
            {
                var n = int.Parse(Console.ReadLine());
                int now = 0;
                int MAX = 20000;
                for (int i = 0; i < n; i++)
                {
                    var s = Console.ReadLine().Split(' ');
                    int d = int.Parse(s[0]);
                    string v = s[1];
                    if (v == "North")
                    {
                        now -= d;
                        if (now < 0) return false;
                    }
                    else if (v == "South")
                    {
                        now += d;
                        if (now > MAX) return false;
                    }
                    else
                    {
                        if (now <= 0 || now >= MAX) return false;
                    }

                }
                return now == 0;
            }

            private void Solve()
            {

                if (Calc()) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                //Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NSproul //B
{
    class Program
    {
        static void Main()
        {
			int n = Int32.Parse(Console.ReadLine());
			int sum = 0;
			string ret = "NO";
			bool ret2 = true;

			for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split();
				if (temp[1] == "South") {
					sum += Int32.Parse(temp[0]);
				}
				else if (temp[1] == "North") {
					sum -= Int32.Parse(temp[0]);
				}
				else if (sum == 0 || sum == 20000) {
					ret2 = false;
					break;
				}

				//Console.WriteLine(sum);
				if (sum < 0 || sum > 20000) {
					break;
				}
            }

            if (sum == 0 && ret2) ret = "YES";
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;

namespace CP_CS
{

    class Task
    {

        static void Solve()
        {
            int n = ReadInt();
            int vert = 0;
            for (int i = 0; i < n; i++)
            {
                int dl = ReadInt();
                string dir = ReadToken();
                if (vert == 0)
                {
                    if (dir != "South")
                    {
                        Write("NO");
                        return;
                    }
                }
                if (vert == 20000)
                {
                    if (dir != "North")
                    {
                        Write("NO");
                        return;
                    }
                }
                if (dir == "North")
                {
                    if (vert - dl < 0)
                    {
                        Write("NO");
                        return;
                    }
                    vert -= dl;
                }
                if (dir == "South")
                {
                    if (vert + dl > 20000)
                    {
                        Write("NO");
                        return;
                    }
                    vert += dl;
                }
                vert = vert % 40000;
                if (vert > 20000)
                {
                    vert = 40000 - vert;
                }
            }
            if (vert == 0)
            {
                Write("YES");
            }
            else
            {
                Write("NO");
            }
        }

        public static double Rast(int[] xy1, int[] xy2)
        {
            return Math.Sqrt(Math.Pow(xy1[0] - xy2[0], 2) + Math.Pow(xy1[1] - xy2[1], 2));
        }

        static string[] Split(string str, int chunkSize)
        {
            return Enumerable.Range(0, str.Length / chunkSize)
                .Select(i => str.Substring(i * chunkSize, chunkSize)).ToArray();
        }

        #region -- Main --

        private static TextReader reader;
        private static TextWriter writer;

        static void Main()
        {
#if DEBUG
            //reader = new StreamReader("..\\..\\input.txt");
            reader = new StreamReader(Console.OpenStandardInput());
            writer = Console.Out;
            //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("pluses.in");
        //writer = new StreamWriter("pluses.out");
#endif
            try
            {
                //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
                //thread.Start();
                //thread.Join();
                Solve();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
            }
            reader.Close();
            writer.Close();
        }

        #endregion
        #region -- Read / Write --

        private static Queue<string> currentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string[] ReadAndSplitLine(char divisor)
        {
            return reader.ReadLine().Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine());
            return currentLineTokens.Dequeue();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        //public static BigInteger ReadBigInteger()
        //{
        //    return BigInteger.Parse(ReadToken());
        //}

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static bool[] ReadBoolArray()
        {
            return ReadAndSplitLine().ToString().ToCharArray().Select(chr => chr == '1').ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray();
            return matrix;
        }

        public static bool[][] ReadBoolMatrix(int numberOfRows)
        {
            bool[][] matrix = new bool[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadBoolArray();
            return matrix;
        }

        public static bool[][] TransposeBoolMatrix(bool[][] array, int numberOfRows)
        {
            bool[][] matrix = array;
            bool[][] ret = new bool[matrix[0].Length][];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = new bool[numberOfRows];
                for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];
            }
            return ret;
        }

        public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
        {
            int[][] matrix = ReadIntMatrix(numberOfRows);
            int[][] ret = new int[matrix[0].Length][];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = new int[numberOfRows];
                for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];
            }
            return ret;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            writer.WriteLine(string.Join(" ", array));
        }

        public static void Write(params object[] array)
        {
            WriteArray(array);
        }
        public static void WriteLines<T>(IEnumerable<T> array)
        {
            foreach (var a in array) writer.WriteLine(a);
        }
        private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
        {
            public new TValue this[TKey key]
            {
                get { return ContainsKey(key) ? base[key] : default(TValue); }
                set { base[key] = value; }
            }
        }
        private static T[] Init<T>(int size) where T : new()
        {
            var ret = new T[size];
            for (int i = 0; i < size; i++) ret[i] = new T();
            return ret;
        }
        #endregion
    }
}

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            private bool Calc()
            {
                var n = int.Parse(Console.ReadLine());
                int now = 0;
                int MAX = 20000;
                for (int i = 0; i < n; i++)
                {
                    var s = Console.ReadLine().Split(' ');
                    int d = int.Parse(s[0]);
                    string v = s[1];
                    if (v == "North")
                    {
                        now -= d;
                        if (now < 0) return false;
                    }
                    else if (v == "South")
                    {
                        now += d;
                        if (now > MAX) return false;
                    }
                    else
                    {
                        if (now == 0 || now == MAX) return false;
                    }

                }
                return now == 0;
            }

            private void Solve()
            {

                if (Calc()) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }

using System;

class B750 {
    static bool ReadJudge(int n) {
        int a = 0;
        for (int i = 0; i < n; ++i) {
            var line = Console.ReadLine().Split();
            var num = int.Parse(line[0]);
            switch (line[1]) {
                case "South":
                    a += num;
                    if (20000 < a) return false;
                    break;
                case "North":
                    a -= num;
                    if (a < 0) return false;
                    break;
                default:
                    if (a == 0 || a == 20000) return false;
                    break;
            }
        }
        return a == 0;
    }

    public static void Main() {
        var n = int.Parse(Console.ReadLine());
        Console.WriteLine(ReadJudge(n) ? "YES" : "NO");
    }
}

using System;

namespace Self
{
    class Program
    {
        static void Main(string[] args)
        {
            int MovAmm = int.Parse(Console.ReadLine());
            int VertPos = 0;
            bool Check = true;
            string[] MovData = new string[MovAmm];
            for (int i = 0; i < MovAmm; i++)
            {
                MovData[i] = Console.ReadLine();
            }

            string[] tempArray;
            int tempLength = 0;
            string tempDirect = null;
            for (int i = 0; i < MovAmm; i++)
            {
                tempArray = MovData[i].Split(' ');
                tempLength = int.Parse(tempArray[0]);
                tempDirect = tempArray[1];

                if (VertPos == 0)
                {
                    if ((tempDirect == "East") || (tempDirect == "West") || (tempDirect == "North"))
                    {
                        Check = false;
                        break;
                    }
                    else
                    {
                        if (VertPos + tempLength > 20000)
                        {
                            Check = false;
                            break;
                        }
                        else
                        {
                            VertPos += tempLength;
                        }
                    }
                }
                else if (VertPos == 20000)
                {
                    if ((tempDirect == "East") || (tempDirect == "West") || (tempDirect == "South"))
                    {
                        Check = false;
                        break;
                    }
                    else
                    {
                        if (VertPos < tempLength)
                        {
                            Check = false;
                            break;
                        }
                        else
                        {
                            VertPos -= tempLength;
                        }
                    }
                }
                else
                {
                    if (tempDirect == "North")
                    {
                        if(VertPos < tempLength)
                        {
                            Check = false;
                            break;
                        }
                        else
                        {
                            VertPos -= tempLength;
                        }
                    }
                    if (tempDirect == "South")
                    {
                        if (VertPos+tempLength > 20000)
                        {
                            Check = false;
                            break;
                        }
                        else
                        {
                            VertPos += tempLength;
                        }
                    }
                }
            }//конец фора
            if (Check)
            {
                if(VertPos == 0)
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
            }
            else
                Console.WriteLine("NO");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.NextInt();
      int w = 0;
      for (int i = 0; i < n; i++)
      {
        int t = input.NextInt();
        string d = input.NextToken();
        if (d == "South")
        {
          w += t;
        }
        else if (d == "North")
        {
          w -= t;
        }
        else if (w == 0 || w == 20000)
        {
          Console.Write("NO");
          return;
        }
        if (w < 0 || w > 20000)
        {
          Console.Write("NO");
          return;
        }
      }
      if (w != 0)
        Console.Write("NO");
      else
        Console.Write("YES");
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n;

        public void Solve()
        {
            n = ioHelper.ReadNextInt();

            int curNS = 0;
            int curEV = 0;

            bool bOK = true;

            while(n>0)
            {
                var dist = ioHelper.ReadNextInt();
                var dir = ioHelper.ReadNextToken();

                if (dir == "North")
                {
                    if (curNS == 0)
                        curNS = -1;
                    else
                        curNS -= dist;
                    if (curNS < 0)
                    {
                        bOK = false;
                        break;
                    }
                }
                else if (dir == "South")
                {
                    if (curNS == 20000)
                        curNS++;
                    else
                        curNS += dist;
                    if (curNS > 20000)
                    {
                        bOK = false;
                        break;
                    }
                }
                else
                {
                    if (curNS == 0 || curNS == 20000)
                    { bOK = false; break; }
                }
                n--;
            }

            if (curNS != 0)
                bOK = false;

            if (bOK)
                ioHelper.WriteLine("YES");
            else
                ioHelper.WriteLine("NO");
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int koord = 0;
            int location = 20000;
            string direction = "";
            string res = "";
            bool violation = false;
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');

                 koord = Convert.ToInt32(s[0]);
                 direction = s[1];

                if(direction=="North")
                {
                    location += koord;
                    if(location>20000)
                    {
                        res = "NO";
                        violation = true;
                    }
                }
                if(direction=="South")
                {
                    location -= koord;
                    if(location<0)
                    {
                        res = "NO";
                        violation = true;
                    }
                }
                if ((direction == "East" || direction == "West") && (location >= 20000 || location <= 0))
                {
                    violation = true;
                }
            }
            if (!violation)
            {
                if (location == 20000)
                {
                    res = "YES";
                }
                else { res = "NO"; }
            }
            else { res = "NO"; }
            Console.WriteLine(res);
        }
    }
}

//750B New Year and North Pole

using System;
class _750B
{
	static void Main()
	{
		int n=int.Parse(Console.ReadLine());
		int[] lens=new int[n];
		string[] dirs=new string[n];
		for(int i=0;i<n;i++)
		{
			string[] lendir=Console.ReadLine().Split();
			lens[i]=int.Parse(lendir[0]);
			dirs[i]=lendir[1];
		}

		int sum;
		sum=(dirs[0]=="South")?0:20000;
		for(int i=0;i<n;i++)
		{
			if(sum<0 || sum>20000)
				break;
			else if((sum==0 || sum==20000) && (dirs[i]=="East" || dirs[i]=="West"))
			{
				sum=-1;
				break;
			}
			else if(sum==0)
				sum+=lens[i];
			else if(sum==20000)
				sum-=lens[i];
			else
				if(dirs[i]=="South")
					sum+=lens[i];
				else if(dirs[i]=="North")
					sum-=lens[i];
		}
		Console.Write((sum==0)?"YES":"NO");
	}
}

using System;

namespace CSharp
{
    public class _750B
    {
        public static void Main()
        {
            bool valid = true;
            int position = 0;

            for (int n = int.Parse(Console.ReadLine()); n > 0; n--)
            {
                string[] tokens = Console.ReadLine().Split();

                int t = int.Parse(tokens[0]);
                string direction = tokens[1];

                if (position == 0 && direction != "South")
                {
                    valid = false;
                }

                if (position == 20000 && direction != "North")
                {
                    valid = false;
                }

                switch (direction)
                {
                    case "South":
                        position += t;
                        break;
                    case "North":
                        position -= t;
                        break;
                }

                if (position < 0 || position > 20000)
                {
                    valid = false;
                }
            }

            valid &= position == 0;

            Console.WriteLine(valid ? "YES" : "NO");
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace New_Year_and_North_Pole
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var t = new int[n];
            var dir = new int[n];
            for (int i = 0; i < n; i++)
            {
                t[i] = Next();
                dir[i] = Next();
            }

            int d = 0;

            for (int i = 0; i < n; i++)
            {
                if ((d == 0 || d == 20000) && dir[i] == 0)
                {
                    writer.WriteLine("NO");
                    writer.Flush();
                    return;
                }
                d += t[i]*dir[i];
                if (d < 0 || d > 20000)
                {
                    writer.WriteLine("NO");
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine(d == 0 ? "YES" : "NO");
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == 'N')
                    return -1;
                if (c == 'E')
                    return 0;
                if (c == 'W')
                    return 0;
                if (c == 'S')
                    return 1;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            int p=0;
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int l = Convert.ToInt32(s[0]);
                if ((p == 0 && s[1] != "South") || (p == 20000 && s[1] != "North") || (s[1] == "South" && p+l>20000) || (s[1] == "North" && p-l<0))
                {
                    Console.WriteLine("NO");
                    return;
                }
                if (s[1] == "South")
                {
                    p +=l;
                }
                else if (s[1] == "North")
                {
                   p-=l;
                }

            }
            if (p != 0) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _750B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int distFromNorth = 0;
            bool result = true;
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int t = int.Parse(line[0]);
                string dir = line[1];
                if (result)
                {
                    if ((distFromNorth == 0 && dir != "South") ||
                        (distFromNorth == 20000 && dir != "North") ||
                        (dir == "North" && t > distFromNorth) ||
                        (dir == "South" && t > 20000 - distFromNorth))
                    {
                        result = false;
                    }

                    if (dir == "North")
                    {
                        distFromNorth -= t;
                    }
                    else if (dir == "South")
                    {
                        distFromNorth += t;
                    }
                }
            }
            if (distFromNorth != 0)
            {
                result = false;
            }

            Console.WriteLine(result ? "YES" : "NO");
            //Console.ReadLine();
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }

        object Solve()
        {
            checked
            {
                var n = (int)ReadLong();
                var coord = 0;
                var result = true;
                for (int i = 0; i < n; i++)
                {
                    var parts = Read().Split(' ');
                    var len = int.Parse(parts[0]);
                    var dir = parts[1];
                    if ((coord == 20000 && dir != "North") || (coord == 0 && dir != "South"))
                    {
                        result = false;
                        break;
                    }
                    if (dir == "South")
                    {
                        if (coord + len > 20000)
                        {
                            result = false;
                            break;
                        }
                        coord += len;
                    }
                    else if (dir == "North")
                    {
                        if (coord - len < 0)
                        {
                            result = false;
                            break;
                        }
                        coord -= len;
                    }
                }
                return (result && coord == 0) ? "YES" : "NO";
            }
        }

        long[] Mirror(Tuple<long[], long[]> line, long[] point)
        {
            var x = line.Item1[0] + line.Item2[0] - point[0];
            var y = line.Item1[1] + line.Item2[1] - point[1];
            return new long[] { x, y };
        }

        class DSU
        {
            private int[] arr;
            private Random r = new Random();
            public DSU(int n)
            {
                arr = new int[n];
                for (int i = 0; i < n; i++)
                {
                    arr[i] = i;
                }
            }

            public int Find(int x)
            {
                if (arr[arr[x]] == arr[x])
                    return arr[x];
                var y = Find(arr[x]);
                arr[x] = y;
                return y;
            }

            public void Union(int x, int y)
            {
                var p1 = Find(x);
                var p2 = Find(y);
                if (p1 == p2)
                    return;
                if (r.NextDouble() < 0.5)
                    arr[p1] = p2;
                else
                    arr[p2] = p1;
            }

            public int[][] Enumerate()
            {
                return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => e.Select(y => y.i).ToArray()).ToArray();
            }

            public Tuple<int, int>[] GetCounts()
            {
                return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => Tuple.Create(k, e.Count())).ToArray();
            }
        }
        class Node
        {
            public List<int> Children = new List<int>();
            public long Sum;
            public Tuple<int, long> RecurseMax;
        }
        //int BS(long[][] cuts, int left, int right)
        //{
        //    if (right - left == 1)
        //        return left;
        //    var half = (left + right) / 2;

        //}

        struct Second
        {
            public Second(long count, long mana)
            {
                Mana = mana;
                Count = count;
            }

            public long Mana;
            public long Count;
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }
}

using System;

namespace bcs
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var n = Int32.Parse(Console.ReadLine().Trim());

            var ans = true;

            var prevHight = 0;
            for (int i = 0; i < n; i++) {
                var line = Console.ReadLine().Trim().Split();
                var t = Int32.Parse(line[0]);
                var dir = line[1];

                if (i == 0 && dir != "South") {
                    ans = false;
                    break;
                }

                switch (dir) {
                    case "South":
                        if (prevHight + t > 20000) {
                            ans = false;
                        }
                        else {
                            prevHight += t;
                        }
                        break;
                    case "North":
                        if (prevHight - t < 0) {
                            ans = false;
                        }
                        else {
                            prevHight -= t;
                        }
                        break;
                    case "East":
                        if (prevHight == 0 || prevHight == 20000) {
                            ans = false;
                        }
                        break;
                    case "West":
                        if (prevHight == 0 || prevHight == 20000) {
                            ans = false;
                        }
                        break;
                }

                if (!ans) {
                    break;
                }
            }

            if (prevHight != 0) {
                ans = false;
            }

            Console.WriteLine(ans ? "YES" : "NO");
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            //using (var sw = new StreamWriter("output.txt"))
            {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var curr = 0L;
            var x = 0.0;
            var y = 0.0;
            var scaleX = 1.0;
            for (var i = 0; i < n; i++) {
                var next = sr.NextSplitStrings();
                var nextD = Int32.Parse(next[0]);
                var dir = next[1];
                if (Math.Abs(y - 0) <= 0.000000001 && Math.Abs(x*scaleX - 0.0) <= 0.000000001 && dir != "South")
                {
                    sw.WriteLine("NO");
                    return;
                }
                if (Math.Abs(y - 20000.0) <= 0.000000001 && Math.Abs(x*scaleX - 0.0) <= 0.000000001 && dir != "North")
                {
                    sw.WriteLine("NO");
                    return;
                }
                switch (dir) {
                    case "North":
                        y -= nextD;
                        break;
                    case "South":
                        y += nextD;
                        break;
                    case "West":
                        x -= nextD;
                        break;
                    default:
                        x += nextD;
                        break;
                }
                if (y < 0.0) {
                    sw.WriteLine("NO");
                    return;
                }
                if (y > 20000.0) {
                    sw.WriteLine("NO");
                    return;
                }
                if (dir == "North" || dir == "South") {
                    scaleX = y / 10000.0;
                }
            }

            if (Math.Abs(y - 0) <= 0.000000001 && Math.Abs(x*scaleX - 0.0) <= 0.000000001)
            {
                sw.WriteLine("YES");
                return;
            }

            sw.WriteLine("NO");
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay = false;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directionToSouth == 0 && directions[i] != "South")
                {
                    rightWay = false;
                    break;
                }
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }

                if (directionToSouth < 0 || directionToSouth > 20000)
                {
                    rightWay = false;
                    break;
                }

                rightWay = directionToSouth == 0 ? true : false;
            }

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            bool cond = true;
            int n = Int32.Parse(Console.ReadLine());
            int[] dist = new int[n];
            string[] dir = new string[n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                dist[i] = Int32.Parse(s[0]);
                dir[i] = s[1];
            }
            if (dir[0] != "South")
            {
                cond = false;
                //Console.WriteLine("no1");
            }
            else
            {
                int x = 0;
                for (int i = 0; i < n; i++)
                {
                    if (dir[i] == "South")
                    {
                        x += dist[i];
                        if (x > 20000 || x < 0)
                            break;
                    }
                    else if (dir[i] == "North")
                    {
                        x -= dist[i];
                        if (x > 20000 || x < 0)
                            break;
                    }
                    if (x >= 20000)
                    {
                        if ((i < n - 1) && ((dir[i] == "South" && dir[i + 1] != "North") || (dir[i] == "North" && dir[i + 1] != "South")))
                        {
                            break;
                        }
                    }
                }
                if (x != 0 || dir[n - 1] != "North")
                    cond = false;
                else
                    cond = true;
            }
            if (cond)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		int now = 0;
		for(int i=0;i<N;i++){
			if(S[i][1] == "East" || S[i][1] == "West"){
				if(now == 0 || now == 20000 ){
					Console.WriteLine("NO");
					return;
				}
			}
			if(S[i][1] == "North"){
				int t = int.Parse(S[i][0]);
				if(now - t < 0){
					Console.WriteLine("NO");
					return;
				}
				now -= t;
			}
			if(S[i][1] == "South"){
				int t = int.Parse(S[i][0]);
				if(now + t > 20000){
					Console.WriteLine("NO");
					return;
				}
				now += t;
			}
		}

		Console.WriteLine(now == 0 ? "YES" : "NO");
	}
	int N;
	String[][] S;
	public Sol(){
		N = ri();
		S = new String[N][];
		for(int i=0;i<N;i++) S[i] = rsa();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

using System;
using System.Linq;

namespace Codeforces
{
    public class Program
    {
        private const int MAXN = 8000;

        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine().Trim());
            int x = 0;

            for (int i = 0; i < n; i++)
            {
                string[] arr = Console.ReadLine().Trim().Split(' ').ToArray();
                int dx = int.Parse(arr[0]);
                string direction = arr[1];

                if (direction == "South")
                {
                    if (x + dx > 20000)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                    x += dx;
                }
                else if (direction == "North")
                {
                    if (x - dx < 0)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                    x -= dx;
                }
                else
                {
                    if (x == 0 || x == 20000)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
            }
            Console.WriteLine(x == 0 ? "YES" : "NO");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;

class Program
{
    static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static Scan sc = new Scan();
//    static Scan sc = new ScanCHK();
    const int M = 1000000007;
    const double eps = 1e-9;
    static readonly int[] dd = { 0, 1, 0, -1, 0 };
    static void Main()
    {
        int n = sc.Int;
        int now = 0;
        for (int i = 0; i < n; i++)
        {
            int d;
            string s;
            sc.Multi(out d, out s);
            switch (s)
            {
                case "North":
                    if (now - d < 0)
                    {
                        DBG("NO");
                        return;
                    }
                    now -= d;
                    break;
                case "South":
                    if (now + d > 20000)
                    {
                        DBG("NO");
                        return;
                    }
                    now += d;
                    break;
                default:
                    if (now == 0 || now == 20000)
                    {
                        DBG("NO");
                        return;
                    }
                    break;
            }
        }
        Prt(now == 0 ? "YES" : "NO");
        sw.Flush();
    }

    static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
    static T Max<T>(params T[] a) => a.Max();
    static T Min<T>(params T[] a) => a.Min();
    static void DBG<T>(params T[] a) => Console.WriteLine(string.Join(" ", a));
    static void DBG(params object[] a) => Console.WriteLine(string.Join(" ", a));
    static void Prt<T>(params T[] a) => sw.WriteLine(string.Join(" ", a));
    static void Prt(params object[] a) => sw.WriteLine(string.Join(" ", a));
}
static class ex
{
    public static string con<T>(this IEnumerable<T> a) => a.con(" ");
    public static string con<T>(this IEnumerable<T> a, string s) => string.Join(s, a);
    public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
    public static T[] copy<T>(this IList<T> a)
    {
        var ret = new T[a.Count];
        for (int i = 0; i < a.Count; i++) ret[i] = a[i];
        return ret;
    }
}
static class Operator<T>
{
    static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
    static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
    public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
    public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
    public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
    public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
    public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
    public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
    public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
    public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}

class ScanCHK : Scan
{
    public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } }
}
class Scan
{
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public string Str => Console.ReadLine().Trim();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
    public string[] StrArr => Str.Split();
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s);
    public void Multi<T>(out T a) => a = cv<T>(Str);
    public void Multi<T, U>(out T a, out U b)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); }
    public void Multi<T, U, V>(out T a, out U b, out V c)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
    public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); }
    public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); }
}
class mymath
{
    public static long Mod = 1000000007;
    public static bool isprime(long a)
    {
        if (a < 2) return false;
        for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
        return true;
    }
    public static bool[] sieve(int n)
    {
        var p = new bool[n + 1];
        for (int i = 2; i <= n; i++) p[i] = true;
        for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
        return p;
    }
    public static List<int> getprimes(int n)
    {
        var prs = new List<int>();
        var p = sieve(n);
        for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
        return prs;
    }
    public static long[][] E(int n)
    {
        var ret = new long[n][];
        for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
        return ret;
    }
    public static long[][] pow(long[][] A, long n)
    {
        if (n == 0) return E(A.Length);
        var t = pow(A, n / 2);
        if ((n & 1) == 0) return mul(t, t);
        return mul(mul(t, t), A);
    }
    public static double dot(double[] x, double[] y)
    {
        int n = x.Length;
        double ret = 0;
        for (int i = 0; i < n; i++) ret += x[i] * y[i];
        return ret;
    }
    public static long dot(long[] x, long[] y)
    {
        int n = x.Length;
        long ret = 0;
        for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
        return ret;
    }
    public static T[][] trans<T>(T[][] A)
    {
        int n = A[0].Length, m = A.Length;
        var ret = new T[n][];
        for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
        return ret;
    }
    public static double[] mul(double[][] A, double[] x)
    {
        int n = A.Length;
        var ret = new double[n];
        for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
        return ret;
    }
    public static long[] mul(long[][] A, long[] x)
    {
        int n = A.Length;
        var ret = new long[n];
        for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
        return ret;
    }
    public static long[][] mul(long[][] A, long[][] B)
    {
        int n = A.Length;
        var Bt = trans(B);
        var ret = new long[n][];
        for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
        return ret;
    }
    public static long[] add(long[] x, long[] y)
    {
        int n = x.Length;
        var ret = new long[n];
        for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
        return ret;
    }
    public static long[][] add(long[][] A, long[][] B)
    {
        int n = A.Length;
        var ret = new long[n][];
        for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
        return ret;
    }
    public static long pow(long a, long b)
    {
        if (a >= Mod) return pow(a % Mod, b);
        if (a == 0) return 0;
        if (b == 0) return 1;
        var t = pow(a, b / 2);
        if ((b & 1) == 0) return t * t % Mod;
        return t * t % Mod * a % Mod;
    }
    public static long inv(long a) => pow(a, Mod - 2);
    public static long gcd(long a, long b)
    {
        while (b > 0) { var t = a % b; a = b; b = t; }
        return a;
    }
    // a x + b y = gcd(a, b)
    public static long extgcd(long a, long b, out long x, out long y)
    {
        long g = a; x = 1; y = 0;
        if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
        return g;
    }
    public static long lcm(long a, long b) => a / gcd(a, b) * b;
    public static long comb(int n, int r)
    {
        if (n < 0 || r < 0 || r > n) return 0;
        if (n - r < r) r = n - r;
        if (r == 0) return 1;
        if (r == 1) return n;
        int[] numer = new int[r], denom = new int[r];
        for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
        for (int p = 2; p <= r; p++)
        {
            int piv = denom[p - 1];
            if (piv > 1)
            {
                int ofst = (n - r) % p;
                for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
            }
        }
        long ret = 1;
        for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
        return ret;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class A
    {
      static void Main(string[] args)
      {
         int n = int.Parse(Console.ReadLine());

         string[] s = new string[n];
         int[] values = new int[n];

         for(int i=0;i<n;i++)
         {
            string[] token = Console.ReadLine().Split();
            values[i] = int.Parse(token[0]);
            s[i] = token[1];
         }

         int sum = 0;

         if(s[0]!="South")
         {
            Console.WriteLine("No");
            return;
         }
         string last = "";
         for(int i=0;i<n;i++)
         {
            if(values[i]>20000)
            {
               if(s[i]=="North"||s[i]=="South"){
               sum =1;
               break;}
            }
            if(s[i]=="South")
            {
               sum += values[i];
               if(sum>20000)
                  break;
            }
            else if(s[i]=="North"){
               sum -= values[i];
               if(sum<0)
                  break;
            }
            if(i<s.Length-1)
            {
               if(sum==0&&s[i+1]!="South")
               {
                  sum = 1;
                  break;
               }else if(sum==20000&&s[i+1]!="North")
               {
                  sum = 1;
                  break;
               }
            }
         }

         if(sum==0)
         {
            Console.WriteLine("Yes");
         }
         else{
            Console.WriteLine("No");
         }
      }

    }
}

using System;

namespace ACM_3M_Bye_2016_
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] Len = new int[n];
            string[] Dir = new string[n];
            for (int i = 0;i< n;i++)
            {
                string s = Console.ReadLine();
                string[] A = s.Split(' ');
                Len[i] = Convert.ToInt32(A[0]);
                Dir[i] = A[1];
            }
            int Meridian = 0;
            int a = 0;
            for (int i = 0; i < n; i++)
                if ((Meridian == 0 && Dir[i] != "South") || (Meridian == 20000 && Dir[i] != "North")) { a++; break; }
                else if (Dir[i] == "South" && (Meridian + Len[i] <= 20000)) Meridian += Len[i];
                else if (Dir[i] == "South" && (Meridian + Len[i] > 20000)) { a++; break; }
                else if (Dir[i] == "North" && (Meridian - Len[i] < 0)) { a++; break; }
                else if (Dir[i] == "North" && (Meridian - Len[i] >= 0)) Meridian -= Len[i];
            if (Meridian != 0 || a != 0) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        SetOut(sw);
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";

    void solve()
    {
        int posi = 0;
        int n = cin.nextint;
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            var L = cin.nextint;
            var D = cin.next;
            if (posi == 0 && D != "South")
            {
                flag = false;
            }
            else if (posi == 20000 && D != "North")
            {
                flag = false;
            }

            else if (D == "South")
            {
                if (posi + L <= 20000)
                {
                    posi += L;
                }
                else
                {
                    flag = false;
                }
            }
            else if (D == "North")
            {
                if (posi - L >= 0)
                {
                    posi -= L;
                }
                else
                {
                    flag = false;
                }
            }
        }

        if (flag && posi == 0)
        {
            WriteLine("YES");
        }
        else
        {
            WriteLine("NO");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

// https://codeforces.com/contest/750/problem/B
public static class B__
{
    private static void Solve()
    {
        int n = ReadInt();

        int y = 0;
        bool valid = true;

        while (n-- > 0)
        {
            int distance = ReadInt();
            string direction = Read();

            if (y == 0 && direction != "South")
            {
                valid = false;
                break;
            }

            if (y == 20000 && direction != "North")
            {
                valid = false;
                break;
            }

            Move(ref y, distance, direction);

            if (y < 0 || y > 20000)
            {
                valid = false;
                break;
            }
        }

        if (y != 0)
            valid = false;

        Write(valid ? "YES" : "NO");
    }

    private static void Move(ref int y, int distance, string direction)
    {
        if (direction == "North")
        {
            y -= distance;
        }
        else if (direction == "South")
        {
            y += distance;
        }
    }

    #region Main

    private static TextReader reader;
    private static TextWriter writer;
    public static void Main()
    {
#if DEBUG
        //reader = new StreamReader("C:\\Users\\Axel\\Desktop\\input.txt");
        reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            Solve();
            //var thread = new Thread(new B__().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string Read() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problem750B
{
    class Program
    {
        static string Solve(int n)
        {
            int latitude = 0;

            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine().Split(' ');
                int d = int.Parse(s[0]);
                switch (s[1])
                {
                    case "South":
                        if (latitude == 20000)
                            return "NO";
                        latitude += d;
                        if (latitude > 20000)
                            return "NO";

                        break;
                    case "North":
                        if (latitude == 0)
                            return "NO";
                        else
                            latitude -= d;
                        if (latitude < 0)
                            return "NO";

                        break;
                    default:
                        if (latitude == 0 || latitude == 20000)
                            return "NO";
                        break;
                }
            }

            return latitude == 0 ? "YES" : "NO";
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(Solve(n));
        }
    }
}

using System;
using System.Collections.Generic;

namespace CF_750B
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int length = 0, ts= 0, tn = 0, sc = 0, nc = 0, row_no;
			string direction, last_direction="North";
			string[] journey;
			string res="NO";
			bool valid = false;
			int n = Int32.Parse (Console.ReadLine ());

			List<string> ls = new List<string> ();
			for (int a = 0; a < n; a++)
			{
				ls.Add (Console.ReadLine ());
			}

//			foreach (var _ls in ls) {
//				Console.WriteLine(_ls);
//			}

			foreach (string row in ls)
			{
				row_no = ls.IndexOf (row);
				if (row_no == 0) {
					last_direction = "North";
				}

				journey = row.Split (' ');

				length= Int32.Parse(journey [0]);
				direction = journey [1];

				valid = is_the_move_legal (n, row_no, last_direction, direction);
//				Console.WriteLine ("=== VALIDITY: {0}", valid);

				if (!valid) {
					res = "NO";
					break;
				}

				if (direction == "North") {
					if (length > 20000 || tn+length > 20000 ) {
						res = "NO";
						break;
					}
					tn += length;
//					Console.WriteLine ("Toward_North: {0}", tn);
					if (tn == 20000) {
						last_direction = "North";
					} else {
						last_direction = "Ignore";
					}
				}
				else if (direction == "South") {
					if (length > 20000 || ts+length > 20000 ) {
						break;
					}
					ts += length;
//					Console.WriteLine ("Toward_South: {0}", ts);
					if (ts == 20000) {
						last_direction = "South";
					} else {
						last_direction = "Ignore";
					}
				}

				if (tn == 20000 && ts == 20000)
				{
					res = "YES";
					tn = ts = 0;
				}

				if (ls.IndexOf (row) == n - 1 && ts == tn) {
					res = "YES";
				}
			}
			Console.WriteLine (res);

		}

		private static bool is_the_move_legal(int n, int _row_no, string last_direction, string direction)
		{
//			Console.WriteLine ("Last_Direction: {0}", last_direction);
//			Console.WriteLine ("Current_Direction: {0}", direction);

			if (_row_no == 0 && direction != "South")
			{
				return false;
			}

			if (_row_no == n - 1 && direction != "North")
			{
				return false;
			}

			if (last_direction == "South" && direction != "North") {
				return false;
			}

			if (last_direction == "North" && direction != "South") {
				return false;
			}

			return true;
		}

	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf750_02
{
    const int intSizeLine = 20000;
    const string SOUTH = "S";
    const string NORTH = "N";

    static bool violation = false;
    static int y;

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        y = 0;

        for (int i = 0; i < n; i++)
        {
            string strInfo = Console.ReadLine();
            int intSize = int.Parse(strInfo.Split()[0]);
            string strDirection = strInfo.Split()[1].Substring(0, 1);

            if (y == 0 && strDirection!=SOUTH)
            {
                violation = true;
            }

            if (y == intSizeLine && strDirection != NORTH)
            {
                violation = true;
            }

            if (strDirection == SOUTH)
            {
                y = GetY(intSize, SOUTH);
            }
            else if (strDirection == NORTH)
            {
                y = GetY(intSize, NORTH);
            }
        }

        if (y == 0 && !violation )
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }

    public static int GetY(int intValue, string strDirection)
    {
        int intResult = 0;

        switch (strDirection)
        {
            case NORTH:
                if (y - intValue < 0)
                {
                    violation = true;
                    return intResult;
                }
                else
                {
                    intResult = y - intValue;
                }
                break;

            case SOUTH:
                if (intValue + y > intSizeLine)
                {
                    violation = true;
                    return intResult;
                }
                else
                {
                    intResult = y + intValue;
                }
                break;
        }

        return intResult;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1A
{
  class Program750B

  {
    static void Main(string[] args)
    {
      int p = 0;

      int n = Convert.ToInt32(Console.ReadLine());
      for (int i = 0; i < n; i++)
      {
        string[] tk = Console.ReadLine().Split(' ');
        int l = Convert.ToInt32(tk[0]);
        if (p == 0 || p == 20000)
          if (tk[1] == "East" || tk[1] == "West")
          {
            Console.WriteLine("NO");
            return;
          }

        if (tk[1] == "North")
          if (p - l < 0)
          {
            Console.WriteLine("NO");
            return;
          }
          else
            p = p - l;

        if (tk[1] == "South")
          if (p + l > 20000)
          {
            Console.WriteLine("NO");
            return;
          }
          else
            p = p + l;
      }

      if (p!=0)
        Console.WriteLine("NO");
      else
        Console.WriteLine("YES");

    }
  }
}

using System;

namespace tmp6
{
    class Program
    {

        static int Main()
        {
            int n = int.Parse(Console.ReadLine()), tmp = 0;
            int[] t = new int[n];
            string[] dir = new string[n];
            for(int i = 0; i < n; i++)
            {
                string[] strMas = Console.ReadLine().Split(' ');
                t[i] = int.Parse(strMas[0]);
                dir[i] = strMas[1];
            }
            if (dir[0] != "South")
            {
                Console.WriteLine("NO");
                return 0;
            }

            for (int i = 0; i < n - 1; i++)
            {
                if (dir[i] == "North")
                    tmp -= t[i];
                else if (dir[i] == "South")
                    tmp += t[i];

                if (tmp == 0)
                {
                    if (dir[i + 1] != "South")
                    {
                        Console.WriteLine("NO");
                        return 0;
                    }
                }
                else if(tmp < 0)
                {
                    Console.WriteLine("NO");
                    return 0;
                }
                else if (tmp == 20000)
                {
                    if (dir[i + 1] != "North")
                    {
                        Console.WriteLine("NO");
                        return 0;
                    }
                }
                else if(tmp > 20000)
                {
                    Console.WriteLine("NO");
                    return 0;
                }

            }
            if (dir[n - 1] == "North")
                tmp -= t[n - 1];
            else if (dir[n - 1] == "South")
                tmp += t[n - 1];
            if (tmp == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            return 0;
        }
    }
}

using System;

namespace Codeforces
{
	class Problem750B
	{

	    static private long Move(long y, long distance, string direction) {
            const long minY = 0;
            const long maxY = 20000;
            if(y == minY && direction !="South" ||
                    y == maxY && direction !="North"){
                return -1;
            }
            long result = y;
            if (direction == "South"){
                result += distance;
            }
            if (direction == "North"){
                result -= distance;
            }
            return result > maxY || result < minY ? -1 : result;
        }

	   	static void Main() {
		    int stepsCount = int.Parse(Console.In.ReadLine());
		    long y = 0;
            for (int i = 0; i < stepsCount; i++) {
                string[] args = Console.In.ReadLine().Split(' ');
                long distance = long.Parse(args[0]);
                string direction = args[1];
                y = Move(y, distance, direction);
                if (y == -1) {
                    break;
                }
            }
			Console.Out.WriteLine(y == 0 ? "YES" : "NO");
			Console.In.ReadLine();
		}
	}
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;

class Myon
{
    static Scanner cin;
    public Myon() { }
    public static int Main()
    {
        //Console.SetOut(new Printer(Console.OpenStandardOutput()));
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    public bool calc2()
    {

        int N;
        N = cin.nextInt();

        int now = 0;
        int MAX = 20000;
        for (int i = 0; i < N; i++)
        {
            int d = cin.nextInt();
            string v = cin.next();
            if(v == "North")
            {
                now -= d;
                if (now < 0) return false;
            }
            else if(v == "South")
            {
                now += d;
                if (now > MAX) return false;
            }
            else
            {
                if (now <= 0 || now >= MAX) return false;
            }

        }
        return now == 0;
    }

    public void calc()
    {
        if (calc2()) Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }

}

class Printer : StreamWriter
{
    public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
    public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        while (i >= s.Length)
        {
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
        }
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication2
{

    class Program
    {

        static int[,] matrix;
        static int[] mark;

        static void DFS(int v)
        {

            mark[v] = 1;
            for (int i = 0; i < matrix.GetLength(0); i++)
            {

                if (matrix[v, i] == 1)
                {

                    if (mark[v] == 0)
                    {
                        DFS(i);
                    }
                }
            }

        }
        static bool IsPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        static void IsYesNo(bool b)
        {
            if (b)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
        static void Main(string[] args)
        {

            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int x = 0;
            bool f = true;
            for (int i = 0; i < n; i++)
            {
                //Console.WriteLine(x);
                string[] s = Console.ReadLine().Split();
                int a = int.Parse(s[0]);
                if (x == 0)
                {
                    if (s[1] != "South")
                    {
                        f = false;
                    }
                    else
                    {

                        x += a;
                        if (x > 20000)
                        {
                            f = false;
                        }

                    }
                }
                else if (x == 20000)
                {
                    if (s[1] != "North")
                    {
                        f = false;
                    }
                    else
                    {

                        x -= a;
                        if (x < 0)
                        {
                            f = false;
                        }

                    }
                }
                else
                {
                    if (s[1] == "South")
                    {

                        x += a;
                        if (x > 20000)
                        {
                            f = false;
                        }

                    }
                    else if (s[1] == "North")
                    {

                        x -= a;
                        if (x < 0)
                        {
                            f = false;
                        }
                    }

                }

            }
            if (!f)
            {
                Console.WriteLine("NO");
            }
            else
            {
                if (x == 0)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }

        }

    }
}

using System;
using System.Linq;
using System.Collections.Generic;

class Solution
{
	static void Main() {
		int n = int.Parse (Console.ReadLine ());
		int y = 0;
		for (int i = 0; i < n; i++) {
			string[] parts = Console.ReadLine ().Split ();
			int dist = int.Parse (parts [0]);
			switch (parts [1]) {
			case "North":
				if (y == 0) {
					Console.WriteLine ("NO");
					return;
				}
				y -= dist;
				break;
			case "South":
				if (y == 20000) {
					Console.WriteLine ("NO");
					return;
				}
				y += dist;
				break;
			case "East":
			case "West":
				if (y == 0 || y == 20000) {
					Console.WriteLine ("NO");
					return;
				}
				break;
			}
			if (y < 0 || y > 20000) {
				Console.WriteLine ("NO");
				return;
			}
		}
		Console.WriteLine (y == 0 ? "YES" : "NO");
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{

    public class Helper
    {
        public List<Helper> Helpers { get; set; }
        public string From { get; set; }
        public List<string> To { get; set; }

        public void Load()
        {
            Helpers = new List<Helper>();

            Helper North = new Helper();
            North.From = "North";
            North.To = new List<string>();
            North.To.Add("South_x_+");
            North.To.Add("North_x_-");

            North.To.Add("West_y_+");
            North.To.Add("East_y_-");

            Helpers.Add(North);

            Helper South = new Helper();
            South.From = "South";
            South.To = new List<string>();

            South.To.Add("North_x_-");
            South.To.Add("South_x_+");

            South.To.Add("East_y_-");
            South.To.Add("West_y_+");

            Helpers.Add(South);

            Helper West = new Helper();
            West.From = "West";
            West.To = new List<string>();
            West.To.Add("South_x_+");
            West.To.Add("North_x_-");

            West.To.Add("East_y_-");
            West.To.Add("West_y_+");

            Helpers.Add(West);

            Helper East = new Helper();
            East.From = "East";
            East.To = new List<string>();
            East.To.Add("South_x_+");
            East.To.Add("North_x_-");

            East.To.Add("West_y_+");
            East.To.Add("East_y_-");

            Helpers.Add(East);

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetIntegerInputFromLine();

            List<object> lines = new List<object>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();

                lines.Add(inputs);

            }

            Helper helper = new Helper();
            helper.Load();

            long x = 0;
            long y = 0;

            var CurrentPosition = "North";

            var satisfy = true;

            foreach (var item in lines)
            {
                var inputs = (string[])item;
                var km = Convert.ToInt64(inputs[0]);
                var dir = inputs[1];

                var anyDirection = helper.Helpers.FirstOrDefault(f => f.From == CurrentPosition);

                var toDirection = anyDirection.To.FirstOrDefault(z => z.Split('_')[0] == dir);

                var toDI = toDirection.Split('_');

                if (x == 0)
                {

                    if (toDI[0] != "South")
                    {
                        satisfy = false;
                        break;
                    }

                }

                if (x == 20000)
                {
                    if (toDI[0] != "North")
                    {
                        satisfy = false;
                        break;
                    }
                }

                if (toDirection == null)
                {

                    satisfy = false;
                    break;
                }
                else
                {

                    if (toDI[1] == "x")
                    {
                        if (toDI[2] == "+")
                        {
                            x += km;
                        }
                        else
                        {
                            x -= km;
                        }
                    }
                    else
                    {
                        if (toDI[2] == "+")
                        {
                            y += km;
                        }
                        else
                        {
                            y -= km;
                        }
                    }
                }
                  if(x>20000||x<0){
                	satisfy=false;
                	break;

                  }

                CurrentPosition = dir;
            }

            if (satisfy && CurrentPosition == "North" && x <= 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

        public static bool Bfs(Dictionary<string, List<string>> graph, string from, string to)
        {
            Dictionary<string, int> level = new Dictionary<string, int>();
            Dictionary<string, int> visited = new Dictionary<string, int>();

            Queue<string> queue = new Queue<string>();

            queue.Enqueue(from);
            level[from] = 1;
            visited[from] = 1;
            while (queue.Count() > 0)
            {
                string front = queue.Peek();

                if (front == to)
                {
                    return true;
                }

                List<string> values;

                if (graph.TryGetValue(front, out values))
                {

                    foreach (var item in values)
                    {
                        if (!visited.ContainsKey(item))
                        {
                            level[item] = level[front] + 1;
                            visited[item] = 1;
                            queue.Enqueue(item);
                        }
                    }
                }

                queue.Dequeue();

            }

            return false;
        }
        public void InputBfs()
        {
            var input = GetIntegerInputFromLine();

            Dictionary<string, List<string>> graph = new Dictionary<string, List<string>>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();
                AddOrUpdate(graph, inputs[0], inputs[1]);
                AddOrUpdate(graph, inputs[1], inputs[0]);
            }

            var ins = GetStringInputsFromLine();

            var isRoute = Bfs(graph, ins[0], ins[1]);

            if (!isRoute)
            {
                Console.WriteLine("No route");
            }
            else
            {
                Console.WriteLine("route");
            }
        }

        public static IDictionary<TKey, List<TValue>> AddOrUpdate<TKey, TValue>(IDictionary<TKey, List<TValue>> dictionary, TKey key, TValue value)
        {
            List<TValue> values;

            if (dictionary.TryGetValue(key, out values))
            {
                values.Add(value);

                dictionary[key] = values;
            }
            else
            {
                values = new List<TValue>();
                values.Add(value);
                dictionary[key] = values;
            }

            return dictionary;
        }

        static int GetIntegerInputFromLine()
        {
            var input = Convert.ToInt32(Console.ReadLine().Trim());
            return input;
        }

        static int[] GetIntegerInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x.Trim())).ToArray();
            return inputs;
        }

        static long GetLongInputFromLine()
        {
            var input = Convert.ToInt64(Console.ReadLine().Trim());
            return input;
        }

        static long[] GetLongInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x.Trim())).ToArray();
            return inputs;
        }

        static double GetDoubleInputFromLine()
        {
            var input = Convert.ToDouble(Console.ReadLine().Trim());
            return input;
        }

        static double[] GetDoubleInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToDouble(x.Trim())).ToArray();
            return inputs;
        }

        static string GetStringInputFromLine()
        {
            var input = Console.ReadLine();
            return input;
        }

        static string[] GetStringInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ');
            return inputs;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Source
{

    public void Program()
    {

    }
    HashSet<int> answers = new HashSet<int>();
    int n;
    int[] a;
    void Read()
    {
        n = ri();
        int a;
        string s;
        int pos = 0;
        for (int i = 0; i < n; i++)
        {
            a = ri();
            s = ReadToken();
            if(s== "North" || s == "South")
            {
                if (s == "South")
                {
                    pos += a;
                }
                else
                    pos -= a;
                if(pos<0||pos>20000)
                {
                    writeLine("NO");
                    return;
                }
            }else
            {
                if(a>0 &&(pos == 0 || pos == 20000))
                {
                    writeLine("NO");
                    return;
                }
            }
        }
        if(pos == 0)
        {
            writeLine("YES");
            return;
        }
        writeLine("NO");
        return;
    }

    #region hide it
    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
            reader = new StreamReader(Console.OpenStandardInput());
            writer = new StreamWriter(Console.OpenStandardOutput());
            //reader = new StreamReader("input.txt");
            //writer = new StreamWriter("output.txt");
#endif
        var source = new Source();
        source.Read();
        source.Program();

        /* try
         {
             new Source().Program();
         }
         catch (Exception ex)
         {
 #if DEBUG
             Console.WriteLine(ex);
 #else
             throw;
 #endif
         }*/
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }
    public static int ri() { return int.Parse(ReadToken()); }
    public static char ReadChar() { return char.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static ulong ReaduLong() { return ulong.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(i => int.Parse(i)).ToArray(); }
    public static char[] ReadCharArray() { return ReadAndSplitLine().Select(i => char.Parse(i)).ToArray(); }
    public static char[] SplitToChar() { string s = ReadToken(); char[] r = new char[s.Length]; for (int i = 0; i < s.Length; i++) r[i] = s[i]; return r; }
    public static byte[] SplitToByte() { string s = ReadToken(); byte[] r = new byte[s.Length]; for (int i = 0; i < s.Length; i++) r[i] = (byte)s[i]; return r; }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static char[][] ReadCharMatrix(int numberOfRows) { char[][] matrix = new char[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadCharArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void write<T>(T value) { writer.Write(value); }
    public static void writeLine<T>(T value) { writer.WriteLine(value); }
    public static void writeArray<T>(T[] array, string split) { for (int i = 0; i < array.Length; i++) { write(array[i] + split); } }
    public static void writeMatrix<T>(T[][] matrix, string split) { for (int i = 0; i < matrix.Length; i++) { writeArray(matrix[i], split); writer.Write("\n"); } }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion

    #region Methods
    #region DSU
    public void MakeSet(int[] poi)
    {
        for (int i = 0; i < poi.Length; i++)
        {
            poi[i] = i;
        }
    }
    public int Find(int x, int[] poi)
    {
        if (poi[x] == x) return x;
        return poi[x] = Find(poi[x], poi);
    }
    Random rand = new Random();
    public void Unite(int x, int y, int[] poi)
    {
        y = Find(y, poi);
        x = Find(x, poi);
        if (rand.Next() % 2 == 0)
            Swap(ref x, ref y);
        poi[x] = y;
    }
    #endregion

    class Deque<T>
    {
        T[] array;
        int start, length;
        public Deque()
        {
            start = 0; length = 0; array = new T[1];
        }
        public T this[int index] { get { return array[(start + index) % array.Length]; } set { array[(start + index) % array.Length] = value; } }
        int last { get { return (start + length) % array.Length; } }
        /// <summary>
        /// ÃÆÃ¢â¬ËÃâÃÂÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬Ã
        /// </summary>
        public T PeekFirst()
        {
            return array[start];
        }
        public int Count { get { return length; } }
        /// <summary>
        /// ÃÆÃÂÃâÃÂºÃÆÃÂÃâÃÂ¾ÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂµÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬  ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        public T PeekLsat()
        {
            return array[last];
        }
        public T PopLast()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            return array[last];
        }
        public T PopFirst()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            if (start >= array.Length - 1) start = 0; else start++;
            return array[start - 1 < 0 ? array.Length - 1 : start - 1];
        }
        public void AddFirst(T value)
        {
            IncreaseAndInspection();
            if (start <= 0) start = array.Length - 1; else start--;
            array[start] = value;
            length++;
        }
        public void AddLast(T value)
        {
            IncreaseAndInspection();
            array[last] = value;
            length++;
        }
        bool overflow { get { return length == array.Length; } }
        void IncreaseAndInspection()
        {
            if (overflow)
                increase();

        }
        void increase()
        {
            T[] array2 = new T[array.Length * 2];
            for (int i = 0; i < array.Length; i++)
            {
                int pos = (start + i) % array.Length;
                array2[i] = array[pos];
            }
            array = array2;
            start = 0;
            array2 = null;
        }
        public void Clear()
        {
            start = 0; length = 0; array = new T[1];
        }
    }
    class Heap<T>
    {
        Comparison<T> ic;
        List<T> storage = new List<T>();
        public Heap(Comparison<T> ic)
        {
            this.ic = ic;
        }
        public void Add(T element)
        {
            storage.Add(element);
            int pos = storage.Count - 1;
            while (pos != 0 && ic(storage[((int)(pos - 1) >> 1)], element) > 0)
            {
                Swap(storage, pos, ((int)(pos - 1) / 2));
                pos = ((int)(pos - 1) / 2);
            }
        }
        public T Pop()
        {
            T t = storage[0];
            Swap(storage, 0, storage.Count - 1);
            int pos = 0;
            storage.RemoveAt(storage.Count - 1);
            if (Count > 0)
                while (true)
                {
                    T my = storage[pos];
                    if (pos * 2 + 1 >= Count)
                        break;
                    T left = storage[pos * 2 + 1];
                    if (pos * 2 + 2 >= Count)
                    {
                        if (ic(left, my) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        break;
                    }
                    T right = storage[pos * 2 + 2];
                    if (ic(left, my) < 0 || ic(right, my) < 0)
                    {
                        if (ic(left, right) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        else
                        {

                            Swap(storage, pos, pos * 2 + 2);
                            pos = pos * 2 + 2;
                        }
                    }
                    else break;
                }
            return t;
        }

        public void Clear()
        {
            storage.Clear();
        }
        /// <summary>
        /// ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        /// <returns></returns>
        public T Peek()
        {
            return storage[0];
        }
        public int Count
        {
            get { return storage.Count; }
        }
        //void RemoveLast, Size, peeklast, add
    }
    static void Swap<T>(ref T lhs, ref T rhs)
    {
        T temp;
        temp = lhs;
        lhs = rhs;
        rhs = temp;
    }
    static void Swap<T>(T[] a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }
    static void Swap<T>(List<T> a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }

    bool outregion(long y, long x, long n, long m)
    {
        if (x < 0 || x >= m || y < 0 || y >= n)
            return true;
        return false;
    }
    static void initlist<T>(ref List<T>[] list, int n)
    {
        list = new List<T>[n];
        for (int i = 0; i < n; i++)
            list[i] = new List<T>();
    }
    static void newarray<T>(ref T[][] array, int n, int m)
    {
        array = new T[n][];
        for (int i = 0; i < n; i++)
            array[i] = new T[m];
    }
    static void newarray<T>(ref T[] array, int n)
    {
        array = new T[n];
    }
    static void fill<T>(T[] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            array[i] = value;
    }
    static void fill<T>(T[][] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            for (int j = 0; j < array[i].Length; j++)
                array[i][j] = value;
    }
    public bool NextPermutation<T>(T[] b, Comparison<T> ic)
    {
        for (int j = b.Length - 2; j >= 0; j--)
        {
            if (ic(b[j], b[j + 1]) < 0)
            {
                for (int l = b.Length - 1; l >= 0; l--)
                {
                    if (ic(b[l], b[j]) > 0)
                    {
                        Swap(b, j, l);
                        Array.Reverse(b, j + 1, b.Length - (j + 1));
                        return true;
                    }
                }
            }
        }
        return false;
    }
    int[,] step8 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
        {1,1 },
        {-1,1 },
        {-1,-1 },
        {1,-1 },
    };
    int[,] step4 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
    };
    struct Vector2
    {
        public double x;
        public double y;
        public Vector2(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
        public double Dist(Vector2 to)
        {
            return Math.Sqrt(Math.Abs(Math.Pow(to.x - x, 2)) + Math.Abs(Math.Pow(to.y - y, 2)));
        }
        public static bool operator ==(Vector2 left, Vector2 right) { return left.x == right.x && left.y == right.y; }
        public static bool operator !=(Vector2 left, Vector2 right) { return left.x != right.x || left.y != right.y; }
    }
    #endregion
    #endregion

}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

public static class B__
{
    private static void Solve()
    {
        int n = ReadInt();

        int x = 0;
        int y = 0;
        bool valid = true;

        while (n-- > 0)
        {
            int distance = ReadInt();
            string direction = Read();

            if (y == 0 && direction != "South")
            {
                valid = false;
                break;
            }

            if (y == 20000 && direction != "North")
            {
                valid = false;
                break;
            }

            Move(ref x, ref y, distance, direction);

            if (y < 0 || y > 20000)
            {
                valid = false;
                break;
            }
        }

        if (y != 0)
            valid = false;

        Write(valid ? "YES" : "NO");
    }

    private static void Move(ref int x, ref int y, int distance, string direction)
    {
        if (direction == "North")
        {
            y -= distance;
        }
        else if (direction == "South")
        {
            y += distance;
        }
        else if (direction == "East")
        {
            x += distance;
        }
        else if (direction == "West")
        {
            x -= distance;
        }
    }

    #region Main

    private static TextReader reader;
    private static TextWriter writer;
    public static void Main()
    {
#if DEBUG
        //reader = new StreamReader("C:\\Users\\Axel\\Desktop\\input.txt");
        reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            Solve();
            //var thread = new Thread(new B__().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string Read() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{

    public class Helper
    {
        public List<Helper> Helpers { get; set; }
        public string From { get; set; }
        public List<string> To { get; set; }

        public void Load()
        {
            Helpers = new List<Helper>();

            Helper North = new Helper();
            North.From = "North";
            North.To = new List<string>();
            North.To.Add("South_x_+");
            North.To.Add("North_x_-");

            North.To.Add("West_y_+");
            North.To.Add("East_y_-");

            Helpers.Add(North);

            Helper South = new Helper();
            South.From = "South";
            South.To = new List<string>();

            South.To.Add("North_x_-");
            South.To.Add("South_x_+");

            South.To.Add("East_y_-");
            South.To.Add("West_y_+");

            Helpers.Add(South);

            Helper West = new Helper();
            West.From = "West";
            West.To = new List<string>();
            West.To.Add("South_x_+");
            West.To.Add("North_x_-");

            West.To.Add("East_y_-");
            West.To.Add("West_y_+");

            Helpers.Add(West);

            Helper East = new Helper();
            East.From = "East";
            East.To = new List<string>();
            East.To.Add("South_x_+");
            East.To.Add("North_x_-");

            East.To.Add("West_y_+");
            East.To.Add("East_y_-");

            Helpers.Add(East);

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetIntegerInputFromLine();

            List<object> lines = new List<object>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();

                lines.Add(inputs);

            }

            Helper helper = new Helper();
            helper.Load();

            long x = 0;
            long y = 0;

            var CurrentPosition = "North";

            var satisfy = true;

            foreach (var item in lines)
            {
                var inputs = (string[])item;
                var km = Convert.ToInt64(inputs[0]);
                var dir = inputs[1];

                var anyDirection = helper.Helpers.FirstOrDefault(f => f.From == CurrentPosition);

                var toDirection = anyDirection.To.FirstOrDefault(z => z.Split('_')[0] == dir);

                var toDI = toDirection.Split('_');

                if (x == 0)
                {

                    if (toDI[0] != "South")
                    {
                        satisfy = false;
                        break;
                    }

                }

                if (x == 20000)
                {
                    if (toDI[0] != "North")
                    {
                        satisfy = false;
                        break;
                    }
                }

                if (toDirection == null)
                {

                    satisfy = false;
                    break;
                }
                else
                {

                    if (toDI[1] == "x")
                    {
                        if (toDI[2] == "+")
                        {
                            x += km;
                        }
                        else
                        {
                            x -= km;
                        }
                    }
                    else
                    {
                        if (toDI[2] == "+")
                        {
                            y += km;
                        }
                        else
                        {
                            y -= km;
                        }
                    }
                }

                if (x < 0)
                {

                    satisfy = false;
                    break;

                }

                if (x > 20000)
                {

                    satisfy = false;
                    break;

                }

                CurrentPosition = dir;
            }

            if (satisfy && CurrentPosition == "North" && x == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

        public static bool Bfs(Dictionary<string, List<string>> graph, string from, string to)
        {
            Dictionary<string, int> level = new Dictionary<string, int>();
            Dictionary<string, int> visited = new Dictionary<string, int>();

            Queue<string> queue = new Queue<string>();

            queue.Enqueue(from);
            level[from] = 1;
            visited[from] = 1;
            while (queue.Count() > 0)
            {
                string front = queue.Peek();

                if (front == to)
                {
                    return true;
                }

                List<string> values;

                if (graph.TryGetValue(front, out values))
                {

                    foreach (var item in values)
                    {
                        if (!visited.ContainsKey(item))
                        {
                            level[item] = level[front] + 1;
                            visited[item] = 1;
                            queue.Enqueue(item);
                        }
                    }
                }

                queue.Dequeue();

            }

            return false;
        }
        public void InputBfs()
        {
            var input = GetIntegerInputFromLine();

            Dictionary<string, List<string>> graph = new Dictionary<string, List<string>>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();
                AddOrUpdate(graph, inputs[0], inputs[1]);
                AddOrUpdate(graph, inputs[1], inputs[0]);
            }

            var ins = GetStringInputsFromLine();

            var isRoute = Bfs(graph, ins[0], ins[1]);

            if (!isRoute)
            {
                Console.WriteLine("No route");
            }
            else
            {
                Console.WriteLine("route");
            }
        }

        public static IDictionary<TKey, List<TValue>> AddOrUpdate<TKey, TValue>(IDictionary<TKey, List<TValue>> dictionary, TKey key, TValue value)
        {
            List<TValue> values;

            if (dictionary.TryGetValue(key, out values))
            {
                values.Add(value);

                dictionary[key] = values;
            }
            else
            {
                values = new List<TValue>();
                values.Add(value);
                dictionary[key] = values;
            }

            return dictionary;
        }

        static int GetIntegerInputFromLine()
        {
            var input = Convert.ToInt32(Console.ReadLine().Trim());
            return input;
        }

        static int[] GetIntegerInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x.Trim())).ToArray();
            return inputs;
        }

        static long GetLongInputFromLine()
        {
            var input = Convert.ToInt64(Console.ReadLine().Trim());
            return input;
        }

        static long[] GetLongInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x.Trim())).ToArray();
            return inputs;
        }

        static double GetDoubleInputFromLine()
        {
            var input = Convert.ToDouble(Console.ReadLine().Trim());
            return input;
        }

        static double[] GetDoubleInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToDouble(x.Trim())).ToArray();
            return inputs;
        }

        static string GetStringInputFromLine()
        {
            var input = Console.ReadLine();
            return input;
        }

        static string[] GetStringInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ');
            return inputs;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{

    class Program
    {
        static void Main(string[] args)
        {
            var input = GetIntegerInputFromLine();

            List<object> lines = new List<object>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();

                lines.Add(inputs);

            }

            long x = 0;
            long y = 0;

            var CurrentPosition = "North";

            var satisfy = true;

            foreach (var item in lines)
            {
                var inputs = (string[])item;
                var km = Convert.ToInt64(inputs[0]);
                var dir = inputs[1];

                if (x == 0)
                {

                    if (dir != "South")
                    {
                        satisfy = false;
                        break;
                    }

                }

                if (x == 20000)
                {
                    if (dir != "North")
                    {
                        satisfy = false;
                        break;
                    }
                }

                if (dir == "South")
                {

                    x += km;

                }
                else if (dir == "North")
                {

                    x -= km;

                }

                if (x < 0)
                {

                    satisfy = false;
                    break;

                }

                if (x > 20000)
                {

                    satisfy = false;
                    break;

                }

                CurrentPosition = dir;
            }

            if (satisfy && CurrentPosition == "North" && x == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

        public static bool Bfs(Dictionary<string, List<string>> graph, string from, string to)
        {
            Dictionary<string, int> level = new Dictionary<string, int>();
            Dictionary<string, int> visited = new Dictionary<string, int>();

            Queue<string> queue = new Queue<string>();

            queue.Enqueue(from);
            level[from] = 1;
            visited[from] = 1;
            while (queue.Count() > 0)
            {
                string front = queue.Peek();

                if (front == to)
                {
                    return true;
                }

                List<string> values;

                if (graph.TryGetValue(front, out values))
                {

                    foreach (var item in values)
                    {
                        if (!visited.ContainsKey(item))
                        {
                            level[item] = level[front] + 1;
                            visited[item] = 1;
                            queue.Enqueue(item);
                        }
                    }
                }

                queue.Dequeue();

            }

            return false;
        }
        public void InputBfs()
        {
            var input = GetIntegerInputFromLine();

            Dictionary<string, List<string>> graph = new Dictionary<string, List<string>>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();
                AddOrUpdate(graph, inputs[0], inputs[1]);
                AddOrUpdate(graph, inputs[1], inputs[0]);
            }

            var ins = GetStringInputsFromLine();

            var isRoute = Bfs(graph, ins[0], ins[1]);

            if (!isRoute)
            {
                Console.WriteLine("No route");
            }
            else
            {
                Console.WriteLine("route");
            }
        }

        public static IDictionary<TKey, List<TValue>> AddOrUpdate<TKey, TValue>(IDictionary<TKey, List<TValue>> dictionary, TKey key, TValue value)
        {
            List<TValue> values;

            if (dictionary.TryGetValue(key, out values))
            {
                values.Add(value);

                dictionary[key] = values;
            }
            else
            {
                values = new List<TValue>();
                values.Add(value);
                dictionary[key] = values;
            }

            return dictionary;
        }

        static int GetIntegerInputFromLine()
        {
            var input = Convert.ToInt32(Console.ReadLine().Trim());
            return input;
        }

        static int[] GetIntegerInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x.Trim())).ToArray();
            return inputs;
        }

        static long GetLongInputFromLine()
        {
            var input = Convert.ToInt64(Console.ReadLine().Trim());
            return input;
        }

        static long[] GetLongInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x.Trim())).ToArray();
            return inputs;
        }

        static double GetDoubleInputFromLine()
        {
            var input = Convert.ToDouble(Console.ReadLine().Trim());
            return input;
        }

        static double[] GetDoubleInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToDouble(x.Trim())).ToArray();
            return inputs;
        }

        static string GetStringInputFromLine()
        {
            var input = Console.ReadLine();
            return input;
        }

        static string[] GetStringInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ');
            return inputs;
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;

			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		public static Dictionary<long, long> mp = new Dictionary<long, long>();
		public static long Go(long u, long v, long w)
		{
			long ans = 0;
			while (u != v)
				if (u > v)
				{
					if (!mp.ContainsKey(u))
						mp.Add(u, 0);
					ans += mp[u];
					mp[u] += w;
					u /= 2;
				}
				else
				{
					if (!mp.ContainsKey(v))
						mp.Add(v, 0);
					ans += mp[v];
					mp[v] += w;
					v /= 2;
				}
			return ans;
		}

		public static int GetAns(int x, int pow)
		{
			if (pow == 0)
				return 1;
			if (pow % 2 == 1)
				return (GetAns(x, pow - 1) * 8) % 10;
			var t = GetAns(x, pow / 2);
			return (t * t) % 10;
		}

		private static void Main()
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var n = ReadInt();
			var dist = 0;
			for (var i = 0; i < n; ++i)
			{
				var s = ReadString().Split(' ');
				var t = int.Parse(s[0]);
				if (s[1] == "East" || s[1] == "West")
				{
					if (dist == 0 || dist == 20000)
					{
						Console.WriteLine("NO");
						return;
					}
				}
				if (s[1] == "North")
					dist -= t;
				if (s[1] == "South")
					dist += t;
				if (dist < 0 || dist > 20000)
				{
					Console.WriteLine("NO");
					return;
				}
			}
			WriteYesNo(dist == 0);
			Console.ReadLine();
			/*			input.Close();
			output.Close();*/
		}
	}
}

using System;

namespace CSharp
{
    public class _750B
    {
        public static void Main()
        {
            bool valid = true;
            int position = 0;

            for (int n = int.Parse(Console.ReadLine()); n > 0; n--)
            {
                string[] tokens = Console.ReadLine().Split();

                int t = int.Parse(tokens[0]);
                string direction = tokens[1];

                if (position == 0 && direction != "South")
                {
                    valid = false;
                }

                if (position == 20000 && direction != "Norht")
                {
                    valid = false;
                }

                switch (direction)
                {
                    case "South":
                        position += t;
                        break;
                    case "North":
                        position -= t;
                        break;
                }

                if (position < 0 || position > 20000)
                {
                    valid = false;
                }
            }

            valid &= position == 0;

            Console.WriteLine(valid ? "YES" : "NO");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            int p=0;
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int l = Convert.ToInt32(s[0]);
                if ((p == 0 && s[1] != "South") || (p == 20000 && s[1] != "North"))
                {
                    Console.WriteLine("NO");
                    return;
                }
                if (s[1] == "South")
                {
                    p += l;
                }
                else if (s[1] == "North")
                {
                    p -= l;
                }

            }
            if (p != 0) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            bool cond = true;
            int n = Int32.Parse(Console.ReadLine());
            int[] dist = new int[n];
            string[] dir = new string[n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                dist[i] = Int32.Parse(s[0]);
                dir[i] = s[1];
            }
            if (dir[0] != "South")
            {
                cond = false;
                //Console.WriteLine("no1");
            }
            else
            {
                int x = 0;
                for (int i = 0; i < n; i++)
                {
                    if (dir[i] == "South")
                    {
                        x += dist[i];
                        if (dist[i] > 20000)
                            break;
                    }
                    else if (dir[i] == "North")
                    {
                        x -= dist[i];
                        if (dist[i] > 20000)
                            break;
                    }
                    if (x >= 20000)
                    {
                        if ((i < n - 1) && ((dir[i] == "South" && dir[i + 1] != "North") || (dir[i] == "North" && dir[i + 1] != "South")))
                        {
                            cond = false;
                            //Console.WriteLine("no2" + " " + i);
                            break;
                        }
                    }
                    if (x < 0)
                        break;
                }
                if (x != 0)
                    cond = false;
                else
                    cond = true;
            }
            if (cond)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            bool cond = true;
            int n = Int32.Parse(Console.ReadLine());
            int[] dist = new int[n];
            string[] dir = new string[n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                dist[i] = Int32.Parse(s[0]);
                dir[i] = s[1];
            }
            if (dir[0] != "South")
            {
                cond = false;
                //Console.WriteLine("no1");
            }
            else
            {
                int x = 0;
                for (int i = 0; i < n; i++)
                {
                    if (dir[i] == "South")
                        x += dist[i];
                    else if (dir[i] == "North")
                        x -= dist[i];
                    if (x >= 20000)
                    {
                        if ((i < n - 1) && ((dir[i] == "South" && dir[i + 1] != "North") || (dir[i] == "North" && dir[i + 1] != "South")))
                        {
                            cond = false;
                            //Console.WriteLine("no2" + " " + i);
                            break;
                        }
                    }
                }
                if (x != 0)
                    cond = false;
                else
                    cond = true;
            }
            if (cond)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            bool cond = true;
            int n = Int32.Parse(Console.ReadLine());
            int[] dist = new int[n];
            string[] dir = new string[n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                dist[i] = Int32.Parse(s[0]);
                dir[i] = s[1];
            }
            if (dir[0] != "South")
            {
                cond = false;
                //Console.WriteLine("no1");
            }
            else
            {
                int x = 0;
                for (int i = 0; i < n; i++)
                {
                    if (dir[i] == "South")
                    {
                        x += dist[i];
                        if (dist[i] > 20000)
                            break;
                    }
                    else if (dir[i] == "North")
                    {
                        x -= dist[i];
                        if (dist[i] > 20000)
                            break;
                    }
                    if (x >= 20000)
                    {
                        if ((i < n - 1) && ((dir[i] == "South" && dir[i + 1] != "North") || (dir[i] == "North" && dir[i + 1] != "South")))
                        {
                            cond = false;
                            //Console.WriteLine("no2" + " " + i);
                            break;
                        }
                    }
                }
                if (x != 0)
                    cond = false;
                else
                    cond = true;
            }
            if (cond)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            bool cond = true;
            int n = Int32.Parse(Console.ReadLine());
            int[] dist = new int[n];
            string[] dir = new string[n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                dist[i] = Int32.Parse(s[0]);
                dir[i] = s[1];
            }
            if (dir[0] != "South")
            {
                cond = false;
                //Console.WriteLine("no1");
            }
            else
            {
                int x = 0;
                for (int i = 0; i < n; i++)
                {
                    if (dir[i] == "South")
                    {
                        x += dist[i];
                        if (x > 20000 || x < 0)
                            break;
                    }
                    else if (dir[i] == "North")
                    {
                        x -= dist[i];
                        if (x > 20000 || x < 0)
                            break;
                    }
                    if (x >= 20000)
                    {
                        if ((i < n - 1) && ((dir[i] == "South" && dir[i + 1] != "North") || (dir[i] == "North" && dir[i + 1] != "South")))
                        {
                            break;
                        }
                    }
                }
                if (x != 0)
                    cond = false;
                else
                    cond = true;
            }
            if (cond)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class A
    {
      static void Main(string[] args)
      {
         int n = int.Parse(Console.ReadLine());

         string[] s = new string[n];
         int[] values = new int[n];

         for(int i=0;i<n;i++)
         {
            string[] token = Console.ReadLine().Split();
            values[i] = int.Parse(token[0]);
            s[i] = token[1];
         }

         int sum = 0;

         if(s[0]!="South")
         {
            Console.WriteLine("No");
            return;
         }
         string last = "";
         for(int i=0;i<n;i++)
         {
            if(s[i]=="South")
            {
               sum += values[i];
            }
            else if(s[i]=="North"){
               sum -= values[i];
               if(sum<0)
                  break;
            }
            if(i<s.Length-1)
            {
               if(sum==0&&s[i+1]!="South")
               {
                  sum = 1;
                  break;
               }else if(sum==20000&&s[i+1]!="North")
               {
                  sum = 1;
                  break;
               }
            }
         }

         if(sum==0)
         {
            Console.WriteLine("Yes");
         }
         else{
            Console.WriteLine("No");
         }
      }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class A
    {
      static void Main(string[] args)
      {
         int n = int.Parse(Console.ReadLine());

         string[] s = new string[n];
         int[] values = new int[n];

         for(int i=0;i<n;i++)
         {
            string[] token = Console.ReadLine().Split();
            values[i] = int.Parse(token[0]);
            s[i] = token[1];
         }

         int sum = 0;

         if(s[0]!="South")
         {
            Console.WriteLine("No");
            return;
         }
         string last = "";
         for(int i=0;i<n;i++)
         {
            if(values[i]>20000)
            {
               sum =1;
               break;
            }
            if(s[i]=="South")
            {
               sum += values[i];
            }
            else if(s[i]=="North"){
               sum -= values[i];
               if(sum<0)
                  break;
            }
            if(i<s.Length-1)
            {
               if(sum==0&&s[i+1]!="South")
               {
                  sum = 1;
                  break;
               }else if(sum==20000&&s[i+1]!="North")
               {
                  sum = 1;
                  break;
               }
            }
         }

         if(sum==0)
         {
            Console.WriteLine("Yes");
         }
         else{
            Console.WriteLine("No");
         }
      }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class A
    {
      static void Main(string[] args)
      {
         int n = int.Parse(Console.ReadLine());

         string[] s = new string[n];
         int[] values = new int[n];

         for(int i=0;i<n;i++)
         {
            string[] token = Console.ReadLine().Split();
            values[i] = int.Parse(token[0]);
            s[i] = token[1];
         }

         int sum = 0;

         if(s[0]!="South")
         {
            Console.WriteLine("No");
            return;
         }
         string last = "";
         for(int i=0;i<n;i++)
         {
            if(values[i]>20000)
            {
               if(s[i]=="North"||s[i]=="South"){
               sum =1;
               break;}
            }
            if(s[i]=="South")
            {
               sum += values[i];
            }
            else if(s[i]=="North"){
               sum -= values[i];
               if(sum<0)
                  break;
            }
            if(i<s.Length-1)
            {
               if(sum==0&&s[i+1]!="South")
               {
                  sum = 1;
                  break;
               }else if(sum==20000&&s[i+1]!="North")
               {
                  sum = 1;
                  break;
               }
            }
         }

         if(sum==0)
         {
            Console.WriteLine("Yes");
         }
         else{
            Console.WriteLine("No");
         }
      }

    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NSproul //B
{
    class Program
    {
        static void Main()
        {
			int n = Int32.Parse(Console.ReadLine());
			int[] dir = new int[n];
			int sum = 0;
			string ret = "NO";

			for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split();
				if (temp[1] == "South") {
					dir[i] = Int32.Parse(temp[0]);
					sum += dir[i];
				}
				else if (temp[1] == "North") {
					dir[i] -= Int32.Parse(temp[0]);
					sum += dir[i];
				}

				Console.WriteLine(sum);
				if (sum < 0 || sum > 20000) {
					break;
				}
            }

            if (sum == 0) ret = "YES";
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NSproul //B
{
    class Program
    {
        static void Main()
        {
			int n = Int32.Parse(Console.ReadLine());
			int[] dir = new int[n];
			int sum = 0;
			string ret = "NO";
			bool ret2 = true;

			for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split();
				if (temp[1] == "South") {
					dir[i] = Int32.Parse(temp[0]);
					sum += dir[i];
				}
				else if (temp[1] == "North") {
					dir[i] -= Int32.Parse(temp[0]);
					sum += dir[i];
				}
				else if ((temp[1] == "East" || temp[1] == "West") && (sum == 0 || sum == 20000)) {
					break;
					ret2 = false;
				}

				//Console.WriteLine(sum);
				if (sum < 0 || sum > 20000) {
					break;
				}
            }

            if (sum == 0 && ret2) ret = "YES";
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NSproul //B
{
    class Program
    {
        static void Main()
        {
			int n = Int32.Parse(Console.ReadLine());
			int sum = 0;
			string ret = "NO";
			bool ret2 = true;

			for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split();
				if (temp[1] == "South") {
					sum += Int32.Parse(temp[0]);
				}
				else if (temp[1] == "North") {
					sum -= Int32.Parse(temp[0]);
				}
				else if (sum == 0 || sum == 20000) {
					break;
					ret2 = false;
				}

				//Console.WriteLine(sum);
				if (sum < 0 || sum > 20000) {
					break;
				}
            }

            if (sum == 0 && ret2) ret = "YES";
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NSproul //B
{
    class Program
    {
        static void Main()
        {
			int n = Int32.Parse(Console.ReadLine());
			int[] dir = new int[n];
			int sum = 0;
			string ret = "NO";

			for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split();
				if (temp[1] == "South") {
					dir[i] = Int32.Parse(temp[0]);
					sum += dir[i];
				}
				else if (temp[1] == "North") {
					dir[i] -= Int32.Parse(temp[0]);
					sum += dir[i];
				}

				if (sum < 0 || sum >= 20000) {
					break;
				}
            }

            if (sum == 0) ret = "YES";
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NSproul //B
{
    class Program
    {
        static void Main()
        {
			int n = Int32.Parse(Console.ReadLine());
			int[] dir = new int[n];
			int sum = 0;
			string ret = "NO";

			for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split();
				if (temp[1] == "South") {
					dir[i] = Int32.Parse(temp[0]);
					sum += dir[i];
				}
				else if (temp[1] == "North") {
					dir[i] -= Int32.Parse(temp[0]);
					sum += dir[i];
				}

				//Console.WriteLine(sum);
				if (sum < 0 || sum > 20000) {
					break;
				}
            }

            if (sum == 0) ret = "YES";
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NSproul //B
{
    class Program
    {
        static void Main()
        {
			int n = Int32.Parse(Console.ReadLine());
			int[] dir = new int[n];
			int sum = 0;
			string ret = "NO";

			for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split();
				if (temp[1] == "South") {
					dir[i] = Int32.Parse(temp[0]);
					sum += dir[i];
				}
				else if (temp[1] == "North") {
					dir[i] -= Int32.Parse(temp[0]);
					sum += dir[i];
				}

				if (sum < 0 || sum > 20000) {
					break;
				}
            }

            if (sum == 0) ret = "YES";
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;

namespace CP_CS
{

    class Task
    {

        static void Solve()
        {
            int n = ReadInt();
            int vert = 0;
            for (int i = 0; i < n; i++)
            {
                int dl = ReadInt();
                string dir = ReadToken();
                if (vert == 0)
                {
                    if (dir != "South")
                    {
                        Write("NO");
                        return;
                    }
                }
                if (vert == 20000)
                {
                    if (dir != "North")
                    {
                        Write("NO");
                        return;
                    }
                }
                if (dir == "North")
                {
                    vert -= dl;
                }
                if (dir == "South")
                {
                    vert += dl;
                }
            }
            if (vert == 0)
            {
                Write("YES");
            }
            else
            {
                Write("NO");
            }
        }

        public static double Rast(int[] xy1, int[] xy2)
        {
            return Math.Sqrt(Math.Pow(xy1[0] - xy2[0], 2) + Math.Pow(xy1[1] - xy2[1], 2));
        }

        static string[] Split(string str, int chunkSize)
        {
            return Enumerable.Range(0, str.Length / chunkSize)
                .Select(i => str.Substring(i * chunkSize, chunkSize)).ToArray();
        }

        #region -- Main --

        private static TextReader reader;
        private static TextWriter writer;

        static void Main()
        {
#if DEBUG
            //reader = new StreamReader("..\\..\\input.txt");
            reader = new StreamReader(Console.OpenStandardInput());
            writer = Console.Out;
            //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("pluses.in");
        //writer = new StreamWriter("pluses.out");
#endif
            try
            {
                //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
                //thread.Start();
                //thread.Join();
                Solve();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
            }
            reader.Close();
            writer.Close();
        }

        #endregion
        #region -- Read / Write --

        private static Queue<string> currentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string[] ReadAndSplitLine(char divisor)
        {
            return reader.ReadLine().Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine());
            return currentLineTokens.Dequeue();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        //public static BigInteger ReadBigInteger()
        //{
        //    return BigInteger.Parse(ReadToken());
        //}

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static bool[] ReadBoolArray()
        {
            return ReadAndSplitLine().ToString().ToCharArray().Select(chr => chr == '1').ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray();
            return matrix;
        }

        public static bool[][] ReadBoolMatrix(int numberOfRows)
        {
            bool[][] matrix = new bool[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadBoolArray();
            return matrix;
        }

        public static bool[][] TransposeBoolMatrix(bool[][] array, int numberOfRows)
        {
            bool[][] matrix = array;
            bool[][] ret = new bool[matrix[0].Length][];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = new bool[numberOfRows];
                for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];
            }
            return ret;
        }

        public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
        {
            int[][] matrix = ReadIntMatrix(numberOfRows);
            int[][] ret = new int[matrix[0].Length][];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = new int[numberOfRows];
                for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];
            }
            return ret;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            writer.WriteLine(string.Join(" ", array));
        }

        public static void Write(params object[] array)
        {
            WriteArray(array);
        }
        public static void WriteLines<T>(IEnumerable<T> array)
        {
            foreach (var a in array) writer.WriteLine(a);
        }
        private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
        {
            public new TValue this[TKey key]
            {
                get { return ContainsKey(key) ? base[key] : default(TValue); }
                set { base[key] = value; }
            }
        }
        private static T[] Init<T>(int size) where T : new()
        {
            var ret = new T[size];
            for (int i = 0; i < size; i++) ret[i] = new T();
            return ret;
        }
        #endregion
    }
}

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            private bool Calc()
            {
                var n = int.Parse(Console.ReadLine());
                int now = 0;
                int MAX = 20000;
                for (int i = 0; i < n; i++)
                {
                    var s = Console.ReadLine().Split(' ');
                    int d = int.Parse(s[0]);
                    string v = s[1];
                    if (v == "North")
                    {
                        now -= d;
                        if (now < 0) return false;
                    }
                    else if (v == "South")
                    {
                        now += d;
                        if (now > MAX) return false;
                    }
                    //else
                    //{
                    //    if (now <= 0 || now >= MAX) return false;
                    //}

                }
                return now == 0;
            }

            private void Solve()
            {

                if (Calc()) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                //Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            private void Solve()
            {
                var n = int.Parse(Console.ReadLine());
                bool isNorth = true;
                bool isSouth = false;
                int y = 0;
                bool ans = false;
                for (int i = 0; i < n; i++)
                {
                    var s = Console.ReadLine().Split(' ');
                    string dir = s[1];
                    int coords = int.Parse(s[0]);
                    if (isNorth)
                    {
                        if (dir != "South")
                        {
                            //ans = false;
                            Console.WriteLine("NO");
                            return;
                        }
                    }
                    else if (isSouth)
                    {
                        if (dir != "North")
                        {
                            //ans = false;
                            Console.WriteLine("NO");
                            return;
                        }
                    }
                    if (dir == "North")
                    {
                        y += (coords % 40000);
                        y = y%40000;
                    }

                    else if (dir == "South")
                    {
                        y -= (coords % 40000);
                        y = y%40000;
                    }

                    if (y == 0)
                        isNorth = true;
                    else
                    {
                        isNorth = false;
                    }
                    if (y == -20000)
                        isSouth = true;
                    else
                    {
                        isSouth = false;
                    }
                }

                ans = y == 0;
                if(ans)
                    Console.WriteLine("YES");
                else
                {
                    Console.WriteLine("NO");
                }
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                //Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            private void Solve()
            {
                var n = int.Parse(Console.ReadLine());
                bool isNorth = true;
                bool isSouth = false;
                int y = 0;
                bool ans = false;
                for (int i = 0; i < n; i++)
                {
                    var s = Console.ReadLine().Split(' ');
                    string dir = s[1];
                    int coords = int.Parse(s[0]);
                    if (isNorth)
                    {
                        if (dir != "South")
                        {
                            ans = false;
                            Console.WriteLine("NO");
                            return;
                        }
                    }
                    else if (isSouth)
                    {
                        if (dir != "North")
                        {
                            ans = false;
                            Console.WriteLine("NO");
                            return;
                        }
                    }
                    if (dir == "North")
                        y += coords;
                    else if (dir == "South")
                        y -= coords;
                    if (y == 0)
                        isNorth = true;
                    else
                    {
                        isNorth = false;
                    }
                    if (y == -20000)
                        isSouth = true;
                    else
                    {
                        isSouth = false;
                    }
                }

                ans = y == 0;
                if(ans)
                    Console.WriteLine("YES");
                else
                {
                    Console.WriteLine("NO");
                }
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                //Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            private void Solve()
            {
                var n = int.Parse(Console.ReadLine());
                bool isNorth = true;
                bool isSouth = false;
                int y = 0;
                bool ans = false;
                for (int i = 0; i < n; i++)
                {
                    var s = Console.ReadLine().Split(' ');
                    string dir = s[1];
                    int coords = int.Parse(s[0]);
                    if (isNorth)
                    {
                        if (dir != "South")
                        {
                            ans = false;
                            break;
                        }
                    }
                    else if (isSouth)
                    {
                        if (dir != "North")
                        {
                            ans = false;
                            break;
                        }
                    }
                    if (dir == "North")
                        y += coords;
                    else if (dir == "South")
                        y -= coords;
                    if (y == 0)
                        isNorth = true;
                    else
                    {
                        isNorth = false;
                    }
                    if (y == 20000)
                        isSouth = true;
                    else
                    {
                        isSouth = false;
                    }
                }

                ans = y == 0;
                if(ans)
                    Console.WriteLine("YES");
                else
                {
                    Console.WriteLine("NO");
                }
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                //Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }

using System;

namespace Self
{
    class Program
    {
        static void Main(string[] args)
        {
            int MovAmm = int.Parse(Console.ReadLine());
            int VertPos = 0;
            bool Check = true;
            string[] MovData = new string[MovAmm];
            for (int i = 0; i < MovAmm; i++)
            {
                MovData[i] = Console.ReadLine();
            }

            string[] tempArray;
            int tempLength = 0;
            string tempDirect = null;
            for (int i = 0; i < MovAmm; i++)
            {
                tempArray = MovData[i].Split(' ');
                tempLength = int.Parse(tempArray[0]);
                tempDirect = tempArray[1];

                if (VertPos == 0)
                {
                    if ((tempDirect == "East") || (tempDirect == "West") || (tempDirect == "North"))
                    {
                        Check = false;
                        break;
                    }
                    else
                    {
                        VertPos += tempLength;
                    }
                }
                else if (VertPos == 20000)
                {
                    if ((tempDirect == "East") || (tempDirect == "West") || (tempDirect == "South"))
                    {
                        Check = false;
                        break;
                    }
                    else
                    {
                        VertPos -= tempLength;
                    }
                }
                else
                {
                    if (tempDirect == "North")
                    {
                        if(VertPos < tempLength)
                        {
                            Check = false;
                            break;
                        }
                        else
                        {
                            VertPos -= tempLength;
                        }
                    }
                    if (tempDirect == "South")
                    {
                        if (VertPos+tempLength > 20000)
                        {
                            Check = false;
                            break;
                        }
                        else
                        {
                            VertPos += tempLength;
                        }
                    }
                }//конец ветвления на проверку корректности направления
            }//конец фора
            if (Check)
            {
                if(VertPos == 0)
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
            }
            else
                Console.WriteLine("NO");
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n;

        public void Solve()
        {
            n = ioHelper.ReadNextInt();

            int curNS = 0;
            int curEV = 0;

            bool bOK = true;

            while(n>0)
            {
                var dist = ioHelper.ReadNextInt();
                var dir = ioHelper.ReadNextToken();

                if(dir=="North")
                {
                    if (curNS == 0)
                        curNS = -1;
                    else
                        curNS -= dist;
                    if(curNS<0)
                    {
                        bOK = false;
                        break;
                    }
                }
                else if (dir=="South")
                {
                    if (curNS == 20000)
                        curNS++;
                    else
                        curNS += dist;
                    if(curNS>20000)
                    {
                        bOK = false;
                        break;
                    }
                }
                n--;
            }

            if (curNS != 0)
                bOK = false;

            if (bOK)
                ioHelper.WriteLine("YES");
            else
                ioHelper.WriteLine("NO");
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}

//750B New Year and North Pole

using System;
class _750B
{
	static void Main()
	{
		int n=int.Parse(Console.ReadLine());
		int[] lens=new int[n];
		string[] dirs=new string[n];
		for(int i=0;i<n;i++)
		{
			string[] lendir=Console.ReadLine().Split();
			lens[i]=int.Parse(lendir[0]);
			dirs[i]=lendir[1];
		}

		int sum;
		sum=(dirs[0]=="South")?0:20000;
		for(int i=0;i<n;i++)
		{
			if(sum<0 || sum>20000)
				break;
			else if(sum==0)
				sum+=lens[i];
			else if(sum==20000)
				sum-=lens[i];
			else
				if(dirs[i]=="South")
					sum+=lens[i];
				else if(dirs[i]=="North")
					sum-=lens[i];
		}
		Console.Write((sum==0)?"YES":"NO");
	}
}

//750B New Year and North Pole

using System;
class _750B
{
	static void Main()
	{
		int n=int.Parse(Console.ReadLine());
		int[] lens=new int[n];
		string[] dirs=new string[n];
		for(int i=0;i<n;i++)
		{
			string[] lendir=Console.ReadLine().Split();
			lens[i]=int.Parse(lendir[0]);
			dirs[i]=lendir[1];
		}

		int sum;
		sum=(dirs[0]=="South")?0:20000;
		for(int i=0;i<n;i++)
			if(sum==0)
				sum+=lens[i];
			else if(sum==20000)
				sum-=lens[i];
			else
				if(dirs[i]=="South")
					sum+=lens[i];
				else if(dirs[i]=="North")
					sum-=lens[i];
		Console.Write((sum==0)?"YES":"NO");
	}
}

using System;
using System.IO;
using System.Text;

namespace New_Year_and_North_Pole
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var t = new int[n];
            var dir = new int[n];
            for (int i = 0; i < n; i++)
            {
                t[i] = Next();
                dir[i] = Next();
            }

            int d = 0;

            for (int i = 0; i < n; i++)
            {
                d += t[i]*dir[i];
                if (d < 0 || d > 20000)
                {
                    writer.WriteLine("NO");
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine(d == 0 ? "YES" : "NO");
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == 'N')
                    return -1;
                if (c == 'E')
                    return 0;
                if (c == 'W')
                    return 0;
                if (c == 'S')
                    return 1;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace New_Year_and_North_Pole
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var t = new int[n];
            var dir = new int[n];
            for (int i = 0; i < n; i++)
            {
                t[i] = Next();
                dir[i] = Next();
            }

            int d = 0;

            for (int i = 0; i < n; i++)
            {
                d += t[i]*dir[i];
                if (d < 0 || d > 40000)
                {
                    writer.WriteLine("NO");
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine(d == 0 ? "YES" : "NO");
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == 'N')
                    return -1;
                if (c == 'E')
                    return 0;
                if (c == 'W')
                    return 0;
                if (c == 'S')
                    return 1;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay = false;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }

                if (directionToSouth < 0)
                {
                    rightWay = false;
                    break;
                }

                rightWay = directionToSouth == 0 ? true : false;
            }

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    directionToSouth = directionToSouth - steps[i];
                }
            }

            rightWay = directionToSouth == 0 ? true : false;

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }
            }

            rightWay = directionToSouth == 0 ? true : false;

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay = false;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }

                if (directionToSouth < 0 || toSouth > 20000)
                {
                    rightWay = false;
                    break;
                }

                rightWay = directionToSouth == 0 ? true : false;
            }

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay = false;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }

                rightWay = directionToSouth == 0 ? true : false;
            }

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay = false;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directionToSouth == 0 && directions[i+1] != "South")
                {
                    rightWay = false;
                    break;
                }
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }

                if (directionToSouth < 0 || directionToSouth > 20000)
                {
                    rightWay = false;
                    break;
                }

                rightWay = directionToSouth == 0 ? true : false;
            }

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay = false;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }

                if (directionToSouth < 0 || directionToSouth > 20000)
                {
                    rightWay = false;
                    break;
                }

                rightWay = directionToSouth == 0 ? true : false;
            }

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay = false;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    if (steps[i] > 20000)
                    {
                        rightWay = false;
                        break;
                    }
                    directionToSouth = directionToSouth - steps[i];
                }

                if (directionToSouth < 0)
                {
                    rightWay = false;
                    break;
                }

                rightWay = directionToSouth == 0 ? true : false;
            }

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);

        }
    }
}

using System;
using System.Collections.Generic;

namespace New_Year_and_North_Pole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> inputs = new List<string>();
            List<int> steps = new List<int>();
            List<string> directions = new List<string>();
            string[] tempString = new string[2];
            int directionToSouth = 0;
            bool rightWay;
            bool fromSouth = true;
            int toSouth = 0;

            for (int i = 0; i < n; i++)
            {
                inputs.Add(Console.ReadLine());
                tempString = inputs[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                steps.Add(Convert.ToInt32(tempString[0]));
                directions.Add(tempString[1]);
            }

            for (int i = 0; i < n; i++)
            {
                if (directions[i] == "South")
                {
                    directionToSouth = directionToSouth + steps[i];
                    toSouth = toSouth + steps[i];
                    if (i != n - 1)
                    {
                        if (toSouth == 20000 && directions[i + 1] != "North")
                        {
                            fromSouth = false;
                            break;
                        }
                    }
                }
                if (directions[i] == "North")
                {
                    directionToSouth = directionToSouth - steps[i];
                }
            }

            rightWay = directionToSouth == 0 ? true : false;

            if (directions[0] != "South")
            {
                rightWay = false;
            }

            if (fromSouth == false)
            {
                rightWay = false;
            }

            if (toSouth > 20000)
            {
                rightWay = false;
            }

            string message = rightWay ? "YES" : "NO";
            Console.Write(message);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problem750B
{
    class Program
    {
        static string Solve(int n)
        {
            int latitude = 0;

            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine().Split(' ');
                int d = int.Parse(s[0]);
                switch (s[1])
                {
                    case "South":
                        if (latitude == 20000)
                            return "NO";
                        latitude += d;
                        if (latitude < 0)
                            return "NO";

                        break;
                    case "North":
                        if (latitude == 0)
                            return "NO";
                        else
                            latitude -= d;
                        if (latitude > 20000)
                            return "NO";

                        break;
                    default:
                        if (latitude == 0 || latitude == 20000)
                            return "NO";
                        break;
                }
            }

            return latitude == 0 ? "YES" : "NO";
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(Solve(n));
        }
    }
}

using System;
using System.Collections.Generic;

namespace CF_750B
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int length = 0, ts= 0, tn = 0, sc = 0, nc = 0, row_no;
			string direction, last_direction="North";
			string[] journey;
			string res="NO";
			bool valid = false;
			int n = Int32.Parse (Console.ReadLine ());

			List<string> ls = new List<string> ();
			for (int a = 0; a < n; a++)
			{
				ls.Add (Console.ReadLine ());
			}

//			foreach (var _ls in ls) {
//				Console.WriteLine(_ls);
//			}

			foreach (string row in ls)
			{
				row_no = ls.IndexOf (row);
				if (row_no == 0) {
					last_direction = "North";
				}

				journey = row.Split (' ');

				length= Int32.Parse(journey [0]);
				direction = journey [1];

				valid = is_the_move_legal (n, row_no, last_direction, direction);
//				Console.WriteLine ("=== VALIDITY: {0}", valid);

				if (!valid) {
					break;
				}

				if (direction == "North") {
					if (length > 20000 || tn+length > 20000 ) {
						break;
					}
					tn += length;
//					Console.WriteLine ("Toward_North: {0}", tn);
					if (tn == 20000) {
						last_direction = "North";
					} else {
						last_direction = "Ignore";
					}
				}
				else if (direction == "South") {
					if (length > 20000 || ts+length > 20000 ) {
						break;
					}
					ts += length;
//					Console.WriteLine ("Toward_South: {0}", ts);
					if (ts == 20000) {
						last_direction = "South";
					} else {
						last_direction = "Ignore";
					}
				}

				if (ls.IndexOf (row) == n - 1 && tn >=1 && ts >= 1 && ts == tn) {
					res = "YES";
				}
			}
			Console.WriteLine (res);

		}

		private static bool is_the_move_legal(int n, int _row_no, string last_direction, string direction)
		{
//			Console.WriteLine ("Last_Direction: {0}", last_direction);
//			Console.WriteLine ("Current_Direction: {0}", direction);

			if (_row_no == 0 && direction != "South")
			{
				return false;
			}

			if (_row_no == n - 1 && direction != "North")
			{
				return false;
			}

			if (last_direction == "South" && direction != "North") {
				return false;
			}

			if (last_direction == "North" && direction != "South") {
				return false;
			}

			return true;
		}

	}
}

using System;
using System.Collections.Generic;

namespace CF_750B
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int length = 0, ts= 0, tn = 0;
			string direction, last_direction = "North";
			string[] journey;
			string res="NO";

			int n = Int32.Parse (Console.ReadLine ());

			List<string> ls = new List<string> ();
			for (int a = 0; a < n; a++)
			{
				ls.Add (Console.ReadLine ());
			}

//			foreach (var _ls in ls) {
//				Console.WriteLine(_ls);
//			}

			foreach (string row in ls)
			{
				journey = row.Split (' ');

				length= Int32.Parse(journey [0]);
				direction = journey [1];

				if (ls.IndexOf (row) == n - 1 && direction != "North")
				{
					break;
				}

				if (last_direction == "South" && direction == "North") {
					tn += length;
					if (tn == 20000) {
						last_direction = "North";
					} else {
						last_direction = "Ignore";
					}
					continue;
				}
				else if (last_direction == "North" && direction == "South")
				{
					ts += length;
					if (ts == 20000) {
						last_direction = "South";
					} else {
						last_direction = "Ignore";
					}
					continue;
				}

				else if (last_direction == "Ignore" && direction == "North") {
					tn += length;
					if (tn == 20000) {
						last_direction = "North";
					} else {
						last_direction = "Ignore";
					}
				}
				else if (last_direction == "Ignore" && direction == "South") {
					ts += length;
					if (ts == 20000) {
						last_direction = "South";
					} else {
						last_direction = "Ignore";
					}
				}

				if (ls.IndexOf (row) == n - 1 && ts == tn) {
					res = "YES";
				}
			}
			Console.WriteLine (res);
		}

	}
}

using System;
using System.Collections.Generic;

namespace CF_750B
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int length = 0, ts= 0, tn = 0, sc = 0, nc = 0, row_no;
			string direction, last_direction="North";
			string[] journey;
			string res="NO";
			bool valid = false;
			int n = Int32.Parse (Console.ReadLine ());

			List<string> ls = new List<string> ();
			for (int a = 0; a < n; a++)
			{
				ls.Add (Console.ReadLine ());
			}

//			foreach (var _ls in ls) {
//				Console.WriteLine(_ls);
//			}

			foreach (string row in ls)
			{
				row_no = ls.IndexOf (row);
				if (row_no == 0) {
					last_direction = "North";
				}

				journey = row.Split (' ');

				length= Int32.Parse(journey [0]);
				direction = journey [1];

				valid = is_the_move_legal (n, row_no, last_direction, direction);
//				Console.WriteLine ("=== VALIDITY: {0}", valid);

				if (!valid) {
					break;
				}

				if (direction == "North") {
					if (length > 20000) {
						break;
					}
					tn += length;
//					Console.WriteLine ("Toward_North: {0}", tn);
					if (tn == 20000) {
						last_direction = "North";
					} else {
						last_direction = "Ignore";
					}
				}
				else if (direction == "South") {
					if (length > 20000) {
						break;
					}
					ts += length;
//					Console.WriteLine ("Toward_South: {0}", ts);
					if (ts == 20000) {
						last_direction = "South";
					} else {
						last_direction = "Ignore";
					}
				}

				if (ls.IndexOf (row) == n - 1 && tn >=1 && ts >= 1 && ts == tn) {
					res = "YES";
				}
			}
			Console.WriteLine (res);

		}

		private static bool is_the_move_legal(int n, int _row_no, string last_direction, string direction)
		{
//			Console.WriteLine ("Last_Direction: {0}", last_direction);
//			Console.WriteLine ("Current_Direction: {0}", direction);

			if (_row_no == 0 && direction != "South")
			{
				return false;
			}

			if (_row_no == n - 1 && direction != "North")
			{
				return false;
			}

			if (last_direction == "South" && direction != "North") {
				return false;
			}

			if (last_direction == "North" && direction != "South") {
				return false;
			}

			return true;
		}

	}
}

using System;
using System.Collections.Generic;

namespace CF_750B
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int length = 0, ts= 0, tn = 0;
			string direction, last_direction = "North";
			string[] journey;
			string res="NO";

			int n = Int32.Parse (Console.ReadLine ());

			List<string> ls = new List<string> ();
			for (int a = 0; a < n; a++)
			{
				ls.Add (Console.ReadLine ());
			}

//			foreach (var _ls in ls) {
//				Console.WriteLine(_ls);
//			}

			foreach (string row in ls)
			{
				journey = row.Split (' ');

				length= Int32.Parse(journey [0]);
				direction = journey [1];

				if (ls.IndexOf (row) == n - 1 && direction != "North")
				{
					break;
				}

				if (last_direction == "South" && direction == "North") {
					if (length > 20000) {
						break;
					}
					tn += length;
					if (tn == 20000) {
						last_direction = "North";
					} else {
						last_direction = "Ignore";
					}
					continue;
				}
				else if (last_direction == "North" && direction == "South")
				{
					if (length > 20000) {
						break;
					}
					ts += length;
					if (ts == 20000) {
						last_direction = "South";
					} else {
						last_direction = "Ignore";
					}
					continue;
				}

				else if (last_direction == "Ignore" && direction == "North") {
					if (length > 20000) {
						break;
					}
					tn += length;
					if (tn == 20000) {
						last_direction = "North";
					} else {
						last_direction = "Ignore";
					}
				}
				else if (last_direction == "Ignore" && direction == "South") {
					if (length > 20000) {
						break;
					}
					ts += length;
					if (ts == 20000) {
						last_direction = "South";
					} else {
						last_direction = "Ignore";
					}
				}

				if (ls.IndexOf (row) == n - 1 && ts == tn) {
					res = "YES";
				}
			}
			Console.WriteLine (res);
		}

	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf750_02
{
    const int intSizeLine = 20000;
    const string SOUTH = "S";
    const string NORTH = "N";

    static bool violation = false;
    static int y;

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        y = 0;

        for (int i = 0; i < n; i++)
        {
            string strInfo = Console.ReadLine();
            int intSize = int.Parse(strInfo.Split()[0]);
            string strDirection = strInfo.Split()[1].Substring(0, 1);

            if (y == 0)
            {
                y = GetY(intSize, SOUTH);
            }
            else if (y == intSizeLine)
            {
                y = GetY(intSize, NORTH);
            }
            else if (strDirection == SOUTH)
            {
                y = GetY(intSize, SOUTH);
            }
            else if (strDirection == NORTH)
            {
                y = GetY(intSize, NORTH);
            }
        }

        if (y == 0 && !violation )
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }

    }

    public static int GetY(int intValue, string strDirection)
    {
        int intResult = 0;

        switch (strDirection)
        {
            case NORTH:
                if (y - intValue < 0)
                {
                    violation = true;
                    return intResult;
                }
                else
                {
                    intResult = y - intValue;
                }
                break;

            case SOUTH:
                if (intValue + y > intSizeLine)
                {
                    violation = true;
                    return intResult;
                }
                else
                {
                    intResult = y + intValue;
                }
                break;
        }

        return intResult;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf002
{
    const int intSizeLine = 20000;
    const int intSizeLine2 = 40000;
    const string SOUTH = "S";
    const string NORTH = "N";

    static int y;

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        y = 0;

        for (int i = 0; i < n; i++)
        {
            string strInfo = Console.ReadLine();
            int intSize = int.Parse(strInfo.Split()[0]);
            string strDirection = strInfo.Split()[1].Substring(0, 1);

            if (y == 0)
            {
                y = GetY(intSize, SOUTH);
            }
            else if(y == intSizeLine)
            {
                y = GetY(intSize, NORTH);
            }
            else if (strDirection == SOUTH)
            {
                y = GetY(intSize, SOUTH);
            }
            else if (strDirection == NORTH)
            {
                y = GetY(intSize, NORTH);
            }
        }

        if (y==0)
        {
            Console.WriteLine("YES");
        }else
        {
            Console.WriteLine("NO");
        }

    }

    public static int GetY(int intValue, string strDirection)
    {
        int intResult = 0;
        int intLeft = 0;

        if (intValue >= intSizeLine2)
        {
            intValue -= (intValue / intSizeLine2) * intSizeLine2;
        }

        switch (strDirection)
        {
            case NORTH:
                if (y-intValue<0)
                {
                    intLeft = y;
                    intValue -= intLeft;
                    if (intValue > intSizeLine)
                    {
                        intValue -= intSizeLine;
                        intResult = GetY(intValue, NORTH);
                    }
                    else
                    {
                        intResult = intValue;
                    }
                }
                else
                {
                    intResult = y - intValue;
                }

                break;

            case SOUTH:
                if (intValue+y>intSizeLine)
                {
                    intLeft = intSizeLine - y;
                    intValue -= intLeft;
                    if (intValue > intSizeLine)
                    {
                        intValue -= intSizeLine;
                        intResult = GetY(intValue, SOUTH);
                    }
                    else
                    {
                        intResult = intSizeLine - intValue;
                    }
                }else
                {
                    intResult = y + intValue;
                }
                break;
        }

        return intResult;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf001
{
    const int intSizeLine = 20000;
    const int intSizeLine2 = 40000;
    const string SOUTH = "S";
    const string NORTH = "N";

    static int y;

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        y = 0;

        for (int i = 0; i < n; i++)
        {
            string strInfo = Console.ReadLine();
            int intSize = int.Parse(strInfo.Split()[0]);
            string strDirection = strInfo.Split()[1].Substring(0, 1);

            if (y == 0)
            {
                y = GetY(intSize, SOUTH);
            }
            else if(y == intSizeLine)
            {
                y = GetY(intSize, NORTH);
            }
            else if (strDirection == SOUTH)
            {
                y = GetY(intSize, SOUTH);
            }
            else if (strDirection == NORTH)
            {
                y = GetY(intSize, NORTH);
            }
        }

        if (y==0)
        {
            Console.WriteLine("YES");
        }else
        {
            Console.WriteLine("NO");
        }

    }

    public static int GetY(int intValue, string strDirection)
    {
        int intResult = 0;
        int intLeft = 0;

        if (intValue >= intSizeLine2)
        {
            intValue -= (intValue / intSizeLine2) * intSizeLine2;
        }

        switch (strDirection)
        {
            case NORTH:
                if (y-intValue<0)
                {
                    intLeft = y;
                    intValue -= intLeft;
                    if (intValue > intSizeLine)
                    {
                        intValue -= intSizeLine;
                        intResult = GetY(intValue, NORTH);
                    }
                    else
                    {
                        intResult = intValue;
                    }
                }
                else
                {
                    intResult = y - intValue;
                }

                break;

            case SOUTH:
                if (intValue+y>intSizeLine)
                {
                    intLeft = intSizeLine - y;
                    intValue -= intLeft;
                    if (intValue > intSizeLine)
                    {
                        intValue -= intSizeLine;
                        intResult = GetY(intValue, SOUTH);
                    }
                    else
                    {
                        intResult = intSizeLine - intValue;
                    }
                }else
                {
                    intResult = y + intValue;
                }
                break;
        }

        return intResult;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf750_02
{
    const int intSizeLine = 20000;
    const string SOUTH = "S";
    const string NORTH = "N";

    static bool violation = false;
    static int y;

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        y = 0;

        for (int i = 0; i < n; i++)
        {
            string strInfo = Console.ReadLine();
            int intSize = int.Parse(strInfo.Split()[0]);
            string strDirection = strInfo.Split()[1].Substring(0, 1);

            if (y == 0)
            {
                y = GetY(intSize, SOUTH);
            }
            else if (y == intSizeLine)
            {
                y = GetY(intSize, NORTH);
            }
            else if (strDirection == SOUTH)
            {
                y = GetY(intSize, SOUTH);
            }
            else if (strDirection == NORTH)
            {
                y = GetY(intSize, NORTH);
            }
        }

        if (y == 0 && !violation )
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }

    }

    public static int GetY(int intValue, string strDirection)
    {
        int intResult = 0;
        int intLeft = 0;

        if (intValue >= intSizeLine)
        {
            violation = true;
            return intResult;
        }

        switch (strDirection)
        {
            case NORTH:
                if (y - intValue < 0)
                {
                    violation = true;
                    return intResult;
                }
                else
                {
                    intResult = y - intValue;
                }
                break;

            case SOUTH:
                if (intValue + y > intSizeLine)
                {
                    violation = true;
                    return intResult;
                }
                else
                {
                    intResult = y + intValue;
                }
                break;
        }

        return intResult;
    }
}

using System;

namespace tmp6
{
    class Program
    {

        static int Main()
        {
            int n = int.Parse(Console.ReadLine()), tmp = 0;
            int[] t = new int[n];
            string[] dir = new string[n];
            for(int i = 0; i < n; i++)
            {
                string[] strMas = Console.ReadLine().Split(' ');
                t[i] = int.Parse(strMas[0]);
                dir[i] = strMas[1];
            }
            if (dir[0] != "South")
            {
                Console.WriteLine("NO");
                return 0;
            }

            for (int i = 0; i < n - 1; i++)
            {
                if (dir[i] == "North")
                    tmp -= t[i];
                else if (dir[i] == "South")
                    tmp += t[i];

                if (tmp == 0)
                {
                    if (dir[i + 1] != "South")
                    {
                        Console.WriteLine("NO");
                        return 0;
                    }
                }
                else if (tmp == 40000)
                    if (dir[i + 1] != "North")
                    {
                        Console.WriteLine("NO");
                        return 0;
                    }

            }
            if (dir[n - 1] == "North")
                tmp -= t[n - 1];
            else if (dir[n - 1] == "South")
                tmp += t[n - 1];
            if (tmp == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            return 0;
        }
    }
}

using System;

namespace tmp6
{
    class Program
    {

        static int Main()
        {
            int n = int.Parse(Console.ReadLine()), tmp = 0;
            int[] t = new int[n];
            string[] dir = new string[n];
            for(int i = 0; i < n; i++)
            {
                string[] strMas = Console.ReadLine().Split(' ');
                t[i] = int.Parse(strMas[0]);
                dir[i] = strMas[1];
            }
            if (dir[0] != "South")
            {
                Console.WriteLine("NO");
                return 0;
            }

            for (int i = 0; i < n - 1; i++)
            {
                if (dir[i] == "North")
                    tmp -= t[i];
                else if (dir[i] == "South")
                    tmp += t[i];

                if (tmp == 0)
                {
                    if (dir[i + 1] != "South")
                    {
                        Console.WriteLine("NO");
                        return 0;
                    }
                }
                else if (tmp == 20000)
                    if (dir[i + 1] != "North")
                    {
                        Console.WriteLine("NO");
                        return 0;
                    }

            }
            if (dir[n - 1] == "North")
                tmp -= t[n - 1];
            else if (dir[n - 1] == "South")
                tmp += t[n - 1];
            if (tmp == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            return 0;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {

        static string ReadLine()
        {
            return Console.ReadLine();
        }
        static void WriteLine(int n)
        {
            Console.WriteLine(n);
        }
        static void Main(string[] args)
        {

            long n = long.Parse(ReadLine());
            string[] s = new string[n];
            for (int i = 0; i < n; i++)
            {
                s[i] = ReadLine();
            }
            long x = 0;
            long y = 0;
            for (int i = 0; i < n; i++)
            {
                string[] p = s[i].Split();
                long a = long.Parse(p[0]);
                string napr = p[1];
                if (y == 0)
                {
                    if (napr != "South")
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                    else
                    {
                        y += a;
                       // y = y % 20000;
                        y = Math.Abs(y);
                        continue;
                    }
                }
                else if (y == 20000)
                {
                    if (napr != "North")
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                    else
                    {
                        y -= a;
                        //y = y % 20000;
                        y = Math.Abs(y);
                        continue;
                    }
                }
                if (napr == "South")
                {
                    y += a;
                    //y = y % 20000;
                    y = Math.Abs(y);
                }
                else if (napr == "North")
                {
                    y -= a;
                   // y = y % 20000;
                    y = Math.Abs(y);
                }
                else if (napr == "West")
                {
                    x -= a;
                   // x = x % 20000;
                    x = Math.Abs(x);
                }
                else if (napr == "East")
                {
                    x += a;
                   // x = x % 20000;
                    x = Math.Abs(x);
                }

            }
            if (y == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {

        static string ReadLine()
        {
            return Console.ReadLine();
        }
        static void WriteLine(int n)
        {
            Console.WriteLine(n);
        }
        static void Main(string[] args)
        {

            long n = long.Parse(ReadLine());
            string[] s = new string[n];
            for (int i = 0; i < n; i++)
            {
                s[i] = ReadLine();
            }
            long x = 0;
            long y = 0;
            for (int i = 0; i < n; i++)
            {
                string[] p = s[i].Split();
                long a = long.Parse(p[0]);
                string napr = p[1];
                if (y == 0)
                {
                    y += a;
                    y = y % 20000;
                    continue;

                }
                else if (y == 20000)
                {
                    y -= a;
                    y = y % 20000;
                    continue;
                }
                if (napr == "South")
                {
                    y += a;
                    y = y % 20000;
                }
                else if (napr == "North")
                {
                    y -= a;
                    y = y % 20000;
                }
                else if (napr == "West")
                {
                    x -= a;
                    x = x % 20000;
                }
                else
                {
                    x += a;
                    x = x % 20000;
                }

            }

            if (y == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication2
{

    class Program
    {

        static int[,] matrix;
        static int[] mark;

        static void DFS(int v)
        {

            mark[v] = 1;
            for (int i = 0; i < matrix.GetLength(0); i++)
            {

                if (matrix[v, i] == 1)
                {

                    if (mark[v] == 0)
                    {
                        DFS(i);
                    }
                }
            }

        }
        static bool IsPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        static void IsYesNo(bool b)
        {
            if (b)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
        static void Main(string[] args)
        {

            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int x = 0;
            bool f = true;
            for (int i = 0; i < n; i++)
            {
                //Console.WriteLine(x);
                string[] s = Console.ReadLine().Split();
                int a = int.Parse(s[0]);
                if (x == 0)
                {
                    if (s[1] != "South")
                    {
                        f = false;
                    }
                    else
                    {
                        a %= 40000;
                        x += a;
                        x %= 40000;
                    }
                }
                else if (x == 20000)
                {
                    if (s[1] != "North")
                    {
                        f = false;
                    }
                    else
                    {
                        a %= 40000;
                        x -= a;
                        x %= 40000;
                    }
                }
                else
                {
                    if (s[1] == "South")
                    {
                        a %= 40000;
                        x += a;
                        x %= 40000;
                    }
                    else if (s[1] == "North")
                    {
                        a %= 40000;
                        x -= a;
                        x %= 40000;
                    }

                }

            }
            if (!f)
            {
                Console.WriteLine("NO");
            }
            else
            {
                if (x == 0)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }

        }
    }
}

using System;
using System.Linq;
using System.Collections.Generic;

class Solution
{
	static void Main() {
		int n = int.Parse (Console.ReadLine ());
		int y = 0;
		for (int i = 0; i < n; i++) {
			string[] parts = Console.ReadLine ().Split ();
			int dist = int.Parse (parts [0]);
			switch (parts [1]) {
			case "North":
				if (y == 0) {
					Console.WriteLine ("NO");
					return;
				}
				y -= dist;
				break;
			case "South":
				if (y == 20000) {
					Console.WriteLine ("NO");
					return;
				}
				y += dist;
				break;
			case "East":
			case "West":
				if (y == 0 || y == 20000) {
					Console.WriteLine ("NO");
					return;
				}
				break;
			}
		}
		Console.WriteLine (y == 0 ? "YES" : "NO");
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{

    public class Helper
    {
        public List<Helper> Helpers { get; set; }
        public string From { get; set; }
        public List<string> To { get; set; }

        public void Load()
        {
            Helpers = new List<Helper>();

            Helper North = new Helper();
            North.From = "North";
            North.To = new List<string>();
            North.To.Add("South_x_+");
            North.To.Add("North_x_-");

            North.To.Add("West_y_+");
            North.To.Add("East_y_-");

            Helpers.Add(North);

            Helper South = new Helper();
            South.From = "South";
            South.To = new List<string>();

            South.To.Add("North_x_-");
            South.To.Add("South_x_+");

            South.To.Add("East_y_-");
            South.To.Add("West_y_+");

            Helpers.Add(South);

            Helper West = new Helper();
            West.From = "West";
            West.To = new List<string>();
            West.To.Add("South_x_+");
            West.To.Add("North_x_-");

            West.To.Add("East_y_-");
            West.To.Add("West_y_+");

            Helpers.Add(West);

            Helper East = new Helper();
            East.From = "East";
            East.To = new List<string>();
            East.To.Add("South_x_+");
            East.To.Add("North_x_-");

            East.To.Add("West_y_+");
            East.To.Add("East_y_-");

            Helpers.Add(East);

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetIntegerInputFromLine();

            List<object> lines = new List<object>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();

                lines.Add(inputs);

            }

            Helper helper = new Helper();
            helper.Load();

            long x = 0;
            long y = 0;

            var CurrentPosition = "North";

            var satisfy = true;

            foreach (var item in lines)
            {
                var inputs = (string[])item;
                var km = Convert.ToInt64(inputs[0]);
                var dir = inputs[1];

                var anyDirection = helper.Helpers.FirstOrDefault(f => f.From == CurrentPosition);

                var toDirection = anyDirection.To.FirstOrDefault(z => z.Split('_')[0] == dir);

                var toDI = toDirection.Split('_');

                if (x == 0)
                {

                    if (toDI[0] != "South")
                    {
                        satisfy = false;
                        break;
                    }

                }

                if (x == 20000)
                {
                    if (toDI[0] != "North")
                    {
                        satisfy = false;
                        break;
                    }
                }

                if(x>20000||x<0){
                	satisfy=false;
                	break;

                  }

                if (toDirection == null)
                {

                    satisfy = false;
                    break;
                }
                else
                {

                    if (toDI[1] == "x")
                    {
                        if (toDI[2] == "+")
                        {
                            x += km;
                        }
                        else
                        {
                            x -= km;
                        }
                    }
                    else
                    {
                        if (toDI[2] == "+")
                        {
                            y += km;
                        }
                        else
                        {
                            y -= km;
                        }
                    }
                }

                CurrentPosition = dir;
            }

            if (satisfy && CurrentPosition == "North" && x <= 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

        public static bool Bfs(Dictionary<string, List<string>> graph, string from, string to)
        {
            Dictionary<string, int> level = new Dictionary<string, int>();
            Dictionary<string, int> visited = new Dictionary<string, int>();

            Queue<string> queue = new Queue<string>();

            queue.Enqueue(from);
            level[from] = 1;
            visited[from] = 1;
            while (queue.Count() > 0)
            {
                string front = queue.Peek();

                if (front == to)
                {
                    return true;
                }

                List<string> values;

                if (graph.TryGetValue(front, out values))
                {

                    foreach (var item in values)
                    {
                        if (!visited.ContainsKey(item))
                        {
                            level[item] = level[front] + 1;
                            visited[item] = 1;
                            queue.Enqueue(item);
                        }
                    }
                }

                queue.Dequeue();

            }

            return false;
        }
        public void InputBfs()
        {
            var input = GetIntegerInputFromLine();

            Dictionary<string, List<string>> graph = new Dictionary<string, List<string>>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();
                AddOrUpdate(graph, inputs[0], inputs[1]);
                AddOrUpdate(graph, inputs[1], inputs[0]);
            }

            var ins = GetStringInputsFromLine();

            var isRoute = Bfs(graph, ins[0], ins[1]);

            if (!isRoute)
            {
                Console.WriteLine("No route");
            }
            else
            {
                Console.WriteLine("route");
            }
        }

        public static IDictionary<TKey, List<TValue>> AddOrUpdate<TKey, TValue>(IDictionary<TKey, List<TValue>> dictionary, TKey key, TValue value)
        {
            List<TValue> values;

            if (dictionary.TryGetValue(key, out values))
            {
                values.Add(value);

                dictionary[key] = values;
            }
            else
            {
                values = new List<TValue>();
                values.Add(value);
                dictionary[key] = values;
            }

            return dictionary;
        }

        static int GetIntegerInputFromLine()
        {
            var input = Convert.ToInt32(Console.ReadLine().Trim());
            return input;
        }

        static int[] GetIntegerInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x.Trim())).ToArray();
            return inputs;
        }

        static long GetLongInputFromLine()
        {
            var input = Convert.ToInt64(Console.ReadLine().Trim());
            return input;
        }

        static long[] GetLongInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x.Trim())).ToArray();
            return inputs;
        }

        static double GetDoubleInputFromLine()
        {
            var input = Convert.ToDouble(Console.ReadLine().Trim());
            return input;
        }

        static double[] GetDoubleInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToDouble(x.Trim())).ToArray();
            return inputs;
        }

        static string GetStringInputFromLine()
        {
            var input = Console.ReadLine();
            return input;
        }

        static string[] GetStringInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ');
            return inputs;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Source
{

    public void Program()
    {

    }
    HashSet<int> answers = new HashSet<int>();
    int n;
    int[] a;
    void Read()
    {
        n = ri();
        int a;
        string s;
        int pos = 0;
        for (int i = 0; i < n; i++)
        {
            a = ri();
            s = ReadToken();
            if(s== "North" || s == "South")
            {
                if (s == "South")
                {
                    pos += a;
                }
                else
                    pos -= a;
                if(pos<0||pos>=20000)
                {
                    writeLine("NO");
                    return;
                }
            }
        }
        if(pos == 0)
        {
            writeLine("YES");
            return;
        }
        writeLine("NO");
        return;
    }

    #region hide it
    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
            reader = new StreamReader(Console.OpenStandardInput());
            writer = new StreamWriter(Console.OpenStandardOutput());
            //reader = new StreamReader("input.txt");
            //writer = new StreamWriter("output.txt");
#endif
        var source = new Source();
        source.Read();
        source.Program();

        /* try
         {
             new Source().Program();
         }
         catch (Exception ex)
         {
 #if DEBUG
             Console.WriteLine(ex);
 #else
             throw;
 #endif
         }*/
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }
    public static int ri() { return int.Parse(ReadToken()); }
    public static char ReadChar() { return char.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static ulong ReaduLong() { return ulong.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(i => int.Parse(i)).ToArray(); }
    public static char[] ReadCharArray() { return ReadAndSplitLine().Select(i => char.Parse(i)).ToArray(); }
    public static char[] SplitToChar() { string s = ReadToken(); char[] r = new char[s.Length]; for (int i = 0; i < s.Length; i++) r[i] = s[i]; return r; }
    public static byte[] SplitToByte() { string s = ReadToken(); byte[] r = new byte[s.Length]; for (int i = 0; i < s.Length; i++) r[i] = (byte)s[i]; return r; }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static char[][] ReadCharMatrix(int numberOfRows) { char[][] matrix = new char[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadCharArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void write<T>(T value) { writer.Write(value); }
    public static void writeLine<T>(T value) { writer.WriteLine(value); }
    public static void writeArray<T>(T[] array, string split) { for (int i = 0; i < array.Length; i++) { write(array[i] + split); } }
    public static void writeMatrix<T>(T[][] matrix, string split) { for (int i = 0; i < matrix.Length; i++) { writeArray(matrix[i], split); writer.Write("\n"); } }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion

    #region Methods
    #region DSU
    public void MakeSet(int[] poi)
    {
        for (int i = 0; i < poi.Length; i++)
        {
            poi[i] = i;
        }
    }
    public int Find(int x, int[] poi)
    {
        if (poi[x] == x) return x;
        return poi[x] = Find(poi[x], poi);
    }
    Random rand = new Random();
    public void Unite(int x, int y, int[] poi)
    {
        y = Find(y, poi);
        x = Find(x, poi);
        if (rand.Next() % 2 == 0)
            Swap(ref x, ref y);
        poi[x] = y;
    }
    #endregion

    class Deque<T>
    {
        T[] array;
        int start, length;
        public Deque()
        {
            start = 0; length = 0; array = new T[1];
        }
        public T this[int index] { get { return array[(start + index) % array.Length]; } set { array[(start + index) % array.Length] = value; } }
        int last { get { return (start + length) % array.Length; } }
        /// <summary>
        /// ÃÆÃ¢â¬ËÃâÃÂÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬Ã
        /// </summary>
        public T PeekFirst()
        {
            return array[start];
        }
        public int Count { get { return length; } }
        /// <summary>
        /// ÃÆÃÂÃâÃÂºÃÆÃÂÃâÃÂ¾ÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂµÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬  ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        public T PeekLsat()
        {
            return array[last];
        }
        public T PopLast()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            return array[last];
        }
        public T PopFirst()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            if (start >= array.Length - 1) start = 0; else start++;
            return array[start - 1 < 0 ? array.Length - 1 : start - 1];
        }
        public void AddFirst(T value)
        {
            IncreaseAndInspection();
            if (start <= 0) start = array.Length - 1; else start--;
            array[start] = value;
            length++;
        }
        public void AddLast(T value)
        {
            IncreaseAndInspection();
            array[last] = value;
            length++;
        }
        bool overflow { get { return length == array.Length; } }
        void IncreaseAndInspection()
        {
            if (overflow)
                increase();

        }
        void increase()
        {
            T[] array2 = new T[array.Length * 2];
            for (int i = 0; i < array.Length; i++)
            {
                int pos = (start + i) % array.Length;
                array2[i] = array[pos];
            }
            array = array2;
            start = 0;
            array2 = null;
        }
        public void Clear()
        {
            start = 0; length = 0; array = new T[1];
        }
    }
    class Heap<T>
    {
        Comparison<T> ic;
        List<T> storage = new List<T>();
        public Heap(Comparison<T> ic)
        {
            this.ic = ic;
        }
        public void Add(T element)
        {
            storage.Add(element);
            int pos = storage.Count - 1;
            while (pos != 0 && ic(storage[((int)(pos - 1) >> 1)], element) > 0)
            {
                Swap(storage, pos, ((int)(pos - 1) / 2));
                pos = ((int)(pos - 1) / 2);
            }
        }
        public T Pop()
        {
            T t = storage[0];
            Swap(storage, 0, storage.Count - 1);
            int pos = 0;
            storage.RemoveAt(storage.Count - 1);
            if (Count > 0)
                while (true)
                {
                    T my = storage[pos];
                    if (pos * 2 + 1 >= Count)
                        break;
                    T left = storage[pos * 2 + 1];
                    if (pos * 2 + 2 >= Count)
                    {
                        if (ic(left, my) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        break;
                    }
                    T right = storage[pos * 2 + 2];
                    if (ic(left, my) < 0 || ic(right, my) < 0)
                    {
                        if (ic(left, right) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        else
                        {

                            Swap(storage, pos, pos * 2 + 2);
                            pos = pos * 2 + 2;
                        }
                    }
                    else break;
                }
            return t;
        }

        public void Clear()
        {
            storage.Clear();
        }
        /// <summary>
        /// ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        /// <returns></returns>
        public T Peek()
        {
            return storage[0];
        }
        public int Count
        {
            get { return storage.Count; }
        }
        //void RemoveLast, Size, peeklast, add
    }
    static void Swap<T>(ref T lhs, ref T rhs)
    {
        T temp;
        temp = lhs;
        lhs = rhs;
        rhs = temp;
    }
    static void Swap<T>(T[] a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }
    static void Swap<T>(List<T> a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }

    bool outregion(long y, long x, long n, long m)
    {
        if (x < 0 || x >= m || y < 0 || y >= n)
            return true;
        return false;
    }
    static void initlist<T>(ref List<T>[] list, int n)
    {
        list = new List<T>[n];
        for (int i = 0; i < n; i++)
            list[i] = new List<T>();
    }
    static void newarray<T>(ref T[][] array, int n, int m)
    {
        array = new T[n][];
        for (int i = 0; i < n; i++)
            array[i] = new T[m];
    }
    static void newarray<T>(ref T[] array, int n)
    {
        array = new T[n];
    }
    static void fill<T>(T[] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            array[i] = value;
    }
    static void fill<T>(T[][] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            for (int j = 0; j < array[i].Length; j++)
                array[i][j] = value;
    }
    public bool NextPermutation<T>(T[] b, Comparison<T> ic)
    {
        for (int j = b.Length - 2; j >= 0; j--)
        {
            if (ic(b[j], b[j + 1]) < 0)
            {
                for (int l = b.Length - 1; l >= 0; l--)
                {
                    if (ic(b[l], b[j]) > 0)
                    {
                        Swap(b, j, l);
                        Array.Reverse(b, j + 1, b.Length - (j + 1));
                        return true;
                    }
                }
            }
        }
        return false;
    }
    int[,] step8 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
        {1,1 },
        {-1,1 },
        {-1,-1 },
        {1,-1 },
    };
    int[,] step4 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
    };
    struct Vector2
    {
        public double x;
        public double y;
        public Vector2(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
        public double Dist(Vector2 to)
        {
            return Math.Sqrt(Math.Abs(Math.Pow(to.x - x, 2)) + Math.Abs(Math.Pow(to.y - y, 2)));
        }
        public static bool operator ==(Vector2 left, Vector2 right) { return left.x == right.x && left.y == right.y; }
        public static bool operator !=(Vector2 left, Vector2 right) { return left.x != right.x || left.y != right.y; }
    }
    #endregion
    #endregion

}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Source
{

    public void Program()
    {

    }
    HashSet<int> answers = new HashSet<int>();
    int n;
    int[] a;
    void Read()
    {
        n = ri();
        int a;
        string s;
        int pos = 0;
        for (int i = 0; i < n; i++)
        {
            a = ri();
            s = ReadToken();
            if(s== "North" || s == "South")
            {
                if (s == "South")
                {
                    pos += a;
                }
                else
                    pos -= a;
                if(pos<0||pos>20000)
                {
                    writeLine("NO");
                    return;
                }
            }
        }
        if(pos == 0)
        {
            writeLine("YES");
            return;
        }
        writeLine("NO");
        return;
    }

    #region hide it
    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
            reader = new StreamReader(Console.OpenStandardInput());
            writer = new StreamWriter(Console.OpenStandardOutput());
            //reader = new StreamReader("input.txt");
            //writer = new StreamWriter("output.txt");
#endif
        var source = new Source();
        source.Read();
        source.Program();

        /* try
         {
             new Source().Program();
         }
         catch (Exception ex)
         {
 #if DEBUG
             Console.WriteLine(ex);
 #else
             throw;
 #endif
         }*/
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }
    public static int ri() { return int.Parse(ReadToken()); }
    public static char ReadChar() { return char.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static ulong ReaduLong() { return ulong.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(i => int.Parse(i)).ToArray(); }
    public static char[] ReadCharArray() { return ReadAndSplitLine().Select(i => char.Parse(i)).ToArray(); }
    public static char[] SplitToChar() { string s = ReadToken(); char[] r = new char[s.Length]; for (int i = 0; i < s.Length; i++) r[i] = s[i]; return r; }
    public static byte[] SplitToByte() { string s = ReadToken(); byte[] r = new byte[s.Length]; for (int i = 0; i < s.Length; i++) r[i] = (byte)s[i]; return r; }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static char[][] ReadCharMatrix(int numberOfRows) { char[][] matrix = new char[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadCharArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void write<T>(T value) { writer.Write(value); }
    public static void writeLine<T>(T value) { writer.WriteLine(value); }
    public static void writeArray<T>(T[] array, string split) { for (int i = 0; i < array.Length; i++) { write(array[i] + split); } }
    public static void writeMatrix<T>(T[][] matrix, string split) { for (int i = 0; i < matrix.Length; i++) { writeArray(matrix[i], split); writer.Write("\n"); } }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion

    #region Methods
    #region DSU
    public void MakeSet(int[] poi)
    {
        for (int i = 0; i < poi.Length; i++)
        {
            poi[i] = i;
        }
    }
    public int Find(int x, int[] poi)
    {
        if (poi[x] == x) return x;
        return poi[x] = Find(poi[x], poi);
    }
    Random rand = new Random();
    public void Unite(int x, int y, int[] poi)
    {
        y = Find(y, poi);
        x = Find(x, poi);
        if (rand.Next() % 2 == 0)
            Swap(ref x, ref y);
        poi[x] = y;
    }
    #endregion

    class Deque<T>
    {
        T[] array;
        int start, length;
        public Deque()
        {
            start = 0; length = 0; array = new T[1];
        }
        public T this[int index] { get { return array[(start + index) % array.Length]; } set { array[(start + index) % array.Length] = value; } }
        int last { get { return (start + length) % array.Length; } }
        /// <summary>
        /// ÃÆÃ¢â¬ËÃâÃÂÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬Ã
        /// </summary>
        public T PeekFirst()
        {
            return array[start];
        }
        public int Count { get { return length; } }
        /// <summary>
        /// ÃÆÃÂÃâÃÂºÃÆÃÂÃâÃÂ¾ÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂµÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬  ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        public T PeekLsat()
        {
            return array[last];
        }
        public T PopLast()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            return array[last];
        }
        public T PopFirst()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            if (start >= array.Length - 1) start = 0; else start++;
            return array[start - 1 < 0 ? array.Length - 1 : start - 1];
        }
        public void AddFirst(T value)
        {
            IncreaseAndInspection();
            if (start <= 0) start = array.Length - 1; else start--;
            array[start] = value;
            length++;
        }
        public void AddLast(T value)
        {
            IncreaseAndInspection();
            array[last] = value;
            length++;
        }
        bool overflow { get { return length == array.Length; } }
        void IncreaseAndInspection()
        {
            if (overflow)
                increase();

        }
        void increase()
        {
            T[] array2 = new T[array.Length * 2];
            for (int i = 0; i < array.Length; i++)
            {
                int pos = (start + i) % array.Length;
                array2[i] = array[pos];
            }
            array = array2;
            start = 0;
            array2 = null;
        }
        public void Clear()
        {
            start = 0; length = 0; array = new T[1];
        }
    }
    class Heap<T>
    {
        Comparison<T> ic;
        List<T> storage = new List<T>();
        public Heap(Comparison<T> ic)
        {
            this.ic = ic;
        }
        public void Add(T element)
        {
            storage.Add(element);
            int pos = storage.Count - 1;
            while (pos != 0 && ic(storage[((int)(pos - 1) >> 1)], element) > 0)
            {
                Swap(storage, pos, ((int)(pos - 1) / 2));
                pos = ((int)(pos - 1) / 2);
            }
        }
        public T Pop()
        {
            T t = storage[0];
            Swap(storage, 0, storage.Count - 1);
            int pos = 0;
            storage.RemoveAt(storage.Count - 1);
            if (Count > 0)
                while (true)
                {
                    T my = storage[pos];
                    if (pos * 2 + 1 >= Count)
                        break;
                    T left = storage[pos * 2 + 1];
                    if (pos * 2 + 2 >= Count)
                    {
                        if (ic(left, my) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        break;
                    }
                    T right = storage[pos * 2 + 2];
                    if (ic(left, my) < 0 || ic(right, my) < 0)
                    {
                        if (ic(left, right) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        else
                        {

                            Swap(storage, pos, pos * 2 + 2);
                            pos = pos * 2 + 2;
                        }
                    }
                    else break;
                }
            return t;
        }

        public void Clear()
        {
            storage.Clear();
        }
        /// <summary>
        /// ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        /// <returns></returns>
        public T Peek()
        {
            return storage[0];
        }
        public int Count
        {
            get { return storage.Count; }
        }
        //void RemoveLast, Size, peeklast, add
    }
    static void Swap<T>(ref T lhs, ref T rhs)
    {
        T temp;
        temp = lhs;
        lhs = rhs;
        rhs = temp;
    }
    static void Swap<T>(T[] a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }
    static void Swap<T>(List<T> a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }

    bool outregion(long y, long x, long n, long m)
    {
        if (x < 0 || x >= m || y < 0 || y >= n)
            return true;
        return false;
    }
    static void initlist<T>(ref List<T>[] list, int n)
    {
        list = new List<T>[n];
        for (int i = 0; i < n; i++)
            list[i] = new List<T>();
    }
    static void newarray<T>(ref T[][] array, int n, int m)
    {
        array = new T[n][];
        for (int i = 0; i < n; i++)
            array[i] = new T[m];
    }
    static void newarray<T>(ref T[] array, int n)
    {
        array = new T[n];
    }
    static void fill<T>(T[] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            array[i] = value;
    }
    static void fill<T>(T[][] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            for (int j = 0; j < array[i].Length; j++)
                array[i][j] = value;
    }
    public bool NextPermutation<T>(T[] b, Comparison<T> ic)
    {
        for (int j = b.Length - 2; j >= 0; j--)
        {
            if (ic(b[j], b[j + 1]) < 0)
            {
                for (int l = b.Length - 1; l >= 0; l--)
                {
                    if (ic(b[l], b[j]) > 0)
                    {
                        Swap(b, j, l);
                        Array.Reverse(b, j + 1, b.Length - (j + 1));
                        return true;
                    }
                }
            }
        }
        return false;
    }
    int[,] step8 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
        {1,1 },
        {-1,1 },
        {-1,-1 },
        {1,-1 },
    };
    int[,] step4 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
    };
    struct Vector2
    {
        public double x;
        public double y;
        public Vector2(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
        public double Dist(Vector2 to)
        {
            return Math.Sqrt(Math.Abs(Math.Pow(to.x - x, 2)) + Math.Abs(Math.Pow(to.y - y, 2)));
        }
        public static bool operator ==(Vector2 left, Vector2 right) { return left.x == right.x && left.y == right.y; }
        public static bool operator !=(Vector2 left, Vector2 right) { return left.x != right.x || left.y != right.y; }
    }
    #endregion
    #endregion

}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

public static class B__
{
    private static void Solve()
    {
        int n = ReadInt();

        int x = 0;
        int y = 0;
        bool valid = true;

        while (n-- > 0)
        {
            int distance = ReadInt();
            string direction = Read();

            if (y == 0 && direction != "South")
            {
                valid = false;
                break;
            }

            if (y == 20000 && direction != "North")
            {
                valid = false;
                break;
            }

            Move(ref x, ref y, distance, direction);
        }

        if (y != 0)
            valid = false;

        Write(valid ? "YES" : "NO");
    }

    private static void Move(ref int x, ref int y, int distance, string direction)
    {
        if (direction == "North")
        {
            y -= distance;
        }
        else if (direction == "South")
        {
            y += distance;
        }
        else if (direction == "East")
        {
            x += distance;
        }
        else if (direction == "West")
        {
            x -= distance;
        }
    }

    #region Main

    private static TextReader reader;
    private static TextWriter writer;
    public static void Main()
    {
#if DEBUG
        //reader = new StreamReader("C:\\Users\\Axel\\Desktop\\input.txt");
        reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            Solve();
            //var thread = new Thread(new B__().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string Read() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{

    public class Helper
    {
        public List<Helper> Helpers { get; set; }
        public string From { get; set; }
        public List<string> To { get; set; }

        public void Load()
        {
            Helpers = new List<Helper>();

            Helper North = new Helper();
            North.From = "North";
            North.To = new List<string>();
            North.To.Add("South_x_+");
            North.To.Add("North_x_-");

            North.To.Add("West_y_+");
            North.To.Add("East_y_-");

            Helpers.Add(North);

            Helper South = new Helper();
            South.From = "South";
            South.To = new List<string>();

            South.To.Add("North_x_-");
            South.To.Add("South_x_+");

            South.To.Add("East_y_-");
            South.To.Add("West_y_+");

            Helpers.Add(South);

            Helper West = new Helper();
            West.From = "West";
            West.To = new List<string>();
            West.To.Add("South_x_+");
            West.To.Add("North_x_-");

            West.To.Add("East_y_-");
            West.To.Add("West_y_+");

            Helpers.Add(West);

            Helper East = new Helper();
            East.From = "East";
            East.To = new List<string>();
            East.To.Add("South_x_+");
            East.To.Add("North_x_-");

            East.To.Add("West_y_+");
            East.To.Add("East_y_-");

            Helpers.Add(East);

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetIntegerInputFromLine();

            List<object> lines = new List<object>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();

                lines.Add(inputs);

            }

            Helper helper = new Helper();
            helper.Load();

            long x = 0;
            long y = 0;

            var CurrentPosition = "North";

            var satisfy = true;

            foreach (var item in lines)
            {
                var inputs = (string[])item;
                var km = Convert.ToInt64(inputs[0]);
                var dir = inputs[1];

                var anyDirection = helper.Helpers.FirstOrDefault(f => f.From == CurrentPosition);

                var toDirection = anyDirection.To.FirstOrDefault(z => z.Split('_')[0] == dir);

                var toDI = toDirection.Split('_');

                if (x == 0)
                {

                    if (toDI[0] != "South")
                    {
                        satisfy = false;
                        break;
                    }

                }

                if (x == 20000)
                {
                    if (toDI[0] != "North")
                    {
                        satisfy = false;
                        break;
                    }
                }

                if (toDirection == null)
                {

                    satisfy = false;
                    break;
                }
                else
                {

                    if (toDI[1] == "x")
                    {
                        if (toDI[2] == "+")
                        {
                            x += km;
                        }
                        else
                        {
                            x -= km;
                        }
                    }
                    else
                    {
                        if (toDI[2] == "+")
                        {
                            y += km;
                        }
                        else
                        {
                            y -= km;
                        }
                    }
                }

                CurrentPosition = dir;
            }

            if (satisfy && CurrentPosition == "North" && x <= 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

        public static bool Bfs(Dictionary<string, List<string>> graph, string from, string to)
        {
            Dictionary<string, int> level = new Dictionary<string, int>();
            Dictionary<string, int> visited = new Dictionary<string, int>();

            Queue<string> queue = new Queue<string>();

            queue.Enqueue(from);
            level[from] = 1;
            visited[from] = 1;
            while (queue.Count() > 0)
            {
                string front = queue.Peek();

                if (front == to)
                {
                    return true;
                }

                List<string> values;

                if (graph.TryGetValue(front, out values))
                {

                    foreach (var item in values)
                    {
                        if (!visited.ContainsKey(item))
                        {
                            level[item] = level[front] + 1;
                            visited[item] = 1;
                            queue.Enqueue(item);
                        }
                    }
                }

                queue.Dequeue();

            }

            return false;
        }
        public void InputBfs()
        {
            var input = GetIntegerInputFromLine();

            Dictionary<string, List<string>> graph = new Dictionary<string, List<string>>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();
                AddOrUpdate(graph, inputs[0], inputs[1]);
                AddOrUpdate(graph, inputs[1], inputs[0]);
            }

            var ins = GetStringInputsFromLine();

            var isRoute = Bfs(graph, ins[0], ins[1]);

            if (!isRoute)
            {
                Console.WriteLine("No route");
            }
            else
            {
                Console.WriteLine("route");
            }
        }

        public static IDictionary<TKey, List<TValue>> AddOrUpdate<TKey, TValue>(IDictionary<TKey, List<TValue>> dictionary, TKey key, TValue value)
        {
            List<TValue> values;

            if (dictionary.TryGetValue(key, out values))
            {
                values.Add(value);

                dictionary[key] = values;
            }
            else
            {
                values = new List<TValue>();
                values.Add(value);
                dictionary[key] = values;
            }

            return dictionary;
        }

        static int GetIntegerInputFromLine()
        {
            var input = Convert.ToInt32(Console.ReadLine().Trim());
            return input;
        }

        static int[] GetIntegerInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x.Trim())).ToArray();
            return inputs;
        }

        static long GetLongInputFromLine()
        {
            var input = Convert.ToInt64(Console.ReadLine().Trim());
            return input;
        }

        static long[] GetLongInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x.Trim())).ToArray();
            return inputs;
        }

        static double GetDoubleInputFromLine()
        {
            var input = Convert.ToDouble(Console.ReadLine().Trim());
            return input;
        }

        static double[] GetDoubleInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToDouble(x.Trim())).ToArray();
            return inputs;
        }

        static string GetStringInputFromLine()
        {
            var input = Console.ReadLine();
            return input;
        }

        static string[] GetStringInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ');
            return inputs;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{

    public class Helper
    {
        public List<Helper> Helpers { get; set; }
        public string From { get; set; }
        public List<string> To { get; set; }

        public void Load()
        {
            Helpers = new List<Helper>();

            Helper North = new Helper();
            North.From = "North";
            North.To = new List<string>();
            North.To.Add("South_x_+");
            North.To.Add("North_x_-");

            North.To.Add("West_y_+");
            North.To.Add("East_y_-");

            Helpers.Add(North);

            Helper South = new Helper();
            South.From = "South";
            South.To = new List<string>();

            South.To.Add("North_x_-");
            South.To.Add("South_x_+");

            South.To.Add("East_y_-");
            South.To.Add("West_y_+");

            Helpers.Add(South);

            Helper West = new Helper();
            West.From = "West";
            West.To = new List<string>();
            West.To.Add("South_x_+");
            West.To.Add("North_x_-");

            West.To.Add("East_y_-");
            West.To.Add("West_y_+");

            Helpers.Add(West);

            Helper East = new Helper();
            East.From = "East";
            East.To = new List<string>();
            East.To.Add("South_x_+");
            East.To.Add("North_x_-");

            East.To.Add("West_y_+");
            East.To.Add("East_y_-");

            Helpers.Add(East);

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetIntegerInputFromLine();

            List<object> lines = new List<object>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();

                lines.Add(inputs);

            }

            Helper helper = new Helper();
            helper.Load();

            long x = 0;
            long y = 0;

            var CurrentPosition = "North";

            var satisfy = true;

            foreach (var item in lines)
            {
                var inputs = (string[])item;
                var km = Convert.ToInt64(inputs[0]);
                var dir = inputs[1];

                var anyDirection = helper.Helpers.FirstOrDefault(f => f.From == CurrentPosition);

                var toDirection = anyDirection.To.FirstOrDefault(z => z.Split('_')[0] == dir);

                var toDI = toDirection.Split('_');

                if (x == 0 || x == 20000)
                {
                    if (CurrentPosition == "North")
                    {
                        if (toDI[0] != "South")
                        {
                            satisfy = false;
                            break;
                        }
                    }

                    if (CurrentPosition == "South")
                    {
                        if (toDI[0] != "North")
                        {
                            satisfy = false;
                            break;
                        }
                    }
                }

                if (toDirection == null)
                {

                    satisfy = false;
                    break;
                }
                else
                {

                    if (toDI[1] == "x")
                    {
                        if (toDI[2] == "+")
                        {
                            x += km;
                        }
                        else
                        {
                            x -= km;
                        }
                    }
                    else
                    {
                        if (toDI[2] == "+")
                        {
                            y += km;
                        }
                        else
                        {
                            y -= km;
                        }
                    }
                }

                CurrentPosition = dir;
            }

            if (satisfy && CurrentPosition == "North" && x == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

        public static bool Bfs(Dictionary<string, List<string>> graph, string from, string to)
        {
            Dictionary<string, int> level = new Dictionary<string, int>();
            Dictionary<string, int> visited = new Dictionary<string, int>();

            Queue<string> queue = new Queue<string>();

            queue.Enqueue(from);
            level[from] = 1;
            visited[from] = 1;
            while (queue.Count() > 0)
            {
                string front = queue.Peek();

                if (front == to)
                {
                    return true;
                }

                List<string> values;

                if (graph.TryGetValue(front, out values))
                {

                    foreach (var item in values)
                    {
                        if (!visited.ContainsKey(item))
                        {
                            level[item] = level[front] + 1;
                            visited[item] = 1;
                            queue.Enqueue(item);
                        }
                    }
                }

                queue.Dequeue();

            }

            return false;
        }
        public void InputBfs()
        {
            var input = GetIntegerInputFromLine();

            Dictionary<string, List<string>> graph = new Dictionary<string, List<string>>();

            for (int i = 0; i < input; i++)
            {
                var inputs = GetStringInputsFromLine();
                AddOrUpdate(graph, inputs[0], inputs[1]);
                AddOrUpdate(graph, inputs[1], inputs[0]);
            }

            var ins = GetStringInputsFromLine();

            var isRoute = Bfs(graph, ins[0], ins[1]);

            if (!isRoute)
            {
                Console.WriteLine("No route");
            }
            else
            {
                Console.WriteLine("route");
            }
        }

        public static IDictionary<TKey, List<TValue>> AddOrUpdate<TKey, TValue>(IDictionary<TKey, List<TValue>> dictionary, TKey key, TValue value)
        {
            List<TValue> values;

            if (dictionary.TryGetValue(key, out values))
            {
                values.Add(value);

                dictionary[key] = values;
            }
            else
            {
                values = new List<TValue>();
                values.Add(value);
                dictionary[key] = values;
            }

            return dictionary;
        }

        static int GetIntegerInputFromLine()
        {
            var input = Convert.ToInt32(Console.ReadLine().Trim());
            return input;
        }

        static int[] GetIntegerInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x.Trim())).ToArray();
            return inputs;
        }

        static long GetLongInputFromLine()
        {
            var input = Convert.ToInt64(Console.ReadLine().Trim());
            return input;
        }

        static long[] GetLongInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x.Trim())).ToArray();
            return inputs;
        }

        static double GetDoubleInputFromLine()
        {
            var input = Convert.ToDouble(Console.ReadLine().Trim());
            return input;
        }

        static double[] GetDoubleInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => Convert.ToDouble(x.Trim())).ToArray();
            return inputs;
        }

        static string GetStringInputFromLine()
        {
            var input = Console.ReadLine();
            return input;
        }

        static string[] GetStringInputsFromLine()
        {
            var inputs = Console.ReadLine().Split(' ');
            return inputs;
        }
    }
}