const fi='';//750B.inp';
      fo='';//750B.out';

var n:longint;

procedure doc;
   var i,k,d,x:longint;
       s:string;
   begin
      assign(input,fi);
      reset(input);
      assign(output,fo);
      rewrite(output);
      readln(n);
      d:=0;
      for i:=1 to n do
      begin
         read(x); readln(s);
         if s[2]='N' then k:=1;
         if s[2]='E' then k:=2;
         if s[2]='S' then k:=3;
         if s[2]='W' then k:=4;
         if ((d=0) or (d=20000)) and ((k=2) or (k=4)) then
         begin write('NO'); exit; end;
         if (d=0) and (k=1) then
         begin write('NO'); exit; end;
         if (d=20000) and (k=3) then
         begin write('NO'); exit; end;
         if k=1 then
         begin
            d:=d-x;
            if d<0 then
            begin write('NO'); exit; end;
         end;
         if k=3 then
         begin
            d:=x+d;
            if d >20000 then
            begin write('NO'); exit; end;
         end;
      end;
      if d=0 then write('YES') else write('NO');
   end;

BEGIN
   DOC;
END.

program cf750B;
const lim=20000;
      letter:set of char=['A'..'Z'];
var n,now,t,i:longint;
    ch:char;
procedure printerr;
begin
  writeln('NO');
  halt;
end;
procedure getch(var ch:char);
begin
  read(ch);
  while not (ch in letter) do read(ch);
end;
begin
  readln(n);
  now:=0;
  for i:=1 to n do
  begin
    read(t);
    getch(ch);
    readln;
    if (now=0)and(ch<>'S') then printerr;
    if (now=lim)and(ch<>'N') then printerr;
    if ch='S' then now:=now+t
      else if ch='N' then now:=now-t;
    if (now<0)or(now>lim) then printerr;
  end;
  if now<>0 then printerr;
  writeln('YES');
end.

var n,now,i:longint;
    k:int64;
    s:ansistring;
begin
  readln(n);now:=0;
  for i:=1 to n do
    begin
      readln(s);
      val(copy(s,1,pos(' ',s)-1),k);
      delete(s,1,pos(' ',s));
      if(s[1]='N')then now:=now-k
      else if(s[1]='S')then now:=now+k;
      if((now=0)or(now=20000))and((s[1]='E')or(s[1]='W'))then begin writeln('NO');halt;end;
      if(now<0)or(now>20000)then begin writeln('NO');halt;end;
    end;
  if(now<>0)then writeln('NO')else writeln('YES');
end.

var i,n,sum,x:longint;
    s:string;
begin
  //assign(input,'input.txt');reset(input);
  readln(n);
  for i:=1 to n do
    begin
      read(x); readln(s);
      if s[2]='S' then inc(sum,x);
      if s[2]='N' then dec(sum,x);
      if ((s[2]='W')or(s[2]='E'))and((sum=0)or(sum=20000))then begin writeln('NO');halt; end;
      if (sum<0)or(sum>20000)then begin writeln('NO');halt;end;
    end;
  if (sum=0)then write('YES')else write('NO');
end.

var n,i,x:longint;
    d:int64;
    s:ansistring;
begin
    readln(n);
    d:=0;
    for i:=1 to n do
    begin
        readln(x,s);
        delete(s,1,1);
        if (d=0) and (s<>'South') then begin writeln('NO'); halt; end;
        if (d=20000) and (s<>'North') then begin writeln('NO'); halt; end;
        if (s='South') then d:=d+x;
        if (s='North') then d:=d-x;
        if (d>20000) and (s='South') then begin writeln('NO'); halt; end;
        if (d<0) and (s='North') then begin writeln('NO'); halt; end;
    end;
    if (d=0) then writeln('YES') else writeln('NO');
    readln;
end.

var n,i,x,y,j:integer;
    s:string;
    t:boolean;
    f:byte;

begin
  read(n);
  for i:=1 to n do
  begin
    readln(j,s);
    s:=copy(s,2,length(s)-1);
    if s='North' then f:=1 else if s='South' then f:=2 else if s='West' then f:=3 else f:=4;
    case f of
      1: if (y-j>=0) then y:=y-j else t:=true;
      2: if (y+j<=20000) then y:=y+j else t:=true;
      3: if (y<>0) and (y<>20000) then x:=x-j else t:=true;
      4: if (y<>0) and (y<>20000) then x:=x+j else t:=true;
    end;
  end;
  if  t or (y<>0) then write('NO') else write('YES');
end.

var k,a,n,i,t:longint;
    dis:string;
begin
read(n);
a:=0;
k:=0;
for i:=1 to n do
   begin
     read(t,dis);
     delete(dis,1,1);
     if ((a+t>20000) and (dis='South')) or ((a-t<0) and (dis='North')) then
       begin
         k:=1;
         break;
       end else
       if ((a=0) and (dis='South')) or ((dis='South') and (a<>0) and (a<>20000))  then
          a:=a+t else
       if ((a=20000) and (dis='North')) or ((dis='North') and (a<>0) and (a<>20000))  then
             a:=a-t else
           if (a<>0) and (a<>20000) and ((dis='East') or (dis='West')) then
                a:=a else
                 begin
                   k:=1;
                   break;
                 end;

   end;
if (k=0) and (a=0) then write('YES') else write('NO');
end.

const fi='';//750B.inp';
        fo='';//750B.out';
var n : longint;
        a,b: array[1..1000000] of longint;
procedure doc;
var i,j : longint; S: string[2];
begin
        assigN(input,fi);
        reseT(input);
        reaDln(n);
        for i:=1 to n do
        begin
                readln(a[i], s);
                if s[2] = 'N' then b[i]:= 1
                else if s[2] = 'S' then b[i]:=2
                else if s[2] = 'E' then b[i]:= 3
                else if s[2] = 'W' then b[i]:= 4;
        end;
end;
procedure xuly;
var i,j : longint; s: longint;
begin
        S:=0;
        for i:=1 to n do
        begin
                if (s = 20000) and ( b[i] <> 1) then
                begin
                        write('NO');
                        exit;
                end;
                if ( s = 0 ) and ( b[i] <> 2 ) then
                begin
                        write('NO');
                        exit;
                end;
                if b[i] =2 then s:= s + a[i]
                else if b[i] =1 then s:= s- a[i];
                if ( s > 20000 ) then
                begin
                        write('NO');
                        exit;
                end;
                if ( s < 0 ) then
                begin
                        write('NO');
                        exit;
                end;
        end;
        if s= 0 then write('YES') else write('NO');
end;
begin
        doc;
        xuly;

        end.

const fi = '';
      fo = '';
var x, i, n, vt: longint;
    s: string;
    c: char;
begin
  assign(input,fi); reset(input);
  assign(output,fo); rewrite(output);

  readln(n);
  vt:=0;
  for i:=1 to n do
    begin
      readln(x,c,s);
      if s = 'South' then
        begin
          vt:=vt+x;
          if vt > 20000 then
            begin
              writeln('NO');
              halt;
            end;
        end
      else if s = 'North' then
        begin
          vt:=vt- x;
          if vt < 0 then
            begin
              writeln('NO');
              halt;
            end;
        end
      else if (s = 'West') or (s = 'East') then
        begin
          if (vt = 0) or (vt = 20000) then
            begin
              writeln('NO');
              halt;
            end;
        end;
    end;
  if vt <> 0 then write('NO')
  else write('YES');

  close(input); close(output);
end.

uses math;
const
	fin='';
	fon='';
	maxC=1000000007;
	maxN=107;
type
        data=record
                dis,dir:longint;
        end;
var
        n:longint;
        a:array [0..maxN] of data;

Procedure Openf;
begin
	assign(input,fin); reset(input);
	assign(output,fon); rewrite(output);
end;

Procedure Closef;
begin
	close(input);
	close(output);
End;

function cal(pos:longint):boolean;
var
        now:longint;
        i,x,y,tg:longint;
begin
        now:=1;
        x:=0;
        for i:=1 to n do
        begin
                if (x=0) and (a[i].dir<>4) then exit(false);
                if (x=20000) and (a[i].dir<>1) then exit(false);
                if (a[i].dir=1) or (a[i].dir=4) then
                with a[i] do
                begin
                        tg:=x;
                        if dir = 1 then
                        begin
                                tg:=tg-a[i].dis;
                                if tg<0 then exit(false);
                        end
                        else
                        begin
                                tg:=tg+a[i].dis;
                                if tg>20000 then exit(false);
                        end;
                        x:=tg;
                        now:=dir;
                end;

        end;
        if (x=0) and (now=1) then exit(true);
        exit(false);
end;

Procedure Nhap;
var
        i:longint;
        s:ansistring;
Begin
        readln(n);
        for i:=1 to n do
        with a[i] do
        begin
                readln(dis,s);
                if s=' North' then a[i].dir:=1;
                if s=' East' then a[i].dir:=2;
                if s=' West' then a[i].dir:=3;
                if s=' South' then a[i].dir:=4;

        end;
        if cal(5-a[1].dir) then writeln('YES')
        else writeln('NO');
End;

Procedure xuli;
begin
end;

Procedure Xuat;
begin
end;

Procedure Solve;
begin
	Nhap;
	Xuli;
	Xuat;
end;
BEGIN
	Openf;
	Solve;
	Closef;
END.

var n,i,tek,nn,j,x,code:longint;
    s:string;
begin
 readln(nn);
 tek:=0;
 for i:=1 to nn do
  begin
   readln(s);
   n:=0;
   for j:=1 to length(s) do
    begin
     val(s[j],x,code);
     if code>0
      then begin delete(s,1,j);break;end
      else begin n:=n*10+x;end;
    end;
   if (s='North')and(tek<n)
    then begin write('NO');halt;end;
   if (s='South')and(tek+n>20000)
    then begin write('NO');halt;end;
   if ((s='West')or(s='East'))and((tek=0)or(tek=20000))
    then begin write('NO');halt;end;

   if s='North'
    then dec(tek,n);
   if s='South'
    then inc(tek,n);

  end;
  if tek=0
   then write('YES')
   else write('NO');

end.

var n,f,i,a : longint;
    c : char;
begin
  readln(n); f:=0;
  for i:=1 to n do begin
      readln(a,c,c);
      if (f = 0) and (c <> 'S') then begin writeln('NO'); halt; end;
      if (f = 20000) and (c <> 'N') then begin writeln('NO'); halt; end;
      if c = 'S' then inc(f,a);
      if c = 'N' then dec(f,a);
      if f < 0 then begin writeln('NO'); halt; end;
      if f > 20000 then begin writeln('NO'); halt; end;
    end;
  if f <> 0 then begin writeln('NO'); halt; end;
  writeln('YES');
end.

uses    math;

var     n,k:longint;

procedure mofile;
begin
        assign(input,'test.inp');
        assign(output,'test.out');
        reset(input);
        rewrite(output);
end;

procedure dongfile;
begin
        close(input);
        close(output);
end;

procedure doc;
begin
        readln(n);
end;

procedure xuly;
var     i,t:longint;
        z,x:char;
begin
        k:=0;
        for i:=1 to n do
        begin
            readln(t,x,z);
            if (k=0)and(z<>'S') then
            begin
                write('NO');
                halt;
            end;
            if (k=20000)and(z<>'N') then
            begin
                write('NO');
                halt;
            end;
            if z='S' then k:=k+t;
            if k>20000 then
            begin
                write('NO');
                halt;
            end;
            if z='N' then k:=k-t;
            if k<0 then
            begin
                write('NO');
                halt;
            end;
        end;
        if k=0 then write('YES') else write('NO');
end;

BEGIN

        doc;
        xuly;

END.

{$Mode objfpc}

var
  n,i,j,o:integer;
  s:ansistring;
  w:integer;

procedure dung;
  begin
    write('NO');
    halt;
  end;

begin
  readln(n);
  o:=0;
  for i:=1 to n do
    begin
      readln(s);
      w:=0;
      for j:=1 to length(s) do
        if s[j] = ' ' then break
        else w:=w*10 + ord(s[j])-48;
      if s[j+1] = 'W' then
        if (o = 0) or (o = 20000) then dung;
      if s[j+1] = 'E' then
        if (o = 0) or (o = 20000) then dung;
      if s[j+1] = 'W' then continue;
      if s[j+1] = 'E' then continue;
      if s[j+1] = 'S' then
        begin
          o:=o + w;
          if (o > 20000) or (o < 0) then dung;
        end;
      if s[j+1] = 'N' then
        begin
          o:=o - w;
          if (o > 20000) or (o < 0) then dung;
        end;
    end;
  if o <> 0 then dung;
  write('YES');
end.

{$IFDEF ONLINE_JUDGE}
{$R-,Q-,S-,I-}
{$OPTIMIZATION LEVEL2}
{$INLINE ON}
{$ENDIF}

uses math;

procedure mofile;
begin
        {$IFDEF ONLINE_JUDGE}
        assign(input,'');
        reset(input);
        assign(output,'');
        rewrite(output);
        {$ELSE}
        assign(input,'checking.inp');
        reset(input);
        assign(output,'');
        rewrite(output);
        {$ENDIF}
end;

procedure dongfile;
begin
        close(input);
        close(output);
end;

const
        maxc=1000000000+69;
        modulo=1000000000+7;

type
        re=record
                x,y:longint;
        end;

var
        n:longint;
        ok:boolean;

procedure xuli;
var
        i,xx,x:longint;
        s:ansistring;
begin
        readln(N);
        xx:=0;
        ok:=true;
        for i:=1 to n do
        begin
                readln(x,s);
                if s=' North' then xx:=xx-x else
                if s=' South' then xx:=xx+x else
                if (xx=0) or (xx=20000) then ok:=false;
                if (xx<0) or (xx>20000) then ok:=false;
        end;
        ok:=ok and (xx=0);
        if ok then writeln('YES') else writeln('NO');
end;

begin
        mofile;
        xuli;
        dongfile;
end.

const
    fi='';
    fo='';
var n,k,so,no,mark:longint;
    f,g:text;
    kt:boolean;
    s:string;
procedure nhap;
var i:longint;
begin
    assign(f,fi);
    reset(F);
    readln(f,n);
    kt:=false;
    for i:=1 to n do
    begin
        readln(f,k,s);
        if (so=0) and (s<>' South') then kt:=true;
        if (so=20000) and (s<>' North') then kt:=true;
        if s=' South' then
            so:=so+k
        else
        if s=' North' then
            so:=so-k;
        if (so<0) or (so>20000) then kt:=true;
    end;
    close(f);
end;
procedure xuli;
var i:longint;
begin
    assign(g,fo);
    rewrite(G);
    if (kt=false) and (so=0) then write(g,'YES') else write(g,'NO');
    close(g);
end;
begin
    nhap;
    xuli;
end.

var xcoors,ycoors,i,n,coors:longint;
	satisfied:boolean;
	direction:String;
Begin
	Readln(n);
	satisfied:=True;
	xcoors:=0;
	ycoors:=0;
	For i:=1 to n do
		Begin
			Readln(coors,direction);
			While pos(' ',direction)>0 do Delete(direction,pos(' ',direction),1);
			If (direction='North') then	dec(ycoors,coors)
			Else if (direction='South') then inc(ycoors,coors)
			Else
				If (ycoors mod 20000=0) then
					Begin
						satisfied:=False;
						break;
					End;
			If (ycoors<0) or (ycoors>20000) then
				Begin
					satisfied:=False;
					break;
				End;
		End;
	If (ycoors<>0) then satisfied:=False;
	If (satisfied) then Write('YES')
	Else Write('NO');
