{"raw_statement":[{"iden":"statement","content":"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.\n\nLimak, 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_\".\n\nLimak isn’t sure whether the description is valid. You must help him to check the following conditions:\n\n*   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.\n*   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.\n*   The journey must end on the North Pole.\n\nCheck if the above conditions are satisfied and print \"_YES_\" or \"_NO_\" on a single line."},{"iden":"input","content":"The first line of the input contains a single integer _n_ (1 ≤ _n_ ≤ 50).\n\nThe _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."},{"iden":"output","content":"Print \"_YES_\" if the description satisfies the three conditions, otherwise print \"_NO_\", both without the quotes."},{"iden":"examples","content":"Input\n\n5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n\nOutput\n\nYES\n\nInput\n\n2\n15000 South\n4000 East\n\nOutput\n\nNO\n\nInput\n\n5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North\n\nOutput\n\nYES\n\nInput\n\n3\n20000 South\n10 East\n20000 North\n\nOutput\n\nNO\n\nInput\n\n2\n1000 North\n1000 South\n\nOutput\n\nNO\n\nInput\n\n4\n50 South\n50 North\n15000 South\n15000 North\n\nOutput\n\nYES"},{"iden":"note","content":"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.\n\n<center>![image](https://espresso.codeforces.com/82aeb8679ccf80c9c32a555b44bfd640c64f9cc4.png)</center>"}],"translated_statement":"[{\"iden\":\"statement\",\"content\":\"在本题中，我们假设地球是一个完美的球体，其表面为一个标准球面。赤道和任意一条子午线的长度均被认定为恰好 #cf_span[40 000] 公里。因此，从北极到南极或反之旅行恰好需要 #cf_span[20 000] 公里。\\n\\nLimak 是一只生活在北极的北极熊。临近新年，他帮助他人向世界各地递送包裹。与直接获得地点坐标不同，Limak 得到了一份描述，说明他应如何从北极出发移动。该描述由 #cf_span[n] 个部分组成。在第 #cf_span[i] 个部分中，Limak 应沿方向为字符串 #cf_span[diri] 的路径移动 #cf_span[ti] 公里，其中 #cf_span[diri] 可能是以下之一：\\\"_North_\\\"、\\\"_South_\\\"、\\\"_West_\\\"、\\\"_East_\\\"。\\n\\nLimak 不确定这份描述是否有效。你需要帮助他检查以下条件：\\n\\n请判断上述条件是否满足，并在一行中输出 \\\"_YES_\\\" 或 \\\"_NO_\\\"。\\n\\n输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 50])。\\n\\n接下来的 #cf_span[n] 行中，第 #cf_span[i] 行包含一个整数 #cf_span[ti] 和一个字符串 #cf_span[diri] (#cf_span[1 ≤ ti ≤ 106]) —— 根据 Limak 所得描述，第 #cf_span[i] 段旅程的长度和方向。\\n\\n如果描述满足三个条件，则输出 \\\"_YES_\\\"，否则输出 \\\"_NO_\\\"，均不带引号。\\n\\n下图展示了前两个样例中 Limak 的行进路线。在第二个样例中，答案为 \\\"_NO_\\\"，因为他没有最终回到北极。\"},{\"iden\":\"input\",\"content\":\"输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 50])。接下来的 #cf_span[n] 行中，第 #cf_span[i] 行包含一个整数 #cf_span[ti] 和一个字符串 #cf_span[diri] (#cf_span[1 ≤ ti ≤ 106]) —— 根据 Limak 所得描述，第 #cf_span[i] 段旅程的长度和方向。\"},{\"iden\":\"output\",\"content\":\"如果描述满足三个条件，则输出 \\\"_YES_\\\"，否则输出 \\\"_NO_\\\"，均不带引号。\"},{\"iden\":\"examples\",\"content\":\"输入\\n5\\n7500 South\\n10000 East\\n3500 North\\n4444 West\\n4000 North\\n输出\\nYES\\n\\n输入\\n2\\n15000 South\\n4000 East\\n输出\\nNO\\n\\n输入\\n5\\n20000 South\\n1000 North\\n1000000 West\\n9000 North\\n10000 North\\n输出\\nYES\\n\\n输入\\n3\\n20000 South\\n10 East\\n20000 North\\n输出\\nNO\\n\\n输入\\n2\\n1000 North\\n1000 South\\n输出\\nNO\\n\\n输入\\n4\\n50 South\\n50 North\\n15000 South\\n15000 North\\n输出\\nYES\"},{\"iden\":\"note\",\"content\":\"下图展示了前两个样例中 Limak 的行进路线。在第二个样例中，答案为 \\\"_NO_\\\"，因为他没有最终回到北极。 \"}]\n\n[{\"iden\":\"statement\",\"content\":\"在本题中，我们假设地球是一个完美的球体，其表面为一个标准球面。赤道和任意一条子午线的长度均被认定为恰好 #cf_span[40 000] 公里。因此，从北极到南极或反之旅行恰好需要 #cf_span[20 000] 公里。\\n\\nLimak 是一只生活在北极的北极熊。临近新年，他帮助他人向世界各地递送包裹。与直接获得地点坐标不同，Limak 得到了一份描述，说明他应如何从北极出发移动。该描述由 #cf_span[n] 个部分组成。在第 #cf_span[i] 个部分中，Limak 应沿方向为字符串 #cf_span[diri] 的路径移动 #cf_span[ti] 公里，其中 #cf_span[diri] 可能是以下之一：\\\"_North_\\\"、\\\"_South_\\\"、\\\"_West_\\\"、\\\"_East_\\\"。\\n\\nLimak 不确定这份描述是否有效。你需要帮助他检查以下条件：\\n\\n请判断上述条件是否满足，并在一行中输出 \\\"_YES_\\\" 或 \\\"_NO_\\\"。\\n\\n输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 50])。\\n\\n接下来的 #cf_span[n] 行中，第 #cf_span[i] 行包含一个整数 #cf_span[ti] 和一个字符串 #cf_span[diri] (#cf_span[1 ≤ ti ≤ 106]) —— 根据 Limak 所得描述，第 #cf_span[i] 段旅程的长度和方向。\\n\\n如果描述满足三个条件，则输出 \\\"_YES_\\\"，否则输出 \\\"_NO_\\\"，均不带引号。\\n\\n下图展示了前两个样例中 Limak 的行进路线。在第二个样例中，答案为 \\\"_NO_\\\"，因为他没有最终回到北极。\"},{\"iden\":\"input\",\"content\":\"输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 50])。接下来的 #cf_span[n] 行中，第 #cf_span[i] 行包含一个整数 #cf_span[ti] 和一个字符串 #cf_span[diri] (#cf_span[1 ≤ ti ≤ 106]) —— 根据 Limak 所得描述，第 #cf_span[i] 段旅程的长度和方向。\"},{\"iden\":\"output\",\"content\":\"如果描述满足三个条件，则输出 \\\"_YES_\\\"，否则输出 \\\"_NO_\\\"，均不带引号。\"},{\"iden\":\"examples\",\"content\":\"输入\\n5\\n7500 South\\n10000 East\\n3500 North\\n4444 West\\n4000 North\\n输出\\nYES\\n\\n输入\\n2\\n15000 South\\n4000 East\\n输出\\nNO\\n\\n输入\\n5\\n20000 South\\n1000 North\\n1000000 West\\n9000 North\\n10000 North\\n输出\\nYES\\n\\n输入\\n3\\n20000 South\\n10 East\\n20000 North\\n输出\\nNO\\n\\n输入\\n2\\n1000 North\\n1000 South\\n输出\\nNO\\n\\n输入\\n4\\n50 South\\n50 North\\n15000 South\\n15000 North\\n输出\\nYES\"},{\"iden\":\"note\",\"content\":\"下图展示了前两个样例中 Limak 的行进路线。在第二个样例中，答案为 \\\"_NO_\\\"，因为他没有最终回到北极。 \"}]","sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of journey segments.  \nLet $ T = \\{(t_i, d_i) \\mid i \\in \\{1, \\dots, n\\}\\} $ be the sequence of journey parts, where:  \n- $ t_i \\in \\mathbb{Z}^+ $ is the distance traveled in segment $ i $,  \n- $ d_i \\in \\{\\text{North}, \\text{South}, \\text{West}, \\text{East}\\} $ is the direction.  \n\nThe Earth is a perfect sphere with circumference $ 40{,}000 $ km; thus, the distance from North Pole to South Pole is $ 20{,}000 $ km.  \n\n**Constraints**  \n1. $ 1 \\leq n \\leq 50 $  \n2. $ 1 \\leq t_i \\leq 10^6 $ for all $ i $  \n\n**Objective**  \nSimulate Limak’s journey starting at the North Pole. Define position as a pair $ (lat, lon) $, where:  \n- Latitude $ lat \\in [-20{,}000, 20{,}000] $: $ 0 $ at equator, $ +20{,}000 $ at North Pole, $ -20{,}000 $ at South Pole.  \n- Longitude $ lon \\in [0, 40{,}000) $: modulo $ 40{,}000 $, with $ 0 $ as reference.  \n\nInitial position: $ (lat, lon) = (20{,}000, 0) $.  \n\nFor each segment $ i $:  \n- If $ d_i = \\text{North} $: $ lat \\leftarrow lat + t_i $  \n- If $ d_i = \\text{South} $: $ lat \\leftarrow lat - t_i $  \n- If $ d_i = \\text{East} $ or $ d_i = \\text{West} $:  \n  - Only valid if $ lat \\in (-20{,}000, 20{,}000) $ (i.e., not at a pole)  \n  - Then: $ lon \\leftarrow (lon + t_i) \\bmod 40{,}000 $ if $ d_i = \\text{East} $,  \n    $ lon \\leftarrow (lon - t_i) \\bmod 40{,}000 $ if $ d_i = \\text{West} $  \n\n**Conditions to Check**  \n1. At no point during the journey should $ lat > 20{,}000 $ or $ lat < -20{,}000 $.  \n2. If $ lat = \\pm 20{,}000 $ (at a pole), the next direction **must not** be East or West.  \n3. After all segments, $ lat = 20{,}000 $ and $ lon \\equiv 0 \\pmod{40{,}000} $ (back at North Pole).  \n\n**Output**  \nPrint \"YES\" if all conditions are satisfied; otherwise, print \"NO\".","simple_statement":null,"has_page_source":false}