{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eDuring a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of $$$n$$$ high school students numbered from $$$1$$$ to $$$n$$$. Initially, each student $$$i$$$ is on position $$$i$$$. Each student $$$i$$$ is characterized by two numbers\u0026nbsp;— $$$a_i$$$ and $$$b_i$$$. \u003cspan class\u003d\"tex-font-style-it\"\u003eDissatisfaction\u003c/span\u003e of the person $$$i$$$ equals the product of $$$a_i$$$ by the number of people standing to the left of his position, add the product $$$b_i$$$ by the number of people standing to the right of his position. Formally, the \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e of the student $$$i$$$, which is on the position $$$j$$$, equals $$$a_i \\cdot (j-1) + b_i \\cdot (n-j)$$$.\u003c/p\u003e\n\u003cp\u003eThe director entrusted Stas with the task: rearrange the people in the queue so that \u003cspan class\u003d\"tex-font-style-bf\"\u003eminimize the total\u003c/span\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e.\u003c/p\u003e\n\u003cp\u003eAlthough Stas is able to solve such problems, this was not given to him. He turned for help to you.\u003c/p\u003en个小朋友排队,第i个小朋友的不满意程度是 ai⋅(i−1)+bi⋅(n−i) 请重新排序n个小朋友的位置,使得总的不满意程度最小"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^5$$$)\u0026nbsp;— the number of people in the queue.\u003c/p\u003e\n\u003cp\u003eEach of the following $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \\leq a_i, b_i \\leq 10^8$$$)\u0026nbsp;— the characteristic of the student $$$i$$$, initially on the position $$$i$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput one integer\u0026nbsp;— \u003cspan class\u003d\"tex-font-style-bf\"\u003eminimum total\u003c/span\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e which can be achieved by rearranging people in the queue.\u003c/p\u003e"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\n4 2\n2 3\n6 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\n2 4\n3 3\n7 1\n2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e25\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 3","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e10\n5 10\n12 4\n31 45\n20 55\n30 17\n29 30\n41 32\n7 1\n5 5\n3 15\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1423\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first example it is optimal to put people in this order: ($$$3, 1, 2$$$). The first person is in the position of $$$2$$$, then his \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e will be equal to $$$4 \\cdot 1+2 \\cdot 1\u003d6$$$. The second person is in the position of $$$3$$$, his \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e will be equal to $$$2 \\cdot 2+3 \\cdot 0\u003d4$$$. The third person is in the position of $$$1$$$, his \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e will be equal to $$$6 \\cdot 0+1 \\cdot 2\u003d2$$$. The total \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e will be $$$12$$$.\u003c/p\u003e\n\u003cp\u003eIn the second example, you need to put people in this order: ($$$3, 2, 4, 1$$$). The total \u003cspan class\u003d\"tex-font-style-it\"\u003edissatisfaction\u003c/span\u003e will be $$$25$$$.\u003c/p\u003e"}}]}