{"raw_statement":[{"iden":"problem statement","content":"You are given two integer sequences $A$ and $B$ of length $N$. For $k = 1, 2, \\ldots, N$, solve the following problem:\n\n*   Consider choosing $k$ distinct integers between $1$ and $N$, inclusive. Let $S$ be the set of chosen integers. Find the maximum value of $\\displaystyle (\\sum_{i \\in S} A_i) - \\max_{i \\in S} B_i$."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 2 \\times 10^5$\n*   $-10^9 \\leq A_i \\leq 10^9$\n*   $-2 \\times 10^{14} \\leq B_i \\leq 2 \\times 10^{14}$"},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $B_1$\n$A_2$ $B_2$\n$\\vdots$\n$A_N$ $B_N$"},{"iden":"sample input 1","content":"3\n4 1\n5 6\n3 2"},{"iden":"sample output 1","content":"3\n5\n6\n\nThe following choices are optimal.\n\n*   $k = 1$: $S = {1}$\n*   $k = 2$: $S = {1, 3}$\n*   $k = 3$: $S = {1, 2, 3}$"},{"iden":"sample input 2","content":"2\n0 1\n0 1"},{"iden":"sample output 2","content":"\\-1\n-1"},{"iden":"sample input 3","content":"6\n9 7\n2 4\n7 1\n-1000 0\n3 4\n8 5"},{"iden":"sample output 3","content":"6\n10\n17\n20\n22\n-978"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}