## Algorithm

B. New Year and North Pole
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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 ≤ 106) — 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.

Examples
input
Copy
`57500 South10000 East3500 North4444 West4000 North`
output
Copy
`YES`
input
Copy
`215000 South4000 East`
output
Copy
`NO`
input
Copy
`520000 South1000 North1000000 West9000 North10000 North`
output
Copy
`YES`
input
Copy
`320000 South10 East20000 North`
output
Copy
`NO`
input
Copy
`21000 North1000 South`
output
Copy
`NO`
input
Copy
`450 South50 North15000 South15000 North`
output
Copy
`YES`
Note

Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````#include <iostream>
#include <vector>
#include <string>

using namespace std;

vector<pair<int, string> > arr;

int main() {
int n, tmp;
string s;
cin >> n;

while(n--) {
cin >> tmp >> s;
arr.push_back(make_pair(tmp, s));
}

if(arr[arr.size()-1].second != "North" || arr[0].second != "South") {
cout << "NO" << endl;
return 0;
}

int x = 0, in = 1;

for(int i = 0; i < arr.size(); i++) {
if(in == 1 && arr[i].second != "South") {
cout << "NO" << endl;
return 0;
}

if(in == 2 && arr[i].second != "North") {
cout << "NO" << endl;
return 0;
}

if(arr[i].second == "North")
x -= arr[i].first;

if(arr[i].second == "South")
x += arr[i].first;

if(x > 20000 || x < 0) {
cout << "NO" << endl;
return 0;
}

if(x == 0) in = 1;
else if(x == 20000) in = 2;
else in = 3;
}

if(x == 0) cout << "YES" << endl;
else cout << "NO" << endl;

return 0;
}``````
Copy The Code &

Input

cmd
5
7500 South
10000 East
3500 North
4444 West
4000 North

Output

cmd
YES