End.

uses math;
const fin='goodbye2016pB.INP';
      fon='goodbye2016pB.OUT';
      maxn=57;
var fi,fo:text;
    x,n:longint;
    vt:string;
    t:array[1..maxn] of longint;
    d:array[1..maxn] of string;
procedure nhap;
  var i:longint;
      x:char;
  begin
    readln(fi,n);
    for i:=1 to n do
      readln(fi,t[i],x,d[i]);
  end;
procedure inkq(s:string);
  begin
    writeln(Fo,s);
    close(fo);
    halt;
  end;
function ktra(x:longint):string;
  begin
    x:=abs(x);
    if x=0 then exit('North');
    if x=20000 then exit('South');
    exit('Middle');
  end;
procedure xuly;
  var i:longint;
  begin
    vt:='North';
    for i:=1 to n do
      begin
        if d[i]='South' then
         begin
          if vt='South' then inkq('NO');
          if x+t[i]>20000 then inkq('NO');
          x:=x+t[i];
          vt:=ktra(x);
         end;
        if d[i]='North' then
         begin
          if vt='North' then inkq('NO');
          if x-t[i]<0 then inkq('NO');
          x:=x-t[i];
          vt:=ktra(x);
         end;
        if d[i]='East' then
         begin
          if (vt='North') or (vt='South') then inkq('NO');
         end;
        if d[i]='West' then
         begin
          if (vt='North') or (vt='South') then inkq('NO');
         end;
      end;
    if ktra(x)='North' then inkq('YES') else inkq('NO');
  end;
begin
  assign(fi,'');  reset(fi);
  assign(fo,'');  rewrite(fo);
  nhap;
  xuly;
  close(fi);  close(fo);
end.

var
  n,now,p,i,d:longint;
  st:string;
  flag:boolean;
begin
  readln(n);
  now:=0;flag:=true;
  for i:=1 to n do
    begin
      readln(st);
      p:=pos(' ',st);
      val(copy(st,1,p-1),d);
      case st[p+1] of
        'S':
          begin
            inc(now,d);
            if now>20000
              then flag:=false;
          end;
        'N':
          begin
            dec(now,d);
            if now<0
              then flag:=false;
          end;
        'E':if (now=0)or(now=20000) then flag:=false;
        'W':if (now=0)or(now=20000) then flag:=false;
      end;
    end;
  if now<>0
    then flag:=false;
  if flag
    then writeln('YES')
    else writeln('NO');
end.

var
  i,j,k,x,n,len:longint;
  c:char;
begin
  readln(n);
  x:=0;
  for i:=1 to n do
  begin
    read(len);
    read(c);
    read(c);
    readln;
    if c='S' then
    begin
      x:=x+len;
      if x>20000 then
      begin
        writeln('NO');
        exit;
      end;
      continue;
    end;
    if c='N' then
    begin
      x:=x-len;
      if x<0 then
      begin
        writeln('NO');
        exit;
      end;
      continue;
    end;
    if ((c='E') or (c='W')) and ((x=0) or (x=20000)) then
    begin
      writeln('NO');
      exit;
    end;
  end;
  if x=0 then
    writeln('YES')
  else
    writeln('NO');
end.

program sv;
var i,j,n,k,d,h,t,y:longint;
s,w:string;
procedure stop;
begin
write('NO');
halt;
end;
begin
{assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);  }
readln(n);
y:=0;
for i:= 1 to n do
  begin
    if (y<0) or (y>20000) then stop;
    readln(s);
    t:=pos(' ',s);
    w:=copy(s,1,t-1);
    val(w,d,h);
    if s[t+1]='N' then y:=y-d else
    if s[t+1]='S' then y:=y+d else
    if (y=0) and (s[t+1]<>'S') then stop else
    if (y=20000) and (s[t+1]<>'N') then stop;
    //writeln(d);
  end;
if y=0 then write('YES') else stop;
end.

var a:array[1..50] of string[6];
    b:array[1..50] of longint;
    i,s,n:longint;
    data:boolean;
begin
readln(n);
for i:=1 to n do begin
readln(b[i],a[i]);
if ((b[i]>20000)and(a[i]=' North')) or ((b[i]>20000)and(a[i]=' South'))then data:=true
end;
s:=0;
for i:=1 to n do begin
if (s<0)or(s>20000) then begin data:=true; break end;
if a[i]=
' South' then begin
        if s=20000 then begin data:= true; break end;
        inc(s,b[i]);
        end;
        if a[i]=
' North' then begin
        if s=0 then begin data:= true; break end;
        dec(s,b[i]);
        end;
        if a[i]=
' West' then begin
        if (s=0)or(s=20000) then begin data:= true; break end;
        end;
        if a[i]=
' East' then begin
        if (s=0)or(s=20000) then begin data:= true; break end;
        end;
end;
//if (s=0)and(r<>0) then data:=true;
if s<>0 then data:=true;
if data then writeln('NO')
         else writeln('YES')
end.

var
 s,t:string;
 n,m,i,k,j,f,c,x,y,z,q,w:longint;
 p:integer;
begin
 w:=10000;
 t:='YES';
 readln(n);
 for i:=1 to n do
 begin
  readln(s);
  val(copy(s,1,pos(' ',s)-1),f,p);
  s:=s[pos(' ',s)+1];
  if(s='W')or(s='E')then f:=0 else
  if s='S'then f:=-f;
  if((s='W')or(s='E'))and(abs(w)=10000)then t:='NO';
  if(w=10000)and(s<>'S')then t:='NO';
  if(w=-10000)and(s<>'N')then t:='NO';
  inc(w,f);
  if abs(w)>10000 then t:='NO';
 end;
 if w<>10000 then t:='NO';
 writeln(t);
end.

Var s:String;
    n,q,i,t:LongInt;
Begin
 readln(n);
 q:=0;
 for i:=1 to n Do
  Begin
   readln(t,s);
   if (q=0) and (s[2]<>'S')
    then begin
          write('NO');
          Exit;
         end;
   if (q=20000) and (s[2]<>'N')
    then Begin
          write('NO');
          Exit;
         end;
   if s[2]='N'
    then Begin
          if q-t<0
           then Begin
                 write('NO');
                 Exit;
                end;
          q:=q-t;
         end;
   if s[2]='S'
    then Begin
          if q+t>20000
           then Begin
                 write('NO');
                 Exit;
                end;
          q:=q+t;
         end;
  end;

 if q=0
  then write('YES')
  else write('NO');
End.

var i,j,m,n,now:longint;
    s:string;
begin
    readln(n);
    now:=20000;
    for i:=1 to n do begin
        read(m);
        readln(s);
        if s=' South' then begin
            now:=now-m;
            if now<0 then begin
                writeln('NO');
                halt;
            end;
        end else if s=' North' then begin
            now:=now+m;
            if now>20000 then begin
                writeln('NO');
                halt;
            end;
        end else begin
            if (now=0) or (now=20000) then begin
                writeln('NO');
                halt;
            end;
        end;
    end;
    if now=20000 then writeln('YES') else writeln('NO');
    //writeln(s);
end.

var n,res:byte;
    t:array[0..50] of longint;
    dir:array[0..50] of string;

procedure solve;
var NS:longint; i:byte;
begin
    NS:=0; res:=1;
    for i:=1 to n do
    begin
        if dir[i]=' North' then
        begin
            if NS=0 then begin res:=0; break; end;
            if t[i]>NS then begin res:=0; break; end;
            NS:=NS-t[i];
        end
        else if dir[i]=' South' then
        begin
            if NS=20000 then begin res:=0; break; end;
            if t[i]>20000-NS then begin res:=0; break; end;
            NS:=NS+t[i];
        end
        else if ((dir[i]=' West') or (dir[i]=' East')) and ((NS=0) or (NS=20000)) then begin res:=0; break; end;
    end;
    if NS<>0 then res:=0;
end;

procedure input;
var i:byte; tmp:string;
begin
    readln(n);
    for i:=1 to n do
    begin
        readln(t[i],dir[i]);
    end;
end;

procedure output;
begin
    if res=0 then writeln('NO') else writeln('YES');
end;

begin
    input;
    solve;
    output;
end.

program B750;

var
  p    : Int64;
  n, i : integer;
  c    : integer = 0;
  s    : string;
begin
  read(n);
  for i := 1 to n do begin
    readln(p, s);
         if ((c = 0) or (c = 20000)) and ((s = ' West') or (s = ' East')) then begin writeln('NO'); exit; end
    else if  (c = 0)                 and (s = ' North')                   then begin writeln('NO'); exit; end
    else if  (c = 20000)             and (s = ' South')                   then begin writeln('NO'); exit; end
    else if  (s = ' North')          and (p > c)                          then begin writeln('NO'); exit; end
    else if  (s = ' South')          and (p + c > 20000)                  then begin writeln('NO'); exit; end
    else if   s = ' North'                                                then c := c - p
    else if   s = ' South'                                                then c := c + p
  end;
  if c <> 0 then writeln('NO') else writeln('YES');
end.

var
 a,m,j,i,n,g,posi : longint;
 s,tempat,s1,ch : string;
 b : boolean;
begin
 tempat:='South';
 posi:=0;
 readln(n);
 ch:=' ';
 //readln(s1);
 //writeln(pos(ch,s1));
 b:=true;
  for i:= 1 to n do
   begin
    readln(a,s1);
    m:=pos(ch,s1);
    s:=copy(s1,m+1,length(s1)-m+1);
    //writeln(s);
    if b then
     begin
      if posi=0 then
       begin
        //writeln('#1');
        if (tempat=s) then
         begin
          posi:=posi+a;
          if posi=20000 then
           begin
            if tempat='South' then
             tempat:='North'
            else
             tempat:='South';
            posi:=0;
           end
          else
           if posi>20000 then
            b:=false;
          //writeln('posi sekarang ',posi);
          //writeln('tempat sekarang ',tempat);
         end
        else
         b:=false;
       end
      else
        begin
         //writeln('#2');
         if tempat=s then
          begin
           posi:=posi+a;
           if posi=20000 then
            begin
             if tempat='North' then
              tempat:='South'
             else
              tempat:='North';
              posi:=0;
            end
           else
            if (posi>20000) or (posi<0) then
             b:=false;
            //writeln('posi sekarang ',posi);
            //writeln('tempat sekarang ',tempat);
          end
         else
          if (tempat<>s) and ((s<>'West') and (s<>'East')) then
           begin
            posi:=posi-a;
            if (posi<0) then
             b:=false;
            //writeln('posi sekarang ',posi);
            //writeln('tempat sekarang ',tempat);;
           end;
    end;
   end;
  end;
  //writeln(b);
  if not b then
   writeln('NO')
  else
   if (tempat='South') and (posi=0) then
    writeln('YES')
   else
    writeln('NO');
end.

Program cf1;
Var
    north,south,i,j,k,nums,code:longint;
    sn,s,test:string;
    fl:boolean;
Begin
    //assign(input,'input.txt'); reset(input);
    //assign(output,'output.txt'); rewrite(output);

    readln(k);

    south:=20000; north:=0; fl:=false;

    for i:=1 to k do Begin
        readln(s);
        nums:=0;
        sn:='';
        j:=1;
        while (s[j] <> ' ') do Begin
            sn:=sn + s[j];
            inc(j);
        End;
        val(sn,nums,code);
        test:=copy(s,j+1,length(s)-j);

        if (nums > south) and (test = 'South') then Begin
            fl:=true;
            break;
        End;

        if (nums > north) and (test = 'North') then Begin
            fl:=true;
            break;
        End;

        nums:=nums mod 40000;

        if ((north = 0) or (north = 40000) or (south = 20000)) and (test <> 'South') then Begin
            fl:=true;
            break;
        End;

        if ((south = 0) or (south = 40000) or (north = 20000)) and (test <> 'North') then Begin
            fl:=true;
            break;
        End;

        if (test = 'South') then Begin
            dec(south,nums);
            inc(north,nums);
        End else if (test = 'North') then Begin
            dec(north,nums);
            inc(south,nums);
        End;
    End;

    if ((north = 0) or (north = 40000) or (south = 20000)) and (fl = false) then write('YES') else write('NO');
End.

var     s,n:longint;      kq:string[3];
procedure Nhap;
var     x,i:longint;      y:string[6];
begin
        read(n);
        for i:=1 to n do
        begin
                read(x,y);
                if ((s=10000) or (s=-10000)) and ((y=' East') or (y=' West')) then exit;
                if y=' North' then
                        inc(s,x)
                else if y=' South' then
                        dec(s,x);
                if (s>10000) or (s<-10000) then
                        exit;
        end;
        if s=10000 then
                kq:='YES';
end;
procedure Xuat;
begin
        write(kq);
end;
begin
        kq:='NO';
        s:=10000;
        Nhap;
        Xuat;
end.

USES Math;
CONST
    tfi = '';
    tfo = '';
VAR
    fi,fo               : text;

Procedure process;
    Var
        n,tmp,cnt,i,j: longint;
        s,p
        : string;
    Begin
        Readln(fi,n);
        tmp:=0;
        For i:=1 to n do
            begin
                readln(fi,s);
                If s[length(s)]=' ' then delete(s,length(s),1);
                cnt:=0;
                j:=1;
                While s[j]<>' ' do
                    begin
                        cnt:=cnt*10+ord(s[j])-48;
                        inc(j);
                    end;
                p:=copy(s,j+1,length(s)-j);
                If ((tmp=0) and (p<>'South')) or ((tmp=20000) and (p<>'North')) then
                    begin
                        write(fo,'NO');
                        exit;
                    end;
                If p='North' then dec(tmp,cnt)
                else if p='South' then inc(tmp,cnt);
                If (tmp<0) or (tmp>20000) then
                    begin
                        write(fo,'NO');
                        exit;
                    end;
            end;
        If tmp=0 then write(fo,'YES')
        else write(fo,'NO');
    End;

BEGIN
    assign(fi,tfi); reset(fi);
    assign(fo,tfo); rewrite(fo);
        process;
    close(fi); close(fo);
END.

const fi='ny_npole.inp';
      fo='ny_npole.out';
var n: longint;
function tinh: boolean;
  var i, np, t: longint;
      s: string;
  begin
    np:=0;
    for i:=1 to n do
      begin
        read(t); readln(s);
        if s[1]=' ' then delete(s,1,1);
        {case s of}
        if s='North' then
            begin
              if np=0 then exit(false)
              else if t>np then exit(false)
              else if np-t<0 then exit(false)
              else np:=np-t;
            end
        else if s='South' then
            begin
              if np=20000 then exit(false)
              else if t>(20000-np) then exit(false)
              else if t+np>20000 then exit(false)
              else np:=np+t;
            end
        else if (np=0) or (np=20000) then exit(false);
      end;
    if np=0 then exit(true)
    else exit(false);
  end;
begin
  //assign(input, fi); reset(input);
  //assign(output, fo); rewrite(output);
  readln(n);
  if tinh then writeln('YES')
  else writeln('NO');
  //close(input); close(output);
end.

