750B.md (2787B)
1 Source: https://codeforces.com/problemset/problem/750/B 2 3 B. New Year and North Pole 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 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 *t**i* kilometers in the direction represented by a string *dir**i* that is one of: "North", "South", "West", "East". 24 25 Limak isn’t sure whether the description is valid. You must help him to check the following conditions: 26 27 * 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. 28 * 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. 29 * The journey must end on the North Pole. 30 31 Check if the above conditions are satisfied and print "YES" or "NO" on a single line. 32 33 Input 34 35 The first line of the input contains a single integer *n* (1 ≤ *n* ≤ 50). 36 37 The *i*-th of next *n* lines contains an integer *t**i* and a string *dir**i* (1 ≤ *t**i* ≤ 106, ) — the length and the direction of the *i*-th part of the journey, according to the description Limak got. 38 39 Output 40 41 Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes. 42 43 Examples 44 45 Input 46 47 ``` 48 5 49 7500 South 50 10000 East 51 3500 North 52 4444 West 53 4000 North 54 ``` 55 56 Output 57 58 ``` 59 YES 60 ``` 61 62 Input 63 64 ``` 65 2 66 15000 South 67 4000 East 68 ``` 69 70 Output 71 72 ``` 73 NO 74 ``` 75 76 Input 77 78 ``` 79 5 80 20000 South 81 1000 North 82 1000000 West 83 9000 North 84 10000 North 85 ``` 86 87 Output 88 89 ``` 90 YES 91 ``` 92 93 Input 94 95 ``` 96 3 97 20000 South 98 10 East 99 20000 North 100 ``` 101 102 Output 103 104 ``` 105 NO 106 ``` 107 108 Input 109 110 ``` 111 2 112 1000 North 113 1000 South 114 ``` 115 116 Output 117 118 ``` 119 NO 120 ``` 121 122 Input 123 124 ``` 125 4 126 50 South 127 50 North 128 15000 South 129 15000 North 130 ``` 131 132 Output 133 134 ``` 135 YES 136 ``` 137 138 Note 139 140 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. 141 142 