New Year and North Pole
time limit per test 2 second memory limit per test 256 megabytes
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.
Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: “North”, “South”, “West”, “East”.
Limak isn’t sure whether the description is valid. You must help him to check the following conditions
If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.
If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.
The journey must end on the North Pole.
Check if the above conditions are satisfied and print “YES” or “NO” on a single line.

传送门:CF750B

Input

The first line of the input contains a single integer n (1≤n≤50). The i-th of next n lines contains an integer ti and a string diri (1≤ti≤1e6, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

Output

Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.

Sample Input

1
2
3
4
5
6
5
7500 South
10000 East
3500 North
4444 West
4000 North

Sample Output

1
YES

题解

简单模拟,途中不能变向
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.*;  
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int biaodu=20000; //northpole
int flag=0;
boolean result=true;
for(int o=1;o<=n;o++){
int temp=sc.nextInt();
String s=sc.next();
if(flag==0&&!s.equals("South")){//northpole
result=false;
}
if(flag==1&&!s.equals("North")){
result=false;
}
if(s.equals("South")){
biaodu-=temp;
if(biaodu<0){
result=false;
}
else if(biaodu==0){
flag=1;
}
else flag=3;
}
else if(s.equals("North")){
biaodu+=temp;
if(biaodu>20000){
result=false;
}
else if(biaodu==20000){
flag=0;
}
else flag=3;

}
}
if(result){
if(biaodu==20000){
System.out.println("YES");
}
else
System.out.println("NO");
}
else
System.out.println("NO");
}
}
}