{$H+}
var st,s,huong:string;   n:longint;
procedure nhap;
var i,tt,j,point:longint; x:longint;
begin
 readln(n);   point:=0;
 for i:=1 to n do
  begin
   readln(st);
   s:='';   tt:=0;  x:=0;
   for j:=1 to length(st) do
   if st[j]=' ' then
    begin
     val(s,x);
     tt:=j;
     break;
    end
   else  s:=s+st[j];
   inc(tt);  huong:='';
   while (st[tt]<>' ')  do
    begin
     huong:=huong+st[tt];
     inc(tt);
     if tt>length(st) then break;
    end;
   if (point<0) or (point>20000) then
    begin
     write('NO');
     exit;
    end
   else
   if (point=0) then
    begin
     if huong='South' then point:=point+x
     else
      begin
       write('NO');
       exit;
      end;
    end
   else
   if (point=20000) then
    begin
     if huong='North' then point:=point-x
     else
      begin
       write('NO');
       exit;
      end;
    end
   else
    begin
     if huong='South' then point:=point+x;
     if huong='North' then point:=point-x;
    end;
  end;
 if (point=0) then write('YES')
 else write('NO');
end;
begin
 //assign(input,'b750.inp');reset(input);
 nhap;
 //close(input);
end.

var n : longint;
        x, y: array[0..1000000] of longint;
     i,j,s : longint; Ss: string[2];// s : string;
begin
        reaD(n);
        for i:=1 to n do
        begin
                readln;
                read(x[i], ss);
                if ss[2] = 'N' then y[i]:= 1;
                if ss[2] = 'S' then y[i]:= 2;
                if ss[2] = 'E' then y[i]:= 3;
                if ss[2] = 'W' then y[i]:= 4;
        end;
        S:=0;
        for i:=1 to n do
        begin
                if (s = 20000) and ( y[i] <> 1) then
                begin
                        write('NO');
                        exit;
                end;
                if ( s = 0 ) and ( y[i] <> 2 ) then
                begin
                        write('NO');
                        exit;
                end;
                if y[i] =2 then s:= s + x[i]
                else if y[i] =1 then s:= s- x[i];
                if ( s > 20000 ) then
                begin
                        write('NO');
                        exit;
                end;
                if ( s < 0 ) then
                begin
                        write('NO');
                        exit;
                end;
        end;
        if s= 0 then write('YES') else write('NO');
end.

var
  x,xx,y,n,_,yy : longint;
  s : ansistring;
  fk : boolean;

begin
  fk:=false;
  readln(n); x:=20000;
  while n > 0 do begin
    readln(s);
    val(copy(s,1,pos(' ',s)-1),xx,_);
    delete(s,1,pos(' ',s));
    if s = 'South' then begin
      x:=x+xx;
      if x > 40000 then fk:=true;
    end;
    if s = 'East' then begin
      if (x = 20000) or (x = 40000) then fk:=true;
    end;
    if s = 'North' then begin
      x:=x-xx;
      if x < 20000 then fk:=true;
    end;
    if s = 'West' then begin
      if (x = 20000) or (x = 40000) then fk:=true;
    end;
    dec(n);
  end;
  if (x = 20000) and (not fk) then writeln('YES') else writeln('NO');
end.

var n,i,a,s,l:longint;
    s1:string;
begin
readln(n);
for i:=1 to n do
begin
read(l);
readln(s1);
//write(s1[1]);
if s1[2]='N' then dec(s,l);
if s1[2]='S' then inc(s,l);
if ((s1[2]='W') or (s1[2]='E')) and ((s=0) or (s=20000))  then begin write('NO'); halt; end;
if (s<0) or (s>20000) then begin write('NO'); halt; end;
end;
if s=0 then write('YES') else write('NO');
end.

var st,a,c:string;
n,i,x,w,s,p:longint;
b:array[1..60] of string;
begin
  readln(n);
  for i:=1 to n do
    begin
      readln(st);
      b[i]:=st;
    end;
  w:=1;
  for i:=1 to n do
    begin
      st:=b[i];
      p:=pos(' ',st);
      a:=copy(st,1,p-1);
      val(a,x);
      c:=st[p+1];
      if c='S' then begin
                      if w<>3 then s:=s+x
                        else begin
                               writeln('NO');
                               halt;
                             end;
                      if s>20000 then begin
                                        writeln('NO');
                                        halt;
                                      end;
                      if s=20000 then begin
                                        w:=3;
                                      end
                      else w:=2;
                    end
      else if c='N' then begin
                           if w<>1 then s:=s-x
                             else begin
                                    writeln('NO');
                                    halt;
                                  end;
                           if s<0 then begin
                                         writeln('NO');
                                         halt;
                                       end;
                           if s=0 then w:=1
                             else w:=2;
                         end
      else begin
             if w<>2 then begin
                            writeln('NO');
                            halt;
                          end;
           end;
    end;
  if s=0 then writeln('YES')
    else writeln('NO');
end.

Var
        n:longint;
        ok:boolean;
Procedure Enter;
Var
        n,i,d,x,y:longint;
        way:String;
Begin
        readln(n);
        ok:=true;
        x:=0;y:=10000;
        For i:=1 to n do
        Begin
         readln(d,way);
         delete(Way,1,1);
         if way='South' then
         Begin
          y:=y-d;
          if y<-10000 then
           Begin
            ok:=false;
            break;
           End;
         End
         else
         if way='East' then
         Begin
          if abs(y)=10000 then
          Begin
           ok:=false;
           break;
          End;
          x:=x+d;
          x:=x mod 40000;
         End
         else
         if way='North' then
         Begin
          y:=y+d;
          if y>10000 then
           Begin
            ok:=false;
            break;
           End;
         End
         else
         if way='West' then
         Begin
          if abs(y)=10000 then
          Begin
           ok:=false;
           break;
          End;
          x:=x-d;
          x:=x mod 40000;
         End;
        End;
        if ( ok) and (y=10000) then writeln('YES') else writeln('NO');
End;

Begin
        Enter;
End.

program q;
var n, m,count, i: longint;
f : boolean;
s : string;
begin
	count := 0;
    f := true;
    readln(n);
    for i := 1 to n do
    begin
            read(m, s);

            if s =' North' then begin
            	if count = 0 then f := false;

            	count := count - m;
            	if count < 0 then f := false;
            end;
            if s = ' South'then begin
            	if count = 20000 then f := false;
            	count := count + m;

            	if count > 20000 then f := false;
            end;
            if s =' West' then begin
                if count = 0 then f := false;
                if count = 20000 then f := false;

            end;
            if s =' East'then begin
            	if count = 0 then f := false;
            	if count = 20000 then f := false;

            end;
    end;

    if f = true then
    begin
    if count = 0 then write('YES')
    else write('NO');
    end
    else write('NO');

end.

program z1;
var a,b,c,d,i,j,k,l,m,n,pos:longint; s:string;
begin
//assign(input,'d:\input.txt'); reset(input);
//assign(output,'d:\output.txt'); rewrite(output);
readln(n);
pos:=0;
for i:=1 to n do
 begin
 readln(a,s);
 if ((pos=0) or (pos=20000)) and (a>20000) then begin write('NO'); exit; end;
 if (s=' East') or (s=' West') then if (pos=0) or (pos=20000) then begin write('NO'); exit; end;
 if s=' North' then if (pos=0) or (a>pos) then begin write('NO'); exit; end else pos:=pos-a;
 if s=' South' then if (pos=20000) or (a>20000-pos) then begin write('NO'); exit; end else pos:=pos+a;
 end;
if pos<>0 then write('NO') else
writeln('YES');
end.

var
i,n:integer;

a:array [1..50] of integer;
b:array [1..50] of string;
c:char;

x,y:integer;

g:byte;
begin
read(n);

x:=0; y:=0;
g:=0;

for i:=1 to n do begin
read(a[i]); read(c);  read(b[i]);
end;

for i:=1 to n do begin

if (x=0) and (b[i]<>'South') then g:=1;

if (x=20000) and (b[i]<>'North') then g:=1;

if b[i]='North' then dec(x,a[i]);
if b[i]='South' then inc(x,a[i]);
if b[i]='West' then dec(y,a[i]);
if b[i]='East' then inc(y,a[i]);

if x<0 then g:=1;
if x>20000 then g:=1;

if (i=n)and(x<>0) then g:=1;
end;

if g=1 then writeln('NO') else writeln('YES');

end.

var n,i,j,put,vert,f:integer;
   s,napr:string;
begin
read(n); f:=0; vert:=0;
for i:=1 to n do begin
 read(put,napr);
 delete(napr,1,1);
 if (put>20000) and (napr<>'East') and (napr<>'West') then f:=1;
 if (vert=20000) and (napr<>'North') then f:=1;
 if (vert=0) and (napr<>'South') then f:=1;
 if napr='South' then vert:=vert+put;
 if vert>20000 then f:=1;
 if napr='North' then vert:=vert-put;
 if vert<0 then f:=1;
 if f=1 then break;
end;
if vert<>0 then f:=1;
if f=1 then write('NO') else write('YES');
end.

var r:boolean;
n,ns,t,i:longint;
dir:string;
begin
readln(n);
r:=true;
for i:=1 to n do
        begin
        readln(t,dir);
        if ns=0 then
                if dir<>' South' then r:=False;
        if ns=20000 then
                if dir<>' North' then r:=False;
        if dir=' South' then
                ns:=ns+t;
        if dir=' North' then
                ns:=ns-t;
        if ns>20000 then
                r:=false;
        if ns<0 then
                r:=false;
        end;
if ns<>0 then r:=False;
if r=false then write('NO')
        else write('YES');
end.

var
  n,i,p,t:longint;
  d:string;
begin
  read(n);
  for i:=1 to n do
    begin
      readln(t,d);
      if d[2] in ['E','W']
      then if (p=0) or (p=20000)
           then begin writeln('NO');halt;end
           else continue;
      if d[2]='S' then inc(p,t) else dec(p,t);
      if (p<0) or (p>20000)
      then begin writeln('NO');halt;end;
    end;
  if p=0 then writeln('YES') else writeln('NO');
end.

Program z2;
var
    n,k,m,t,v:integer;
    i,j:integer;
    f:boolean;
    s,mt:string;
begin
    readln(n);
    f:=true;
    k:=0;
    for i:=1 to n do begin
        readln(s);
        if f=true then
            if s[length(s)]='h' then begin
                mt:=copy(s,1,length(s)-6);
                t:=length(mt);
                v:=1;
                m:=0;
                for j:=t downto 1 do begin
                    m:=m+(ord(mt[j])-48)*v;
                    v:=v*10;
                end;
                if s[length(s)-2]='r' then m:=-m;
                if ((k+m)<0)OR((k+m)>20000)OR((k=0)AND(m<0))OR((k=20000)AND(m>0)) then f:=false;
                k:=k+m;
            end else if (k=0)OR(k=20000) then f:=false;
    end;
    if k<>0 then f:=false;
    if f=false then write('NO') else write('YES');
end.

  const eps=0.00000001;  besk=200000008;  nn=200000;
   label 1,2,3;
    type   { real=double;}  {string=ansistring;}
    mas=array [0..nn] of longint;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var mmin,kk,gr,ttt,t,kol,pos,x1,x2,p,z,pmax,imax,p1,p2,p3,p4,l,ot,nm,n,s1,s2,m,s,smin,cen,dl,t2,i1:int64;
    oldnapgor,oldnapver,napgor,napver,dist,xmin,xmax,ymin,ymax,napx,napy,time,pp,jj,step, t1,ii,i,tt,j:longint;
     aa,bb,cc:double;
     d,k,x,y,aold,b,a:array[-10..10000002] of int64;
     dda:array[-10..1200,-10..1200] of int64;
   zanx,zany:array[-10..200000] of boolean;
   polog:array[-10..200004, 0..5] of int64;
    zam:array[-10..300,-10..300] of boolean;
    ss, ss1,ss2:array[-1000..1000000] of string;
     zan,fl:array[-10000..600000] of boolean;
    sss:string;ch:char;
    pole :array [-10..2000,-10..2000] of char;
    maxpr:array[0..nn] of string;
    st2:array[0..nn] of string;
     v0,v1,s0,t0:real;
     zv:point;
     newx,newy,xx,yy:array[-1..200000] of int64;

     yot:double;
       oldflag,flag,flag1:boolean;
    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:int64):int64;begin min:=x;if y<x then min:=y; end;
  function max(x,y:int64):int64;begin max:=x;if y>x then max:=y; end;

  function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

begin
   { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
    }
     readln(n);
    for i:=1 to n do begin read(a[i]);read(ch);readln(ss[i]);  end;
  { for i:=1 to n do write(ss[i]);
   }

   flag:=true;
   if ss[1]<>'South' then flag:=false;
   for i:=1 to n do
     begin
     {  writeln('step= ',i,' ',flag);
     }  if (ss[i]='North')or (ss[i]='South') then
       begin
        if ss[i]='North' then ot:=ot-a[i];
        if ss[i]='South' then ot:=ot+a[i];
        if (ot<0) then flag:=false;
        if (ot>20000) then flag:=false;
        if (i<n)and(ot=0)and(ss[i+1]<>'South') then flag:=false;
        if (i<n)and(ot=20000)and(ss[i+1]<>'North') then flag:=false;

       end;
       if (ot<0) then flag:=false;
        if (ot>20000) then flag:=false;
        if (i<n)and(ot=0)and(ss[i+1]<>'South') then flag:=false;
        if (i<n)and(ot=20000)and(ss[i+1]<>'North') then flag:=false;

     {  writeln(i,' ',flag,' ot= ',ot);
    } end;
   if ot<>0 then flag:=false;
   if flag then write('YES') else write('NO');

   1:          close(output);
end.

program test;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n, i, x, t: integer;
  c: char;
  s: string;
  b: boolean;

begin
  readln(n);
  x := 20000;
  b := true;
  for i := 1 to n do begin
    read(t);
    read(c);
    readln(s);
    if ((s = 'East') or (s = 'West')) and ((x = 0) or (x = 20000)) then
      b := false;
    if (s = 'North') then
      inc(x, t)
    else if (s = 'South') then
      dec(x, t);
    if (x > 20000) or (x < 0) then
      b := false;
  end;
  if (x = 20000) and (b) then
    writeln('YES')
  else
    writeln('NO');
  readln;
end.

var aa,aa1:int64; suk:string; j,nom:longint;
a:array[1..1000] of longint;
dddd:int64;
d:boolean;
begin

read(nom);
for j:=1 to nom do
begin
read(aa);
readln(suk);
if  ((aa1=20000) and (suk<>' North')) or ((aa1=0) and (suk<>' South'))
 then begin writeln('NO'); exit; end;
 if suk=' North' then aa1:=aa1-aa;
if suk=' South' then aa1:=aa1+aa;

if (aa1>20000)  or (aa1<0) then begin writeln('NO'); exit; end;
end;
if aa1<>0 then writeln('NO')
else writeln('YES');
end.

program Project5;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;
var i,n,k,res,x,y:longint;
flag:boolean;
s:String;
begin
 readln(n);
 x:=0;
 y:=0;
 flag:=false;
 for i:=1 to n do
  begin
   readln(k,s);
   if (x=0) and (s<>' South') then flag:=true;
   if (x=20000) and (s<>' North') then flag:=true;
   if s=' North' then
    begin
     x:=x-k;
     if x<0 then flag:=true;
    end else
   if s=' South' then
    begin
     x:=x+k;
     if x>20000 then flag:=true;
    end;
  end;
  if x<>0 then flag:=true;
  if flag then writeln('NO') else writeln('YES');
 readln;
 readln;
end.

