{"raw_statement":[{"iden":"statement","content":"Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strange order so they had to create this new tower using already produced rings.\n\nThere are _n_ rings in factory's stock. The _i_\\-th ring has inner radius _a__i_, outer radius _b__i_ and height _h__i_. The goal is to select some subset of rings and arrange them such that the following conditions are satisfied:\n\n*   Outer radiuses form a non-increasing sequence, i.e. one can put the _j_\\-th ring on the _i_\\-th ring only if _b__j_ ≤ _b__i_.\n*   Rings should not fall one into the the other. That means one can place ring _j_ on the ring _i_ only if _b__j_ > _a__i_.\n*   The total height of all rings used should be maximum possible."},{"iden":"input","content":"The first line of the input contains a single integer _n_ (1 ≤ _n_ ≤ 100 000) — the number of rings in factory's stock.\n\nThe _i_\\-th of the next _n_ lines contains three integers _a__i_, _b__i_ and _h__i_ (1 ≤ _a__i_, _b__i_, _h__i_ ≤ 109, _b__i_ > _a__i_) — inner radius, outer radius and the height of the _i_\\-th ring respectively."},{"iden":"output","content":"Print one integer — the maximum height of the tower that can be obtained."},{"iden":"examples","content":"Input\n\n3\n1 5 1\n2 6 2\n3 7 3\n\nOutput\n\n6\n\nInput\n\n4\n1 2 1\n1 3 3\n4 6 2\n5 7 1\n\nOutput\n\n4"},{"iden":"note","content":"In the first sample, the optimal solution is to take all the rings and put them on each other in order 3, 2, 1.\n\nIn the second sample, one can put the ring 3 on the ring 4 and get the tower of height 3, or put the ring 1 on the ring 2 and get the tower of height 4."}],"translated_statement":[{"iden":"statement","content":"当然，你一定听说过著名的汉诺塔问题，但你是否知道，有一个专门生产该游戏圆环的特殊工厂？从前，古埃及的统治者命令汉诺工厂的工人建造尽可能高的塔。他们并不准备接受如此奇怪的命令，因此不得不使用已生产的圆环来建造这座新塔。\n\n工厂库存中有 #cf_span[n] 个圆环。第 #cf_span[i] 个圆环的内半径为 #cf_span[ai]，外半径为 #cf_span[bi]，高度为 #cf_span[hi]。目标是从中选择一个子集，并将它们按如下条件排列：\n\n输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100 000]) —— 工厂库存中的圆环数量。\n\n接下来的 #cf_span[n] 行中，第 #cf_span[i] 行包含三个整数 #cf_span[ai]、#cf_span[bi] 和 #cf_span[hi] (#cf_span[1 ≤ ai, bi, hi ≤ 10^9]，#cf_span[bi > ai]) —— 分别表示第 #cf_span[i] 个圆环的内半径、外半径和高度。\n\n请输出一个整数 —— 可以获得的塔的最大高度。\n\n在第一个测试用例中，最优解是取所有圆环，并按 #cf_span[3]、#cf_span[2]、#cf_span[1] 的顺序叠放。\n\n在第二个测试用例中，可以将圆环 #cf_span[3] 放在圆环 #cf_span[4] 上，得到高度为 #cf_span[3] 的塔；或将圆环 #cf_span[1] 放在圆环 #cf_span[2] 上，得到高度为 #cf_span[4] 的塔。"},{"iden":"input","content":"输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100 000]) —— 工厂库存中的圆环数量。第 #cf_span[i] 行接下来的 #cf_span[n] 行包含三个整数 #cf_span[ai]、#cf_span[bi] 和 #cf_span[hi] (#cf_span[1 ≤ ai, bi, hi ≤ 10^9]，#cf_span[bi > ai]) —— 分别表示第 #cf_span[i] 个圆环的内半径、外半径和高度。"},{"iden":"output","content":"请输出一个整数 —— 可以获得的塔的最大高度。"},{"iden":"examples","content":"输入\n3\n1 5 1\n2 6 2\n3 7 3\n输出\n6\n\n输入\n4\n1 2 1\n1 3 3\n4 6 2\n5 7 1\n输出\n4"},{"iden":"note","content":"在第一个测试用例中，最优解是取所有圆环，并按 #cf_span[3]、#cf_span[2]、#cf_span[1] 的顺序叠放。在第二个测试用例中，可以将圆环 #cf_span[3] 放在圆环 #cf_span[4] 上，得到高度为 #cf_span[3] 的塔；或将圆环 #cf_span[1] 放在圆环 #cf_span[2] 上，得到高度为 #cf_span[4] 的塔。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of rings.  \nFor each ring $ i \\in \\{1, \\dots, n\\} $, define:  \n- $ a_i \\in \\mathbb{Z}^+ $: inner radius,  \n- $ b_i \\in \\mathbb{Z}^+ $: outer radius, with $ b_i > a_i $,  \n- $ h_i \\in \\mathbb{Z}^+ $: height.  \n\nA tower is a sequence of rings $ (i_1, i_2, \\dots, i_k) $ such that for all $ j \\in \\{1, \\dots, k-1\\} $, the outer radius of ring $ i_j $ is **greater than** the inner radius of ring $ i_{j+1} $:  \n$$\nb_{i_j} > a_{i_{j+1}}.\n$$\n\n**Constraints**  \n1. $ 1 \\le n \\le 100{,}000 $  \n2. $ 1 \\le a_i, b_i, h_i \\le 10^9 $  \n3. $ b_i > a_i $ for all $ i $\n\n**Objective**  \nMaximize the total height of a valid tower:  \n$$\n\\max \\sum_{j=1}^k h_{i_j}\n$$  \nover all valid sequences $ (i_1, \\dots, i_k) $ satisfying the stacking condition.","simple_statement":null,"has_page_source":false}