program zxc;
var n,i,o:longint;
a:array[1..50] of longint;
b:array[1..50] of string;
begin
readln(n);
for i:=1 to n do
read(a[i],b[i]);
o:=0;
if b[1][2]<>'S' then begin writeln('NO'); exit; end;
for i:=1 to n do begin
if (b[i][2]<>'N') and (o=-20000) then begin writeln('NO'); exit; end;
if (b[i][2]<>'S') and (o=0) then begin writeln('NO'); exit; end;
if (b[i][2]='S') and (o-a[i]<-20000) then begin writeln('NO'); exit; end;
if (b[i][2]='N') and (o+a[i]>0) then begin writeln('NO'); exit; end;
if b[i][2]='S' then o:=o-a[i];
if b[i][2]='N' then o:=o+a[i];
end;
if o<>0 then begin writeln('NO'); exit; end;
if o=0 then writeln('YES');
end.

program cf750B;
var n,i,t,km:longint;
    rez,s:string;
begin
readln(n);
t:=0;
rez:='YES';
for i:=1 to n do
        begin
        readln(km,s);
        if (t=0) and (s[2]<>'S') then
                rez:='NO';
        if (t=20000) and (s[2]<>'N') then
                rez:='NO';

        if (t+km>20000) and (s[2]='S') then
                rez:='NO';

        if (t-km<0) and (s[2]='N') then
                rez:='NO';

        if s[2]='S' then
                t:=t+km;
        if s[2]='N' then
                t:=t-km;
        end;

if t<>0 then
        rez:='NO';

writeln(rez);

end.

var
a:array [1..1000000] of integer;
s,i,n:integer;
np,sp:boolean;
p: array [1..1000000] of string;
begin
read (n);
for i:=1 to n do begin
read (a[i]); readln (p[i]); end;
for i:=1 to n do begin
if  s=0 then
if p[i]<>' South' then begin write ('NO'); exit; end;
if s=20000 then
if p[i]<>' North' then begin write ('NO'); exit; end;
if p[i]=' South' then begin s:=s+a[i]; end else if p[i]=' North' then s:=s-a[i];
if (s<0) or (s>20000) then begin write ('NO'); exit; end;
end;
if s<>0 then write ('NO')
else write ('YES');
end.

var
  n, i, sum, v,f,f1: longint;
  s: string;

begin
  readln(n);
  for i := 1 to n do
  begin
    read(v);
        readln(s);
    if ((sum = 0) and (s <> ' South'))  or ((sum = 20000) and (s <> ' North')) then
                                        begin
                                         f:=1;
                                          end;
    if s = ' South' then sum := sum + v;
          if s = ' North' then sum := sum - v;

    if (sum < 0) or (sum> 20000) then begin f1:=1; end;
  end;
  if f=1 then begin  writeln('NO'); exit; end;
  if f1=1 then begin writeln('NO'); exit; end;
  if sum = 0 then writeln('YES')
  else writeln('NO');
end.

var n,i,a,s,l:longint;
    s1:string;
begin
readln(n);
for i:=1 to n do
begin
read(l);
readln(s1);
//write(s1[1]);
if s1[2]='N' then dec(s,l);
if s1[2]='S' then inc(s,l);
if ((s1[2]='W') or (s1[2]='E')) and ((s=0) or (s=20000))  then begin write('NO'); halt; end;
if (s<0) or (s>20000) then begin write('NO'); halt; end;
end;
if s=0 then write('YES') else write('NO');
end.

program hsfdk;
var n,i:integer;
    td,so:longint;
    st:string;
    kt:boolean;
begin
   readln(n); kt:=true;
   td:=0;
    for i:=1 to n do
     begin
      readln(so,st);
      if kt=true then
      begin
      if(td=0)and(st<>' South')
      or(td=20000)and(st<>' North')then kt:=false;
       if st=' North'then td:=td-so
       else if st=' South'then td:=td+so;
       if(td<0)or(td>20000)then kt:=false;
      end;
     end;
     if td<>0 then kt:=false;
     if kt=true then write('YES')
     else write('NO');
     readln
end.

var n,i,t: longint;
    x: longint = 0;
    dir: string;
begin
    read(n);
    for i:=1 to n do
    begin
        read(t); readln(dir);
        if dir=' North'
           then dec(x,t)
        else if dir=' South'
             then inc(x,t)
        else if (x=0)or(x=20000)
             then begin
                 write('NO');
                 exit;
             end;
        if (x<0)or(x>20000) then
        begin
            write('NO');
            exit;
        end;
    end;
    if x=0 then write('YES') else write('NO');
end.

var
  dir,len:array[1..100]of longint;
  n,now,i:longint;
  flag:boolean;
  s:string;
begin
  readln(n);
  now:=0;
  flag:=true;
  for i:=1 to n do
    begin
      readln(len[i],s);
      while(s[1]=' ')do
        delete(s,1,1);
      if(s[1]='S')then dir[i]:=1;
      if(s[1]='N')then dir[i]:=-1;
      if(s[1]='E')or(s[1]='W')then dir[i]:=0;
	  if(now=0)and(dir[i]<1)then flag:=false;
          if(now=20000)and(dir[i]>-1)then flag:=false;
	  now:=now+dir[i]*len[i];
	  if(now<0)or(now>20000)then flag:=false;
  end;
  if(now<>0)then flag:=false;
  if(not flag)then writeln('NO')
  else writeln('YES');
end.

program j01;
var n,i:longint;
    now,x:longint;
    flag:boolean;
    s:string;
begin
  now:=0;
  readln(n);flag:=true;
  for i:=1 to n do
  begin
    read(x);
    readln(s);
    if (now=0)and(s[2]<>'S') then flag:=false;
    if(now=20000)and(s[2]<>'N') then flag:=false;
    if s[2]='N' then now:=now-x;
    if now<0 then flag:=false;
    if s[2]='S' then now:=now+x;
    if now>20000 then flag:=false;
  end;
  if  (now=0)and flag then writeln('YES') else writeln('NO');
end.

Program b;
uses sysutils;
Var
        n,i,l:Integer;
        t:Int64;
        dir:string;
        u,d:boolean;
begin
        readln(n);
        d:=true;
        l:=20000;
        for i:=0 to n-1 do
                begin
                readln(t,dir);
                dir:=Trim(dir);
                if((d=true) and (dir<>'South')) then
                        begin
                        writeln('NO');
                        exit;
                        end;
                if((u=true) and (dir<>'North')) then
                        begin
                        writeln('NO');
                        exit;
                        end;
                if dir='North' then l:=l+t;
                if dir='South' then l:=l-t;
                if((l>20000) or (l<0)) then
                        begin
                        writeln('NO');
                        exit;
                        end;
                if(l=20000)then
                        begin
                        d:=true;
                        u:=false;
                        end
                else if(l=0) then
                        begin
                        u:=true;
                        d:=false;
                        end
                else
                        begin
                        d:=false;
                        u:=false;
                        end;
                end;
        if l=20000 then writeln('YES')
        else writeln('NO');
        readln;
end.

var
  n, x, y, sd, i: longint;
  s: string;

procedure sphalt;
begin
  writeln('NO');
  halt(0);
end;

begin
  readln(n);
  for i := 1 to n do
  begin
    read(sd);
    readln(s);
    if (y <= 0) and (s <> ' South') then
      sphalt;
    if (y >= 20000) and (s <> ' North') then
      sphalt;
    if s = ' South' then
      inc(y, sd);
    if s = ' North' then
      dec(y, sd);
    if s = ' West' then
      inc(x, sd);
    if s = ' East' then
      dec(x, sd);
    if (y < 0) or (y > 20000) then
      sphalt;
  end;
  if (y <> 0) then
    sphalt;
  writeln('YES');
end.

var
  n,i,p,t:longint;
  d:string;
begin
  read(n);
  for i:=1 to n do
    begin
      readln(t,d);
      if d[2] in ['E','W']
      then if (p=0) or (p=20000)
           then begin writeln('NO');halt;end
           else continue;
      if d[2]='S' then inc(p,t) else dec(p,t);
      if (p<0) or (p>20000)
      then begin writeln('NO');halt;end;
    end;
  if p=0 then writeln('YES') else writeln('NO');
end.

var c,cs,n:integer;s:string;i:integer;
begin
readln(n);
cs:=0;
For i:=1 to n do
 begin
  readln(c,s);
  If (s=' South')and(cs+c>20000)
   then begin writeln('NO');exit;end;
  If (s=' North')and(cs-c<0)
   then begin writeln('NO');exit;end;
  If cs=0 then if s<>' South'
   then begin writeln('NO');
              exit;
        end;
  If cs=20000 then if s<>' North' then begin writeln('NO');exit;end;
  If (s=' South') then cs:=cs+c;
  If (s=' North') then cs:=cs-c;
  If cs > 0 then begin
                   cs:=cs mod 40000;
                   If cs>20000 then cs:=-cs;
                 end
            else begin
                  cs:=cs mod 40000;
                  If cs>=-20000 then cs:=-cs;
                 end;
 end;
If cs=0 then writeln('YES') else writeln('NO');
end.

var n,i,s,c:longint; t:string;
begin
      read(n);
      for i:=1 to n do
      begin
       read(c); readln(t);
       if ((s=0) and (t<>' South')) or ((s=20000) and (t<>' North')) then begin writeln('NO'); exit; end;
       if t=' South' then s:=s+c;
       if t=' North' then s:=s-c;

       if (s<0) or (s>20000) then begin writeln('NO'); exit; end;
      end;
      if s=0 then writeln('YES')
              else writeln('NO');
end.

var
a:array [1..10] of integer;
s,i,n:integer;
np,sp:boolean;
p: array [1..10] of string;
begin
read (n);
for i:=1 to n do begin
read (a[i]); readln (p[i]); end;
for i:=1 to n do begin
if  s=0 then
if p[i]<>' South' then begin write ('NO'); exit; end;
if s=20000 then
if p[i]<>' North' then begin write ('NO'); exit; end;
if p[i]=' South' then begin s:=s+a[i]; end else if p[i]=' North' then s:=s-a[i];
end;
if s<>0 then write ('NO')
else write ('YES');
end.

 var t, p, n, i, x: longint;
s: string;
begin
readln (n);
if n=5 then begin for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
end;
if n=2 then begin for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 write (' ',p, ' ');
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
write (' ',p, ' ');
end;
end.

const
        fi='';
        fo='';
var     f:text;
        n,x,ans,ec:longint;
        huong,dis:array[1..5000] of longint;
        ok:boolean;
{}
procedure docf;
var     st1,st2,st:string;
        i,j,u,v,er:longint;
begin
        assign(f,fi); reset(f);
        readln(f,n);
        for j:=1 to n do
        begin
                readln(f,st);
                while st[length(st)]=' ' do delete(st,length(st),1);

                i:=1;  st1:='';
                while st[i] <> ' ' do begin
                        st1:=st1+st[i]; inc(i); end;
                val(st1,u,er);
                inc(i); st2:='';
                while (i <= length(st)) do begin
                        st2:=st2+st[i]; inc(i); end;

                if st2='North' then v:=0
                else if st2='South' then v:=1
                else v:=2;

               // if v < 2 then
                begin
                        inc(ec);
                        huong[ec]:=v;
                        dis[ec]:=u;
                end;
        end;
end;
{}
procedure lam;
var     i:longint;
        np,sp:boolean;
begin
        //North = 0 , South =  1
        ok:=false;  np:=true; sp:=false;
        for i:=1 to ec do
        begin
                if np then
                begin
                        if huong[i]<>1 then exit;
                        inc(x, dis[i]);  np:=false;
                        if x > 20000 then exit;
                end
                else if sp then
                begin
                        if huong[i]<>0 then exit;
                        dec(x, dis[i]); sp:=false;
                        if x < 0 then exit;
                end
                else begin
                        if huong[i]=0 then dec(x, dis[i])
                        else if huong[i]=1 then inc(x,dis[i]);
                end;

                if (x > 0) and (x < 20000) then begin
                        np:=false; sp:=false; end
                else if (x=0) then np:=true
                else if x=20000 then sp:=true;
        end;

        if x=0 then ok:=true;
end;
{}
procedure xuat;
begin
        assign(f,fo); rewrite(f);
        if ok then writeln(f,'YES')
        else writeln(f,'NO');
        close(F);
end;
{}
begin
        docf;
        lam;
        xuat;
end.

const fi='';
    fo='';
procedure process;
var  s:longint;
    l:1..40000;
    n,i:1..50;
    a:string;
    f,g:text;
begin
    s:=0;
    assign(f,fi);reset(F);
    assign(g,fo);rewrite(g);
    readln(F,n);
    for i:=1 to n do
    begin
        read(f,l);readln(f,a);
        delete(a,1,1);
        if (a[1]='N') then dec(s,l);
        if (a[1]='S') then inc(s,l);
        if (( (a[1]='W') or (a[1]='E') ) and ( (s=0) or (s=20000) )) or ( (s<0) and (s>20000) )  then
        begin
            writeln(g,'No');
            close(F);
            close(g);
            exit;
        end;
    end;
    if (s=0) then write(g,'Yes') else write(g,'No');
    close(F);
    close(g);
end;
begin
    process;
end.

var ch,i,n,x,q,y,p,w:longint;
    f:boolean;
    s:string;
    a:array[1..100] of longint;
begin
 readln(n);
 x:=0;
 y:=0;
 p:=0;
 f:=true;
 for i:=1 to n do
 begin
  readln(s);
  val(s,ch,q);
  w:=q;
  val(copy(s,1,q-1),ch,q);
  s:=copy(s,w+1,length(s)-w);
  if (p=2)and(s[1]<>'N') then
   f:=false;
  if (p=1)and(s[1]<>'S') then
   f:=false;
  p:=0;
  a[i]:=ch;
  case s[1] of
  'N':  dec(y,ch);
  'E':  dec(x,ch);
  'S':  inc(y,ch);
  'W':  inc(x,ch);
  end;
  x:=abs(x mod 40001);
  if y<0 then
  f:=false;
  if (y<=0) then
   p:=1;
  if (y>=20000) then
   p:=2;

 end;
 if y<>0 then
 f:=false;
 if f then
 writeln('YES') else
 writeln('NO');
end.

var n,i,j,k,t,l,r,d,x,y:longint;
m:longint;
dir:string;
flag: integer;
begin
readln(n);
flag:=1;
y:=0;
i:=1;
while ((i<=n)and(flag=1)) do begin
    readln(t,dir);
 //   writeln(pos('North',dir),' ',dir);
    if ((pos('South',dir)=0)and(y=0)) then flag:=-1
    else if ((pos('North',dir)=0)and(y=20000)) then flag:=-1
    else if (pos('South',dir)>0)or(pos('North',dir)>0) then begin
        if pos('South',dir)>0 then y:=y+t;
        if pos('North',dir)>0 then y:=y-t;
        while ((y<0)or(y>20000)) do begin
            if (y<0) then y:=abs(y);
            while y>=40000 do y:=y-40000;
            if (y<0) then y:=abs(y);
            if y>20000 then y:=20000-(y-20000);
            while y>=40000 do y:=y-40000;
            if (y<0) then y:=abs(y);
        end;
    end;
    i:=i+1;
 //   writeln(i,' ',y,' ',flag);
end;
if ((abs(y) mod 40000)<>0) then flag:=-1;
if (flag=-1) then writeln('NO')
else writeln('YES');
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

 var t, p, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

const fi='';//750B.inp';
      fo='';//750B.out';

var n:longint;

procedure doc;
   var i,k,d,x:longint;
       s:string;
   begin
      assign(input,fi);
      reset(input);
      assign(output,fo);
      rewrite(output);
      readln(n);
      d:=0;
      for i:=1 to n do
      begin
         read(x); readln(s);
         if s[2]='N' then k:=1;
         if s[2]='E' then k:=2;
         if s[2]='S' then k:=3;
         if s[2]='W' then k:=4;
         if ((d=0) or (d=12000)) and ((k=2) or (k=4)) then
         begin write('NO'); exit; end;
         if (d=0) and (k=1) then
         begin write('NO'); exit; end;
         if (d=12000) and (k=3) then
         begin write('NO'); exit; end;
         if k=2 then continue;
         if k=4 then continue;
         if k=1 then
         begin
            if x >= d then d:=0 else d:=d-x;
            continue;
         end;
         if k=3 then
         begin
            if x + d >= 12000 then d:=12000 else d:=x+d;
         end;
      end;
      if d=0 then write('YES') else write('NO');
   end;

BEGIN
   DOC;
END.

const
    fi='';
    fo='';
var n,k,so,no,mark:longint;
    f,g:text;
    kt:boolean;
    s:string;
procedure nhap;
var i:longint;
begin
    assign(f,fi);
    reset(F);
    readln(f,n);
    kt:=false;
    for i:=1 to n do
    begin
        readln(f,k,s);
        if s=' South' then
            so:=so+k
        else
        if s=' North' then
            so:=so-k;
        if (so<0) or (so>20000) then kt:=true;
    end;
    close(f);
end;
procedure xuli;
var i:longint;
begin
    assign(g,fo);
    rewrite(G);
    if (kt=false)  then write(g,'YES') else write(g,'NO');
    close(g);
end;
begin
    nhap;
    xuli;
end.

var i,c,cs,n:integer;s:string;
begin
readln(n);
cs:=0;
For i:=1 to n do
 begin
  readln(c,s);
  If ((s=' South')or(s=' North'))and(c>20000)then begin writeln('NO');exit;end;
  If cs=0 then if s<>' South'
   then begin writeln('NO');
              exit;
        end;
  If cs=20000 then if s<>' North' then begin writeln('NO');exit;end;
  If s=' South' then cs:=cs+c;
  If s=' North' then cs:=cs-c;

  If cs mod 40000=0 then cs:=0;
  If cs mod 40000=20000 then cs:=20000;
 end;
If cs=0 then writeln('YES') else writeln('NO');
end.

Program Andronic;
var n,i:byte; t:array[1..50]of longword; dir,s:string; a:qword;
begin
     readln(n);
     i:=1;
     a:=0;
     s:='YES';
     while (i<=n)and(s<>'NO') do begin
                   readln(t[i]);
                   readln(dir);
                   IF (a=0) and(dir<>'South') then s:='NO';
                   IF (a mod 20000=0)and(dir<>'North') then s:='NO';
                   IF dir='South' then a:=a+t[i];
                   IF dir='North' then a:=a-t[i];
                   inc(i);
                   IF (i>n)and(a <>0) then s:='NO';
                   end;
     writeln(s);
     readln;
end.

var ch,i,n,x,q,y,p,w:longint;
    f:boolean;
    s:string;
begin
 readln(n);
 x:=0;
 y:=0;
 p:=0;
 f:=true;
 for i:=1 to n do
 begin
  readln(s);
  val(s,ch,q);
  w:=q;
  val(copy(s,1,q-1),ch,q);
  s:=copy(s,w+1,length(s)-w);
  if (p=2)and(s[1]<>'S') then
   f:=false;
  if (p=1)and(s[1]<>'N') then
   f:=false;
  p:=0;
  case s[1] of
  'N':  dec(y,ch);
  'E':  dec(x,ch);
  'S':  inc(y,ch);
  'W':  inc(x,ch);
  end;
  x:=abs(x mod 40000);
  y:=abs(y mod 20000);
  if (y=0) then
   p:=1;
  if (y=20000) then
   p:=2;

 end;
 if y<>0 then
 f:=false;
 if f then
 writeln('YES') else
 writeln('NO');
end.

var
  p,a,b,i,n,j:longint;
  s:Array[1..111]of string;
  k:array[1..111]of longint;
begin
  readln(n);
  for i:=1 to n do
  begin
  read(k[i]);
  readln(s[i]);
  end;

  p:=0;
  if (s[1][2]<>'S') then begin writeln('NO');halt;end;
  for i:=1 to n do
  begin
    if (p=0) or (p=20000) then if (s[i][2]='E') or (s[i][2]='W') then begin writeln('NO');halt;end;
    if (s[i][2])='N' then p:=p-k[i] else
    if (s[i][2])='S' then p:=p+k[i];
    if (p<-20000) or (p>20000) then begin writeln('NO');halt;end;
    if (p<0) and (p>-20000)  then p:=-p;
  end;
//  writeln(p);
  if p<>0 then writeln('NO') else writeln('YES');
end.

var n,i,j,put,vert,f:integer;
   s,napr:string;
begin
read(n); f:=0; vert:=0;
for i:=1 to n do begin
 read(put,napr);
 delete(napr,1,1);
 if (put>20000) and (napr<>'East') and (napr<>'West') then f:=1;
 if (vert=20000) and (napr<>'North') then f:=1;
 if (i=1) and (napr<>'South') then f:=1;
 if napr='South' then vert:=vert+put;
 if napr='North' then vert:=vert-put;
 if f=1 then break;
end;
if vert<>0 then f:=1;
if f=1 then write('NO') else write('YES');
end.

var n,i,t: longint;
    x: longint = 0;
    dir: string;
begin
    read(n);
    for i:=1 to n do
    begin
        read(t); readln(dir);
        if dir=' North'
           then dec(x,t)
        else if dir=' South'
             then inc(x,t);
        if (x<0)or(x>20000) then
        begin
            write('NO');
            exit;
        end;
    end;
    if x=0 then write('YES') else write('NO');
end.

 var t, p, n, i, x: longint;
s: string;
begin
readln (n);
if n=5 then begin for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
end;
if n=2 then begin for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=p+t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 write (' ',p, ' ');
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
write (' ',p, ' ');
end;
end.

const
    fi ='';
    fg ='';
var n,i,distance:longint;
    c:char;
    x:array[0..51] of longint;
    s:array[0..51] of string;
    f,g:text;
begin
    assign(f,fi);
    reset(f);
    assign(g,fg);
    rewrite(g);
    readln(f,n);distance :=0;
    For i:=1 to n do
    begin
        read(f,x[i]);read(f,c);s[i] :='';
        While not eoln(f) do
        begin
            read(f,c);s[i] :=s[i] + c;
        end;
        readln(f);
    end;
    For i:=1 to n do
    begin
        If (distance = 0) and (s[i] <> 'South') then
        begin
            writeln(g,'NO');close(g);exit;
        end;
        If (distance = 20000) and (s[i] <> 'North') then
        begin
            writeln(g,'NO');close(g);exit;
        end;
        If (s[i] = 'South') then distance :=distance + x[i]
        else if (s[i] = 'North') then distance :=distance - x[i];
    end;
    If (distance = 0) then writeln(g,'YES')
    else writeln(g,'NO');
    close(f);
    close(g);
end.

var     s,n:longint;      kq:string[3];
procedure Nhap;
var     x,i:longint;      y:string[6];
begin
        read(n);
        for i:=1 to n do
        begin
                read(x,y);
                if y=' North' then
                        inc(s,x)
                else if y=' South' then
                        dec(s,x);
                if (s>20000) or (s<-20000) then
                        exit;
        end;
        if s=20000 then
                kq:='YES';
end;
procedure Xuat;
begin
        write(kq);
end;
begin
        kq:='NO';
        s:=20000;
        Nhap;
        Xuat;
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 read(t);
 readln (s);
 write (t,s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=1;
 if (put=20000) and (s<>'North') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

var n,i,k,m:longint;
    fl:boolean;
    s:string;
begin
readln(n);
m:=0;
fl:=true;
for i:=1 to n do
 begin
  read(k);
  readln(s);
  if m = 0 then if s <> ' South' then begin fl:=false; break; end;
  if m = 20000 then if s <> ' North' then begin fl:=false; break; end;
  if s = ' South' then m:=m+k;
  if s = ' North' then m:=m-k;
  if (m<0) and (m>20000) then begin fl:=false; break; end;
 end;
 if fl then if m = 0 then writeln('YES')
                     else writeln('NO')
       else writeln('NO');
end.

var
a:array [1..1000000] of integer;
s,i,n:integer;
np,sp:boolean;
p: array [1..1000000] of string;
begin
read (n);
for i:=1 to n do begin
read (a[i]); readln (p[i]); end;
for i:=1 to n do begin
if  s=0 then
if p[i]<>' South' then begin write ('NO'); exit; end;
if s=20000 then
if p[i]<>' North' then begin write ('NO'); exit; end;
if p[i]=' South' then begin s:=s+a[i]; end else if p[i]=' North' then s:=s-a[i];
end;
if s<>0 then write ('NO')
else write ('YES');
end.

var i,j,k,l,ms,me,n,f:longint;
t:array [0..50] of longint;
d:array [0..50] of string;
s,sn,se,sw:string;
begin

ms:=0;
me:=0;
s:=' South';
sn:=' North';
se:=' East';
sw:=' West';
readln(n);
for i:=1 to n do
    read(t[i],d[i]);

if d[n] <> sn then writeln('NO') else
if d[1] <> s then writeln('NO') else
   begin
   for i:=1 to n do
      begin
      if d[i] = s then
        if ms=20000 then begin f:=1; break; end else
                                        begin
                                        ms:=ms+t[i];
                                        if ms>20000 then
                                            begin
                                            f := 1;
                                            break;
                                            end;
                                       end;
      if d[i] = sn then
            if ms=0 then begin f:=1; break; end else
                                        begin
                                        ms:=ms-t[i];
                           if (ms>20000) and (ms < 0) then
                                            begin
                                            f := 1;
                                            break;
                                            end;
                                       end;
       if d[i] = se then begin
          if ms=20000 then begin f:=1; break; end else
           if ms=0 then begin f:=1; break; end else
                              me:=me+t[i];
                              if me > 20000 then me:=20000-me;
                               end;
       if d[i] = sw then begin
         if ms=20000 then begin f:=1; break; end else
           if ms=0 then begin f:=1; break; end else
                              me:=me-t[i];
                              if me < 0then me:=abs(me);
                               end;
      end;
     if f = 1then writeln('NO') else writeln('YES');
   end;

   end.

Program cf1;
Var
    north,south,i,j,k,nums,code:longint;
    sn,s,test:string;
    fl:boolean;
Begin
    //assign(input,'input.txt'); reset(input);
    //assign(output,'output.txt'); rewrite(output);

    readln(k);

    south:=20000; north:=0; fl:=false;

    for i:=1 to k do Begin
        readln(s);
        nums:=0;
        sn:='';
        j:=1;
        while (s[j] <> ' ') do Begin
            sn:=sn + s[j];
            inc(j);
        End;
        val(sn,nums,code);
        test:=copy(s,j+1,length(s)-j);

        if (nums > 20000) and ((test = 'South') or (test = 'North')) then Begin
            fl:=true;
            break;
        End;

        nums:=nums mod 40000;

        if ((north = 0) or (north = 40000) or (south = 20000)) and (test <> 'South') then Begin
            fl:=true;
            break;
        End;

        if ((south = 0) or (south = 40000) or (north = 20000)) and (test <> 'North') then Begin
            fl:=true;
            break;
        End;

        if (test = 'South') then Begin
            dec(south,nums);
            inc(north,nums);
        End else if (test = 'North') then Begin
            dec(north,nums);
            inc(south,nums);
        End;
    End;

    if ((north = 0) or (north = 40000) or (south = 20000)) and (fl = false) then write('YES') else write('NO');
End.

var n,i,j,k,t,l,r,d,x,y:longint;
m:longint;
dir:string;
flag: integer;
begin
readln(n);
flag:=1;
y:=0;
for i:=1 to n do begin
    readln(t,dir);
  //  writeln(dir);
    if ((dir<>' South')and(y=0)) then flag:=-1
    else if ((dir<>' North')and(y=20000)) then flag:=-1
    else begin
        if (dir=' South') then y:=y+t;
        if (dir=' North') then y:=y-t;
        if (y<0) then y:=abs(y);
        while y>=40000 do y:=y-40000;
        if y>20000 then y:=20000-(y-20000);

    end;
    writeln(y);
end;
if (y<>0) then flag:=-1;
if (flag=-1) then writeln('NO')
else writeln('YES');
end.

program hsfdk;
var n,i:integer;
    td,so:longint;
    st:string;
    kt:boolean;
begin
   readln(n); kt:=true;
   td:=0;
    for i:=1 to n do
     begin
      readln(so,st);
      if kt=true then
      begin
      if(td=0)and(st<>' South')
      or(td=40000)and(st<>' North')then kt:=false;
       if st=' North'then td:=td-so
       else if st=' South'then td:=td+so;
       if(td<0)or(td>40000)then kt:=false;
      end;
     end;
     if td<>0 then kt:=false;
     if kt=true then write('YES')
     else write('NO');
     readln
end.

var n,i,j,k,t,l,r,d,x,y:longint;
m:longint;
dir:string;
flag: integer;
begin
readln(n);
flag:=1;
y:=0;
for i:=1 to n do begin
    readln(t,dir);

    if ((dir<>' South')and(y=0)) then flag:=-1
    else if ((dir<>' North')and(y=20000)) then flag:=-1
    else begin
        if (dir=' South') then y:=y+t;
        if (dir=' North') then y:=y-t;
        while y>20000 do y:=y-20000;
        while y<0 do y:=y+20000;
    end;
//    writeln(y);
end;
if (y<>0) then flag:=-1;
if (flag=-1) then writeln('NO')
else writeln('YES');
end.

var t,a1,i,k,n:longint;
    dis:string;
begin
read(n);
a1:=0;
k:=0;
for i:=1 to n do
 begin
  read(t,dis);
   if (a1=0) then
     begin
      if dis='South' then a1:=a1+t;
     end else
   if a1=20000 then
     begin
       if dis='North' then a1:=a1-t;
     end else
   if dis='North' then a1:=a1-t else
   if dis='South' then a1:=a1+t else
   if (dis='West') or (dis='East') then a1:=a1 else
      k:=1;
 end;
if k=1 then write('NO') else
 if k=0 then
    begin
      if a1>20000 then
       begin
        if a1 mod 20000 = 0 then write('YES') else write('NO');
       end else
      if a1=0 then write('YES') else write('NO');
    end;
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 read(t);
 read (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=1;
 if (put=20000) and (s<>'North') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

var n,i,x:longint;
    d:int64;
    s:ansistring;
begin
    readln(n);
    d:=0;
    for i:=1 to n do
    begin
        readln(x,s);
        delete(s,1,1);
        if (d=0) and (s<>'South') then begin writeln('NO'); halt; end;
        if (d=20000) and (s<>'North') then begin writeln('NO'); halt; end;
        if (s='South') then d:=d+x;
        if (s='North') then d:=d-x;
    end;
    if (d=0) then writeln('YES') else writeln('NO');
    readln;
end.

uses math;
const
	fin='';
	fon='';
	maxC=1000000007;
	maxN=107;
type
        data=record
                dis,dir:longint;
        end;
var
        n:longint;
        a:array [0..maxN] of data;

Procedure Openf;
begin
	assign(input,fin); reset(input);
	assign(output,fon); rewrite(output);
end;

Procedure Closef;
begin
	close(input);
	close(output);
End;

function cal(pos:longint):boolean;
var
        now:longint;
        i,x,y:longint;
begin
        if (pos<>1) and (pos<>4) then exit(false);

        x:=0;
        y:=0;
        for i:=1 to n do
        if a[i].dis<20001 then
        begin
                if  a[i].dir=1 then x:=x+a[i].dis;
                if  a[i].dir=4 then y:=y+a[i].dis;
        end
        else
        begin
                if (a[i].dis div 20000) mod 2=0 then
                begin
                        if a[i].dir=1 then x:=x+a[i].dis mod 20000;
                        if a[i].dir=4 then y:=y+a[i].dis mod 20000;
                end
                else
                begin
                        if a[i].dir=4 then x:=x+a[i].dis mod 20000;
                        if a[i].dir=1 then y:=y+a[i].dis mod 20000;
                end;
        end;
        now:=pos;
        if x<>y then exit(false);
        for i:=1 to n do
        begin
                if (a[i].dir=1) or (a[i].dir=4) then now:=a[i].dir;
        end;
        if now=1 then exit(true);
        exit(false);
end;

Procedure Nhap;
var
        i:longint;
        s:ansistring;
Begin
        readln(n);
        for i:=1 to n do
        with a[i] do
        begin
                readln(dis,s);
                if s=' North' then a[i].dir:=1;
                if s=' East' then a[i].dir:=2;
                if s=' West' then a[i].dir:=3;
                if s=' South' then a[i].dir:=4;

        end;
        if cal(5-a[1].dir) then writeln('YES')
        else writeln('NO');
End;

Procedure xuli;
begin
end;

Procedure Xuat;
begin
end;

Procedure Solve;
begin
	Nhap;
	Xuli;
	Xuat;
end;
BEGIN
	Openf;
	Solve;
	Closef;
END.

var n,i,j,put,vert,f:integer;
   s,napr:string;
begin
read(n); f:=0; vert:=0;
for i:=1 to n do begin
 read(put,napr);
 delete(napr,1,1);
 if (vert=20000) and (napr<>'North') then f:=1;
 if (i=1) and (napr<>'South') then f:=1;
 if napr='South' then vert:=vert+put;
 if napr='North' then vert:=vert-put;
 if f=1 then break;
end;
if vert<>0 then f:=1;
if f=1 then write('NO') else write('YES');
end.

var n,i,j,k,t,l,r,d,x,y:longint;
m:longint;
dir:string;
flag: integer;
begin
readln(n);
flag:=1;
y:=0;
for i:=1 to n do begin
    readln(t,dir);
  //  writeln(dir);

    if ((pos('South',dir)=0)and(y=0)) then flag:=-1
    else if ((pos('North',dir)=0)and(y=20000)) then flag:=-1
    else if (pos('South',dir)>0)or(pos('North',dir)>0) then begin
        if pos('South',dir)>0 then y:=y+t;
        if pos('North',dir)>0 then y:=y-t;
        if (y<0) then y:=abs(y);
        while y>=40000 do y:=y-40000;
        if y>20000 then y:=20000-(y-20000);

    end;
   // writeln(y);
end;
if (y<>0) then flag:=-1;
if (flag=-1) then writeln('NO')
else writeln('YES');
end.

Program cf1;
Var
    north,south,i,j,k,nums,code:longint;
    sn,s,test:string;
    fl:boolean;
Begin
    //assign(input,'input.txt'); reset(input);
    //assign(output,'output.txt'); rewrite(output);

    readln(k);

    south:=20000; north:=0; fl:=false;

    for i:=1 to k do Begin
        readln(s);
        nums:=0;
        sn:='';
        j:=1;
        while (s[j] <> ' ') do Begin
            sn:=sn + s[j];
            inc(j);
        End;
        val(sn,nums,code);
        test:=copy(s,j+1,length(s)-j);

        nums:=nums mod 40000;

        if ((north = 0) or (north = 40000) or (south = 20000)) and (test <> 'South') then Begin
            fl:=true;
            break;
        End;

        if ((south = 0) or (south = 40000) or (north = 20000)) and (test <> 'North') then Begin
            fl:=true;
            break;
        End;

        if (test = 'South') then Begin
            dec(south,nums);
            inc(north,nums);
        End else if (test = 'North') then Begin
            dec(north,nums);
            inc(south,nums);
        End;
    End;

    if ((north = 0) or (north = 40000) or (south = 20000)) and (fl = false) then write('YES') else write('NO');
End.

var i,c,cs,n:integer;s:string;a:char;
begin
readln(n);
cs:=0;
For i:=1 to n do
 begin
  readln(c,a,s);
  If cs=0 then if s<>'South'
   then begin writeln('NO');
              exit;
        end;
  If cs=20000 then if s<>'North' then begin writeln('NO');exit;end;
  If s='South' then cs:=cs+c;
  If s='North' then cs:=cs-c;

  If cs mod 40000=0 then cs:=0;
  If cs mod 40000=20000 then cs:=20000;
 end;
If cs=0 then writeln('YES') else writeln('NO');
end.

var
  n, x, y, sd, i: longint;
  s: string;

procedure sphalt;
begin
  writeln('NO');
  halt(0);
end;

begin
  readln(n);
  for i := 1 to n do
  begin
    read(sd);
    readln(s);

    if (y <= 0) and (s <> ' South') then
      sphalt;
    if (y >= 20000) and (s <> ' North') then
      sphalt;
    if s = ' South' then
      inc(y, sd);
    if s = ' North' then
      dec(y, sd);
    if s = ' West' then
      inc(x, sd);
    if s = ' East' then
      dec(x, sd);

  end;
  if (y <> 0) then
    sphalt;
  writeln('YES');
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

uses math;
var
 s,t:string;
 n,m,i,k,j,f,c,x,y,z,q,w,v,g:longint;
 pp:integer;
begin
 readln(n);
 v:=10000;
 for i:=1 to n do
 begin
  readln(s);
  val(copy(s,1,pos(' ',s)-1),f,pp);
  f:=f mod 40000;
 // writeln(f);
  if s[pos(' ',s)+1]='N'then inc(v,f)else
  if s[pos(' ',s)+1]='S'then dec(v,f)else
  begin
   if v=-10000 then inc(v,f)else
   if v=10000 then dec(v,f);

  end;
  if v>abs(10000)then v:=-(v mod 40000);
 // writeln(v);
 end;
 if v=10000 then writeln('YES')
 else writeln('NO');
end.

var n,now,i:longint;
    k:int64;
    s:ansistring;
begin
  readln(n);now:=0;
  for i:=1 to n do
    begin
      readln(s);
      val(copy(s,1,pos(' ',s)-1),k);
      delete(s,1,pos(' ',s));
      if(s[1]='N')then now:=now-k
      else if(s[1]='S')then now:=now+k;
      if(now<0)or(now>20000)then begin writeln('NO');halt;end;
    end;
  if(now<>0)then writeln('NO')else writeln('YES');
end.

var k,n,l,d:integer; s:string;
begin

readln(n);
for var i:=1 to n do begin
read(l); readln(s);
if (k<0) or (k>20000) then d+=1;
if (k=0) and (s[2]<>'S')then d+=1;
if (k=20000) and (s[2]<>'N')then d+=1;
if s[2]='S' then k+=l;
if s[2]='N' then k-=l; end;
if d>0 then write('NO') else if k>0 then write('NO') else write('YES');
end.

var n,i,k,m:longint;
    fl:boolean;
    s:string;
begin
readln(n);
m:=0;
fl:=true;
for i:=1 to n do
 begin
  read(k);
  readln(s);
  if m = 0 then if s <> ' South' then begin fl:=false; break; end;
  if m = 20000 then if s <> ' North' then begin fl:=false; break; end;
  if s = ' South' then m:=m+k;
  if s = ' North' then m:=m-k;
  if (m<0) and (m>20000) then begin fl:=false; break; end;
 end;
 if fl then if m = 0 then writeln('YES')
                     else writeln('NO')
       else writeln('NO');
end.

var n,res:byte;
    t:array[0..50] of longint;
    dir:array[0..50] of string;

procedure solve;
var NS:longint; i:byte;
begin
    NS:=0; res:=0;
    for i:=1 to n do
    begin
        if dir[i]=' North' then
        begin
            if NS=0 then break;
            if t[i]>NS then break;
            NS:=NS-t[i];
        end
        else if dir[i]=' South' then
        begin
            if NS=20000 then break;
            if t[i]>20000-NS then break;
            NS:=NS+t[i];
        end
        else if ((dir[i]=' West') or (dir[i]=' East')) and ((NS=0) or (NS=20000)) then break;
    end;
    if NS=0 then res:=1;
end;

procedure input;
var i:byte; tmp:string;
begin
    readln(n);
    for i:=1 to n do
    begin
        readln(t[i],dir[i]);
    end;
end;

procedure output;
begin
    if res=0 then writeln('NO') else writeln('YES');
end;

begin
    input;
    solve;
    output;
end.

var a:array[1..50] of string[6];
    b:array[1..50] of longint;
    i,s,n:longint;
    data:boolean;
begin
readln(n);
for i:=1 to n do begin
readln(b[i],a[i]);
if ((b[i]>20000)and(a[i]=' North')) or ((b[i]>20000)and(a[i]=' South'))then data:=true
end;
s:=0;
for i:=1 to n do begin
if a[i]=
' South' then begin
        if s=20000 then begin data:= true; break end;
        inc(s,b[i]);
        end;
        if a[i]=
' North' then begin
        if s=0 then begin data:= true; break end;
        dec(s,b[i]);
        end;
        if a[i]=
' West' then begin
        if (s=0)or(s=20000) then begin data:= true; break end;
        end;
        if a[i]=
' East' then begin
        if (s=0)or(s=20000) then begin data:= true; break end;
        end;
end;
//if (s=0)and(r<>0) then data:=true;
if s<>0 then data:=true;
if data then writeln('NO')
         else writeln('YES')
end.

var
 a,m,j,i,n,g,posi : longint;
 s,tempat,s1,ch : string;
 b : boolean;
begin
 tempat:='South';
 posi:=0;
 readln(n);
 ch:=' ';
 //readln(s1);
 //writeln(pos(ch,s1));
 b:=true;
  for i:= 1 to n do
   begin
    readln(a,s1);
    m:=pos(ch,s1);
    s:=copy(s1,m+1,length(s1)-m+1);
    //writeln(s);
    if b then
     begin
      if posi=0 then
       begin
        //writeln('#1');
        if (tempat=s) then
         begin
          posi:=posi+a;
          if posi=20000 then
           begin
            tempat:='North';
            posi:=0;
           end
          else
           if posi>20000 then
            b:=false;
          //writeln('posi sekarang ',posi);
          //writeln('tempat sekarang ',tempat);
         end
        else
         b:=false;
       end
      else
        begin
         //writeln('#2');
         if tempat=s then
          begin
           posi:=posi+a;
           if posi=20000 then
            begin
             if tempat='North' then
              tempat:='South'
             else
              tempat:='North';
              posi:=0;
            end
           else
            if posi>20000 then
             b:=false;
            //writeln('posi sekarang ',posi);
            //writeln('tempat sekarang ',tempat);
          end
         else
          if (tempat<>s) and ((s<>'West') and (s<>'East')) then
           begin
            posi:=posi-a;
            //writeln('posi sekarang ',posi);
            //writeln('tempat sekarang ',tempat);;
           end;
    end;
   end;
  end;
  //writeln(b);
  if not b then
   writeln('NO')
  else
   if (tempat='South') and (posi=0) then
    writeln('YES')
   else
    writeln('NO');
end.

Program cf1;
Var
    north,south,i,j,k,nums,code,east,west:longint;
    sn,s,test:string;
    fl:boolean;
Begin
    //assign(input,'input.txt'); reset(input);
    //assign(output,'output.txt'); rewrite(output);

    readln(k);

    south:=10000; north:=0; fl:=false; east:=0; west:=0;

    for i:=1 to k do Begin
        readln(s);
        nums:=0;
        sn:='';
        j:=1;
        while (s[j] <> ' ') do Begin
            sn:=sn + s[j];
            inc(j);
        End;
        val(sn,nums,code);
        test:=copy(s,j+1,length(s)-j);

        nums:=nums mod 40000;

        if ((north = 0) or (north = 40000)) and (test <> 'South') then Begin
            fl:=true;
            break;
        End;

        if (test = 'South') then Begin
            dec(south,nums);
            inc(north,nums);
        End else if (test = 'North') then Begin
            dec(north,nums);
            inc(south,nums);
        End else if (test = 'East') then Begin
            inc(east);
        End else if (test = 'West') then Begin
            inc(west);
        End;
    End;

    if ((north = 0) or (north = 40000)) and (fl = false) and (east-west = 0) then write('YES') else write('NO');
End.

Program z2;
var
    n,k,m,t,v:integer;
    i,j:integer;
    f:boolean;
    s,mt:string;
begin
    readln(n);
    f:=true;
    k:=0;
    for i:=1 to n do begin
        readln(s);
        if f=true then
            if s[length(s)]='h' then begin
                mt:=copy(s,1,length(s)-6);
                t:=length(mt);
                v:=1;
                m:=0;
                for j:=t downto 1 do begin
                    m:=m+(ord(mt[j])-48)*v;
                    v:=v*10;
                end;
                if s[length(s)-2]='r' then m:=-m;
                if ((k+m)<0)OR((k+m)>40000)OR((k=0)AND(m<0))OR((k=40000)AND(m>0)) then f:=false;
                k:=k+m;
            end else if (k=0)OR(k=40000) then f:=false;
    end;
    if k<>0 then f:=false;
    if f=false then write('NO') else write('YES');
end.

var
  n,m,i,k,x,c:longint;
  s:string;
begin
  readln(n);
  m:=0;
  for i:=1 to n do
  begin
    readln(s);
    x:=pos(' ',s);
    val(copy(s,1,x-1),k,c);
    case s[x+1] of
      'S':begin
            m:=m+k;
            if m>20000 then m:=20000;
          end;
      'N':begin
            m:=m-k;
            if m<0 then m:=0;
          end;
    end;
  end;
  if m=0 then writeln('YES') else writeln('NO');
end.

const fi = '';
      fo = '';
var x, i, n, vt: longint;
    s: string;
    c: char;
begin
  assign(input,fi); reset(input);
  assign(output,fo); rewrite(output);

  readln(n);
  vt:=0;
  for i:=1 to n do
    begin
      readln(x,c,s);
      if s = 'South' then
        begin
          vt:=vt+x;
          if vt > 20000 then
            begin
              writeln('NO');
              halt;
            end;
        end
      else if s = 'North' then
        begin
          vt:=vt- x;
          if vt < 0 then
            begin
              writeln('NO');
              halt;
            end;
        end
      else if (s = 'West') or (s = 'North') then
        begin
          if (vt = 0) or (vt = 20000) then
            begin
              writeln('NO');
              halt;
            end;
        end;
    end;
  if vt <> 0 then write('NO')
  else write('YES');

  close(input); close(output);
end.

var
t: array [1..75] of longint;
dir: array [1..75] of string;
temp: boolean;
e: char;
i, pos, n: longint;

begin
	readln (n);

	for i:= 1 to n do
		readln (t[i], e, dir[i]);

	temp:= true;
	pos:=0;
	for i:= 1 to n do
	begin
		if (temp) then
		begin
			if (pos=0) then
			begin
				if (dir[i]<>'South') then
				temp:= false;
			end else if (pos=20000) then
			begin
				if (dir[i]<>'North') then
				temp:= false;
			end else begin
				if (dir[i]='South') then
				begin
					if (pos+t[i]>20000) then
						temp:= false
					else begin
						pos:=pos+t[i];
						temp:= true;
					end;
				end else if (dir[i]='North') then
				begin
					if (pos-t[i]<0) then
						temp:= false
					else begin
						pos:=pos-t[i];
						temp:= true;
					end;
				end;
			end;
		end;
	end;
	if (temp) then begin
	if (pos=0) then
		temp:=true
	else temp:= false;
	end;

	if (temp) then
		writeln ('YES')
	else writeln ('NO');
end.

var
	A,n,i:longint;
	s:string;
	res:int64;
begin
	readln(n);res:=0;
	for i:=1 to n do
		begin
			read(a);
			readln(s);
			if (res = 0) and (s<>' North') and (s<>' South')  then
				begin
					write('NO');
					exit;
				end
			else
			if (res=20000) and (s<>' North') and (s<>' South') then
				begin
					write('NO');
					exit;
				end
			else
			if (s = ' South') then res:=res+a
			else
			if (s = ' North') then res:=res-a
		end;
	if res = 0 then write('YES')
	else write('NO');
end.

 var t, p, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

{var
t: array [1..75] of longint;
dir: array [1..75] of string;
temp: boolean;
e: char;
i, pos, n: longint;

begin
	readln (n);

	for i:= 1 to n do
		readln (t[i], e, dir[i]);

	temp:= true;
	pos:=0;
	for i:= 1 to n do
	begin
		if (temp) then
		begin
			if (pos=0) then
			begin
				if (dir[i]<>'South') then
				temp:= false;
			end;
			if (pos=20000) then
			begin
				if (dir[i]<>'North') then
				temp:= false;
			end;
			if ((pos>0) and (pos<20000)) then begin
				if (dir[i]='South') then
				begin
					if (pos+t[i]>20000) then
						temp:= false
					else begin
						pos:=pos+t[i];
						temp:= true;
					end;
				end else if (dir[i]='North') then
				begin
					if (pos-t[i]<0) then
						temp:= false
					else begin
						pos:=pos-t[i];
						temp:= true;
					end;
				end;
			end;
		end;
	end;
	if (temp) then begin
	if (pos=0) then
		temp:=true
	else temp:= false;
	end;

	if (temp) then
		writeln ('YES')
	else writeln ('NO');
end.}

var
t: array [1..75] of longint;
dir: array [1..75] of string;
temp: boolean;
e: char;
i, pos, n: longint;

begin
 readln (n);

 for i:= 1 to n do
  readln (t[i], e, dir[i]);

 temp:= true;
 pos:=0;
 for i:= 1 to n do
 begin
  if (temp) then
  begin
   if (pos=0) then
   begin
    if (dir[i]<>'South') then
    temp:= false;
   end;
   if (pos=20000) then
   begin
    if (dir[i]<>'North') then
    temp:= false;
   end;

   if ((pos > 0) AND (pos < 20000)) then
    if (dir[i]='South') then
    begin
     pos:=pos+t[i];
     if (pos>20000) then temp:= false;
    end else if (dir[i]='North') then
    begin
     pos:=pos-t[i];
     if (pos<0) then temp:= false;
    end;
   end;
  end;
 if (pos<>0) then temp:= false;

 if (temp) then
  writeln ('YES')
 else writeln ('NO');
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 read(t);
 read (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=1;
 if (put=20000) and (s<>'North') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

var n,f,i,a : longint;
    c : char;
begin
  readln(n); f:=0;
  for i:=1 to n do begin
      readln(a,c,c);
      if c = 'S' then inc(f,a);
      if c = 'N' then dec(f,a);
      if f < 0 then begin writeln('NO'); halt; end;
      if f > 20000 then begin writeln('NO'); halt; end;
    end;
  if f <> 0 then begin writeln('NO'); halt; end;
  writeln('YES');
end.

var a1,a2,i,j,n,k:longint;
    t:array[1..55] of longint;
    dis:array[1..55] of string;
    b:string;
begin
readln(n);
for i:=1 to n do
 begin
   read(t[i],b);
   delete(b,1,1);
   dis[i]:=b;
 end;
i:=1;
a1:=0;
a2:=0;
while (i<=n) and (k=0) do
  begin
     if (a1=0) and (dis[i]='South') then
        a1:=a1+t[i] else
      if (a1=20000) and (dis[i]='North')then
        a1:=a1-t[i] else
       if (a1<>0) and (a1<>20000) and (dis[i]='South') then
          a1:=a1+t[i] else
        if (a1<>0) and (a1<>20000) and (dis[i]='North') then
           a1:=a1-t[i] else
           if (a1<>0) and (a1<>20000) and (dis[i]='West') then
            a2:=a2+t[i] else
            if  (a1<>0) and (a1<>20000) and (dis[i]='East') then
            a2:=a2-t[i] else
             k:=1;
         inc(i);
   end;
if (k=0) and (a1=0) then write('Yes') else write('NO');
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 if (put=20000) and (s<>'North') then x:=3;
 if (put<0) then x:=4;
 if (put>20000) then x:=5;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 write (put);
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
write (put,' ',x);
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 read (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=1;
 if (put=20000) and (s<>'North') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
write (put,' ',x);
end.

 var t, p, n, i, x: longint;
s: string;
begin
readln (n);
if n=5 then begin for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
end;
if n=2 then begin for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then p:=t;
 if (i>1) and (s='South') then p:=p+t;
 if (i>1) and (s='North') then p:=p-t;
 if (p<0) then x:=4;
 if (p>20000) then x:=5;
 write (' ',p, ' ');
 end;
if (p=0) and (x=0) then writeln ('YES') else writeln ('NO');
end;
 write (' ',p, ' ');
end.

var c,cs,n:int64;s:string;i:integer;
begin
readln(n);
cs:=0;
For i:=1 to n do
 begin
  readln(c,s);
  If cs=0 then if s<>' South'
   then begin writeln('NO');
              exit;
        end;
  If cs=20000 then if s<>' North' then begin writeln('NO');exit;end;
  If s=' South' then cs:=cs+c;
  If s=' North' then cs:=cs-c;

  If cs mod 40000=0 then cs:=0;
  If cs mod 40000=20000 then cs:=20000;
 end;
If cs=0 then writeln('YES') else writeln('NO');
end.

{$mode objfpc}
{$coperators on}
const
        fi='input.txt';
        fo='output.txt';
procedure fileio;
begin
        assign(input,fi); reset(input);
        assign(output,fo); rewrite(output);
end;
var     n:longint;
procedure enter;
begin
        readln(n);
end;
function solve:string;
var     me,dis,i:longint;
        c,d:char;
begin
        me:=0;
        for i:=1 to n do begin
                readln(dis,c,d);
                if (d<>'S') and (d<>'N') then continue;
                if (me=0) and (d<>'S') then exit('NO');
                if (me=20000) and (d<>'N') then exit('NO');
                //dis:=dis mod 40000;
                if (dis>20000) then exit('NO');
                if d='S' then begin
                        me+=dis;
                        if me>20000 then exit('NO');
                end;
                if d='N' then begin
                        me-=dis;
                        if me<0 then exit('NO');
                end;
        end;
        if me=0 then exit('YES');
        exit('NO');
end;
begin
        //fileio;
        enter;
        writeln(solve);
end.

uses math;
const
	fin='';
	fon='';
	maxC=1000000007;
	maxN=107;
type
        data=record
                dis,dir:longint;
        end;
var
        n:longint;
        a:array [0..maxN] of data;

Procedure Openf;
begin
	assign(input,fin); reset(input);
	assign(output,fon); rewrite(output);
end;

Procedure Closef;
begin
	close(input);
	close(output);
End;

function cal(pos:longint):boolean;
var
        now:longint;
        i,x,y,tg:longint;
begin
        if (pos<>1) and (pos<>4) then exit(false);
        now:=pos;
        if now=1 then x:=0
        else x:=20000;
        for i:=1 to n do
        begin
                if (a[i].dir=1) or (a[i].dir=4) then
                with a[i] do
                begin
                        tg:=x;
                        if dir=1 then tg:=max(tg-a[i].dis,0)
                        else tg:=min(tg+a[i].dis,20000);
                        x:=tg;
                        now:=dir;
                end
                else
                begin
                        if (x=0) or (x=20000) then exit(false);
                end;
        end;
        if (x=0) and (now=1) then exit(true);
        exit(false);
end;

Procedure Nhap;
var
        i:longint;
        s:ansistring;
Begin
        readln(n);
        for i:=1 to n do
        with a[i] do
        begin
                readln(dis,s);
                if s=' North' then a[i].dir:=1;
                if s=' East' then a[i].dir:=2;
                if s=' West' then a[i].dir:=3;
                if s=' South' then a[i].dir:=4;

        end;
        if cal(5-a[1].dir) then writeln('YES')
        else writeln('NO');
End;

Procedure xuli;
begin
end;

Procedure Xuat;
begin
end;

Procedure Solve;
begin
	Nhap;
	Xuli;
	Xuat;
end;
BEGIN
	Openf;
	Solve;
	Closef;
END.

var qq:array[0..200000]of longint;
nn,i,j:longint;

begin
randomize;
nn:=36000;
for i:=1 to nn do qq[i]:=32768*random(32768)+random(32768);
for i:=1 to nn-1 do
  for j:=i+1 to nn do
    if qq[i]>qq[j] then
      begin
      qq[0]:=qq[i]; qq[i]:=qq[j]; qq[j]:=qq[0];
      end;
end.

var n,i,j,k,t,l,r,d,x,y:longint;
m:longint;
dir:string;
flag: integer;
begin
readln(n);
flag:=1;
y:=0;
i:=1;
while ((i<=n)and(flag=1)) do begin
    readln(t,dir);
  //  writeln(dir);
    if ((pos('South',dir)=0)and(y=0)) then flag:=-1
    else if ((pos('North',dir)=0)and(y=20000)) then flag:=-1
    else if (pos('South',dir)>0)or(pos('North',dir)>0) then begin
        if pos('South',dir)>0 then y:=y+t;
        if pos('North',dir)>0 then y:=y-t;
        if (y<0) then y:=abs(y);
        while y>=40000 do y:=y-40000;
        if y>20000 then y:=20000-(y-20000);
    end;
    i:=i+1;
//    writeln(i,' ',y,' ',flag);
end;
if (y<>0) then flag:=-1;
if (flag=-1) then writeln('NO')
else writeln('YES');
end.

var a:array[1..50] of string[6];
    b:array[1..50] of longint;
    i,s,n:longint;
    data:boolean;
begin
readln(n);
for i:=1 to n do
readln(b[i],a[i]);
s:=0;
for i:=1 to n do begin
if a[i]=
' South' then begin
        if s=20000 then begin data:= true; break end;
        inc(s,b[i]);
        end;
        if a[i]=
' North' then begin
        if s=0 then begin data:= true; break end;
        dec(s,b[i]);
        end;
        if a[i]=
' West' then begin
        if (s=0)or(s=20000) then begin data:= true; break end;
        end;
        if a[i]=
' East' then begin
        if (s=0)or(s=20000) then begin data:= true; break end;
        end;
end;
//if (s=0)and(r<>0) then data:=true;
if s<>0 then data:=true;
if data then writeln('NO')
         else writeln('YES')
end.

uses math;
var
 s,t:string;
 n,m,i,k,j,f,c,x,y,z,q,w,v,g:longint;
 pp:integer;
begin
 readln(n);
 v:=10000;
 for i:=1 to n do
 begin
  readln(s);
  val(copy(s,1,pos(' ',s)-1),f,pp);
  f:=f mod 40000;
 // writeln(f);
  if(s[pos(' ',s)+1]='N')and(v=10000)then f:=0;
  if(s[pos(' ',s)+1]='S')and(v=-10000)then f:=0;

  if s[pos(' ',s)+1]='N'then inc(v,f)else
  if s[pos(' ',s)+1]='S'then dec(v,f)else
  begin
   if v=-10000 then inc(v,f)else
   if v=10000 then dec(v,f);

  end;
//  writeln(v);
//  writeln;
  if abs(v)>abs(10000)then v:=-(v mod 20000);
//  writeln(v);
 end;
 if v=10000 then writeln('YES')
 else writeln('NO');
end.

var
	A,n,i:longint;
	s:string;
	res:int64;
begin
	readln(n);
	for i:=1 to n do
		begin
			read(a);
			readln(s);
			if s = ' South' then res:=res+a;
			if s = ' North' then res:=res-a;
		end;
	if res = 0 then write('YES')
	else write('NO');
end.

var x,y,i,r,j,n,z,f,f1:longint;
s:string;
  begin
 // assign(input,'input.txt'); reset(input);
    readln(n);
    x:=10000;y:=0;
     for i:= 1 to n do
     begin
      readln(s);
       j:=1;
       r:=0;
       while s[j]<>' ' do
        begin
          vaL(s[j],z,f);
          r:=r*10+z;
          j:=j+1;
        end;
        if s[j+1]='E' then y:=y+r;
        if s[j+1]='W' then y:=y-r;
        if abs(y)>20000 then f:=1;
        if (x=10000) and(s[j+1]<>'S')and(s[j+1]='N')and(i<>1) then f1:=1;
          if (x=-10000) and(s[j+1]<>'N')and(s[j+1]='S') then f1:=1;
        if (x<>10000)and(s[j+1]='N')  then x:=x+r;
        if x>10000 then f1:=1;
        if (x<>-10000)and(s[j+1]='S')  then x:=x-r;
         if x<-10000 then f1:=1;
    end;
    if (x=10000)and(f1=0) then writeln('YES')
    else writeln('NO');
    end.

var n,i,tek:longint;
    s:string;
begin
 readln(n);
 tek:=0;
 for i:=1 to n do
  begin
   read(n,s);
   if (s='North')and(tek<n)
    then begin write('NO');halt;end;
   if (s='South')and(tek+n>20000)
    then begin write('NO');halt;end;
   if ((s='West')or(s='East'))and((tek=0)or(tek=20000))
    then begin write('NO');halt;end;

   if s='North'
    then dec(tek,n);
   if s='South'
    then inc(tek,n);

  end;
  if tek=0
   then write('YES')
   else write('NO');

end.

const fi='';
    fo='';
procedure process;
var  s:longint;
    l:1..40000;
    n,i:1..50;
    a:string;
    f,g:text;
begin
    s:=0;
    assign(f,fi);reset(F);
    assign(g,fo);rewrite(g);
    readln(F,n);
    for i:=1 to n do
    begin
        read(f,l);readln(f,a);
        delete(a,1,1);
        if (a[1]='N') then dec(s,l);
        if (a[1]='S') then inc(s,l);
        if (( (a[1]='W') or (a[1]='E') ) and ( (s=0) or (s=20000))) or (s<0) or  (s>20000)  then
        begin
            writeln(g,'No');
            close(F);
            close(g);
            exit;
        end;
    end;
    if (s=0) then write(g,'Yes') else write(g,'No');
    close(F);
    close(g);
end;
begin
    process;
end.

var t,a1,i,k,n:longint;
    dis:string;
begin
read(n);
a1:=0;
k:=0;
for i:=1 to n do
 begin
  read(t,dis);
  delete(dis,1,1);
   if (a1=0) then
     begin
      if dis='South' then a1:=a1+t;
     end else
   if a1=20000 then
     begin
       if dis='North' then a1:=a1-t;
     end else
   if dis='North' then a1:=a1-t else
   if dis='South' then a1:=a1+t else
   if (dis='West') or (dis='East') then a1:=a1 else
      k:=1;
 end;
if k=1 then write('NO') else
 if k=0 then
    begin
      if a1>20000 then
       begin
        if a1 mod 20000 = 0 then write('YES') else write('NO');
       end else
      if a1=0 then write('YES') else write('NO');
    end;
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=1;
 if (put=20000) and (s<>'North') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

uses math;
var
 s,t:string;
 n,m,i,k,j,f,c,x,y,z,q,w,v,g:longint;
 pp:integer;
begin
 readln(n);
 v:=10000;
 for i:=1 to n do
 begin
  readln(s);
  val(copy(s,1,pos(' ',s)-1),f,pp);
  f:=f mod 40000;
  if s[pos(' ',s)+1]='N'then inc(v,f)else
  if s[pos(' ',s)+1]='S'then dec(v,f)else
  begin
   if v=-10000 then inc(v,f);
   if v=10000 then dec(v,f);
  end;
  if v>10000 then v:=-(v mod 10000);
  if v<-10000 then v:=-(v mod 10000);
 // writeln(v);
 end;
 if v=10000 then writeln('YES')
 else writeln('NO');
end.

Program Andronic;
var n,i:byte; t:array[1..50]of longword; dir,s:string; a:qword;
begin
     readln(n);
     i:=1;
     a:=0;
     s:='YES';
     while (i<=n)and(s<>'NO') do begin
                   readln(t[i]);
                   readln(dir);
                   IF (a div 40000=0) and(dir<>'South') then s:='NO';
                   IF (a div 20000=0)and(dir<>'North') then s:='NO';
                   IF dir='South' then a:=a+t[i];
                   IF dir='North' then a:=a-t[i];
                   inc(i);
                   IF (i>n)and(a div 40000<>0) then s:='NO';
                   end;
     writeln(s);
     readln;
end.

var qq:array[0..200000]of longint;
nn,i,j:longint;

begin
randomize;
nn:=27000;
for i:=1 to nn do qq[i]:=32768*random(32768)+random(32768);
for i:=1 to nn-1 do
  for j:=i+1 to nn do
    if qq[i]>qq[j] then
      begin
      qq[0]:=qq[i]; qq[i]:=qq[j]; qq[j]:=qq[0];
      end;
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 read (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=1;
 if (put=20000) and (s<>'North') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

var i,c,cs,n:integer;s:string;
begin
readln(n);
cs:=0;
For i:=1 to n do
 begin
  readln(c,s);
  If ((s=' South')or(s=' North'))and(c>20000)then writeln('NO');
  If cs=0 then if s<>' South'
   then begin writeln('NO');
              exit;
        end;
  If cs=20000 then if s<>' North' then begin writeln('NO');exit;end;
  If s=' South' then cs:=cs+c;
  If s=' North' then cs:=cs-c;

  If cs mod 40000=0 then cs:=0;
  If cs mod 40000=20000 then cs:=20000;
 end;
If cs=0 then writeln('YES') else writeln('NO');
end.

{$mode objfpc}
{$coperators on}
const
        fi='input.txt';
        fo='output.txt';
procedure fileio;
begin
        assign(input,fi); reset(input);
        assign(output,fo); rewrite(output);
end;
var     n:longint;
procedure enter;
begin
        readln(n);
end;
function solve:string;
var     me,dis,i:longint;
        c,d:char;
begin
        me:=0;
        for i:=1 to n do begin
                readln(dis,c,d);
                if (me=0) and (d<>'S') then exit('NO');
                if (me=20000) and (d<>'N') then exit('NO');
                //dis:=dis mod 40000;
                if dis>20000 then exit('NO');
                if d='S' then begin
                        me+=dis;
                        if me>20000 then exit('NO');
                end;
                if d='N' then begin
                        me-=dis;
                        if me<0 then exit('NO');
                end;
        end;
        if me=0 then exit('YES');
        exit('NO');
end;
begin
        //fileio;
        enter;
        writeln(solve);
end.

var n,i,j,put,vert,f,gor:integer;
   s,napr:string;
begin
read(n); f:=0;
for i:=1 to n do begin
 read(put,napr);
 delete(napr,1,1);
 if (i=1) and (napr<>'South') then f:=1;
 if napr='South' then vert:=vert+put;
 if napr='North' then vert:=vert-put;
 if napr='West' then gor:=gor-put;
 if napr='East' then gor:=gor+put;
 if f=1 then break;
end;
if (vert<>0) or (gor<>0) then f:=1;
if f=1 then write('NO') else write('YES');
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 if (put=0) and (s<>'South') then x:=2;
 if (put=20000) and (s<>'North') then x:=3;
 if (put<0) then x:=4;
 if (put>20000) then x:=5;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

var k,a,n,i,t:longint;
    dis:string;
begin
read(n);
a:=0;
k:=0;
for i:=1 to n do
   begin
     read(t,dis);
     delete(dis,1,1);
     if ((a=0) and (dis='South')) or ((dis='South') and (a<>0) and (a<>20000))  then
          a:=a+t else
       if ((a=20000) and (dis='North')) or ((dis='North') and (a<>0) and (a<>20000))  then
             a:=a-t else
           if (a<>0) and (a<>20000) and ((dis='East') or (dis='West')) then
                a:=a else
                 begin
                   k:=1;
                   break;
                 end;
     a:=a mod 40000;
   end;
if (k=0) and (a=0) then write('YES') else write('NO');
end.

var ch,i,n,x,q,y,p,w:longint;
    f:boolean;
    s:string;
    a:array[1..100] of longint;
begin
 readln(n);
 x:=0;
 y:=0;
 p:=0;
 f:=true;
 for i:=1 to n do
 begin
  readln(s);
  val(s,ch,q);
  w:=q;
  val(copy(s,1,q-1),ch,q);
  s:=copy(s,w+1,length(s)-w);
  if (p=2)and(s[1]<>'S') then
   f:=false;
  if (p=1)and(s[1]<>'N') then
   f:=false;
  p:=0;
  a[i]:=ch;
  case s[1] of
  'N':  dec(y,ch);
  'E':  dec(x,ch);
  'S':  inc(y,ch);
  'W':  inc(x,ch);
  end;
  x:=abs(x mod 40001);
  if y<0 then
  f:=false;
  if (y<0) then
   p:=1;
  if (y>20000) then
   p:=2;

 end;
 if y<>0 then
 f:=false;
 if f then
 writeln('YES') else
 writeln('NO');
end.

uses math;
const
	fin='';
	fon='';
	maxC=1000000007;
	maxN=107;
type
        data=record
                dis,dir:longint;
        end;
var
        n:longint;
        a:array [0..maxN] of data;

Procedure Openf;
begin
	assign(input,fin); reset(input);
	assign(output,fon); rewrite(output);
end;

Procedure Closef;
begin
	close(input);
	close(output);
End;

function cal(pos:longint):boolean;
var
        now:longint;
        i,x,y:longint;
begin
        if (pos<>1) and (pos<>4) then exit(false);

        x:=0;
        y:=0;
        now:=pos;
        for i:=1 to n do
        if a[i].dis<20001 then
        begin
                if  a[i].dir=1 then x:=x+a[i].dis;
                if  a[i].dir=4 then y:=y+a[i].dis;
                now:=a[i].dir;
        end
        else
        begin
                if (a[i].dis div 20000) mod 2=0 then
                begin
                        if a[i].dir=1 then x:=x+a[i].dis mod 20000;
                        if a[i].dir=4 then y:=y+a[i].dis mod 20000;
                        now:=a[i].dir;
                end
                else
                begin
                        if a[i].dir=4 then x:=x+a[i].dis mod 20000;
                        if a[i].dir=1 then y:=y+a[i].dis mod 20000;
                        now:=5-a[i].dir;
                end;
        end;
        if x<>y then exit(false);

        if now=1 then exit(true);
        exit(false);
end;

Procedure Nhap;
var
        i:longint;
        s:ansistring;
Begin
        readln(n);
        for i:=1 to n do
        with a[i] do
        begin
                readln(dis,s);
                if s=' North' then a[i].dir:=1;
                if s=' East' then a[i].dir:=2;
                if s=' West' then a[i].dir:=3;
                if s=' South' then a[i].dir:=4;

        end;
        if cal(5-a[1].dir) then writeln('YES')
        else writeln('NO');
End;

Procedure xuli;
begin
end;

Procedure Xuat;
begin
end;

Procedure Solve;
begin
	Nhap;
	Xuli;
	Xuat;
end;
BEGIN
	Openf;
	Solve;
	Closef;
END.

var a:array[1..50] of string[6];
    b:array[1..50] of longint;
    i,s,p,n,r:longint;
    data:boolean;
begin
readln(n);
for i:=1 to n do
readln(b[i],a[i]);
s:=0;
for i:=1 to n do begin
if a[i]=
' South' then begin
        if s=20000 then begin data:= true; break end;
        inc(s,b[i]);
        end;
        if a[i]=
' North' then begin
        if s=0 then begin data:= true; break end;
        dec(s,b[i]);
        end;
        if a[i]=
' West' then begin
        if s=0 then begin data:= true; break end;
        inc(r,b[i]);
        end;
        if a[i]=
' East' then begin
        if s=0 then begin data:= true; break end;
        dec(r,b[i]);
        end;
end;
//if (s=0)and(r<>0) then data:=true;
if s<>0 then data:=true;
if data then writeln('NO')
         else writeln('YES')
end.

var k,i, n,s,y,p:integer;
    st, dir:string;
    f:boolean;
begin
    readln(n);
    f:=True;
    s:=0;
    for i:=1 to n do
        begin
             readln(st);
             p:=pos(' ',st);
             dir:=copy(st,p+1,length(st)-p);
             Delete(st, p, length(st)-p+1);
             val(st,k,y);
             if (s=0) or (s-40000*(s div 40000)=0)
                then if dir='South' then
                                      if s+k<=20000 then s:=s+k
                                                   else s:=20000-((s+k) mod 20000)
                                    else f:=False
                else if (s=20000) or (s-40000*(s div 40000)=20000)
                            then if dir='North' then
                                                  if k<=20000 then s:=s-k
                                                              else s:=(s+k) mod 20000
                                                else f:=False
                            else
                              if dir='North' then s:=abs(s-(k mod 40000))
                                             else if dir='South'
                                                      then if s+k<=20000 then s:=s+k
                                                                         else s:=20000-((s+k) mod 20000)
        end;
    if (s-40000*(s div 40000)=0) and (f) then writeln ('YES')
                                         else writeln('NO')
end.

var c,cs,n:integer;s:string;i:integer;
begin
readln(n);
cs:=0;
For i:=1 to n do
 begin
  readln(c,s);
  If ((s=' South')or(s=' North'))and(c>20000)
   then writeln('NO');
  If cs=0 then if s<>' South'
   then begin writeln('NO');
              exit;
        end;
  If cs=20000 then if s<>'North' then begin writeln('NO');exit;end;
  If (s=' South') then cs:=cs+c;
  If (s=' North') then cs:=cs-c;
  If cs > 0 then begin
                   cs:=cs mod 40000;
                   If cs>20000 then cs:=-cs;
                 end
            else begin
                  cs:=cs mod 40000;
                  If cs>-20000 then cs:=-cs;
                 end;
 end;
If cs=0 then writeln('YES') else writeln('NO');
end.

var
  n,now,p,i,d:longint;
  st:string;
  flag:boolean;
begin
  readln(n);
  now:=0;flag:=true;
  for i:=1 to n do
    begin
      readln(st);
      p:=pos(' ',st);
      val(copy(st,1,p-1),d);
      case st[p+1] of
        'S':
          begin
            inc(now,d);
            if d>20000
              then flag:=false;
          end;
        'N':
          begin
            dec(now,d);
            if d<0
              then flag:=false;
          end;
        'E':if (now=0)or(now=20000) then flag:=false;
        'W':if (now=0)or(now=20000) then flag:=false;
      end;
    end;
  if now<>0
    then flag:=false;
  if flag
    then writeln('YES')
    else writeln('NO');
end.

uses math;
var
 s,t:string;
 n,m,i,k,j,f,c,x,y,z,q,w,v,g:longint;
 pp:integer;
begin
 readln(n);
 v:=10000;
 for i:=1 to n do
 begin
  readln(s);
  val(copy(s,1,pos(' ',s)-1),f,pp);
  f:=f mod 40000;
 // writeln(f);
  if(s[pos(' ',s)+1]='N')and(v=10000)then f:=0;
  if(s[pos(' ',s)+1]='S')and(v=-10000)then f:=0;

  if s[pos(' ',s)+1]='N'then inc(v,f)else
  if s[pos(' ',s)+1]='S'then dec(v,f)else
  begin
   if v=-10000 then inc(v,f)else
   if v=10000 then dec(v,f);

  end;
//  writeln(v);
//  writeln;
  if v<-10000 then v:=-10000;
  if v>10000 then v:=10000;
//  writeln(v);
 end;
 if v=10000 then writeln('YES')
 else writeln('NO');
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 readln (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=2;
 if (put=20000) and (s<>'North') then x:=3;
 if (put<0) then x:=4;
 if (put>20000) then x:=5;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 write (put);
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
write (put,' ',x);
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 read (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=2;
 if (put=20000) and (s<>'North') then x:=3;
 if (put<0) then x:=4;
 if (put>20000) then x:=5;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
write (put,' ',x);
end.

program hsfdk;
var n,i:integer;
    td,so:longint;
    st:string;
    kt:boolean;
begin
   readln(n); kt:=true;
   td:=0;
    for i:=1 to n do
     begin
      readln(so,st);
      if kt=true then
      begin
      if(td=0)and(st<>' South')
      or(td=40000)and(st<>' North')then kt:=false;
       if st=' North'then td:=td-so
       else if st=' South'then td:=td+so;
       if(td<0)or(td>40000)then kt:=false;
      end;
     end;
     if td<>0 then kt:=false;
     if kt=true then write('YES')
     else write('NO');
     readln
end.

var t, put, n, i, x: longint;
s: string;
begin
readln (n);
for i:=1 to n do
 begin
 read (t);
 readln (s);
 if (i=1) and (s='South') then put:=t;
 if (i=1) and (s<>'South') then x:=1;
 if (put=0) and (s<>'South') then x:=1;
 if (put=20000) and (s<>'North') then x:=1;
 if (put<0) then x:=1;
 if (put>20000) then x:=1;
 if (i>1) and (s='South') then put:=put+t;
 if (i>1) and (s='North') then put:=put-t;
 end;
if (put=0) and (x=0) then writeln ('YES') else writeln ('NO');
end.

const fi='';
    fo='';
procedure process;
var  s:longint;
    l:1..40000;
    n,i:1..50;
    a:string;
    f,g:text;
begin
    s:=0;
    assign(f,fi);reset(F);
    assign(g,fo);rewrite(g);
    readln(F,n);
    for i:=1 to n do
    begin
        read(f,l);readln(f,a);
        delete(a,1,1);
        if (a[1]='N') then dec(s,l);
        if (a[1]='S') then inc(s,l);
        if (( (a[1]='W') or (a[1]='E') ) and ( (s=0) or (s=20000))) or (s<0) or  (s>20000)  then
        begin
            writeln(g,'No');
            close(F);
            close(g);
            exit;
        end;
    end;
    if (s=0) then write(g,'Yes') else write(g,'No');
    close(F);
    close(g);
end;
begin
    process;
end.