{"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\u003eIn a grand event, \u003cstrong\u003eIYKYK\u003c/strong\u003e invited \u003cem\u003en\u003c/em\u003e ministers, journalists, and guests to listen to her long, repetitive speech about her \u003cstrong\u003eবেদনা\u003c/strong\u003e. They arrived and sat in a queue. As expected, the longer people had to endure this never-ending speech, the more bored they became. Findind no way to skip, everyone present said \"কেঁদো না\" hearing \u003cstrong\u003eIYKYK\u003c/strong\u003e\u0027s বেদনা.\u003c/p\u003e\n\n\u003cp\u003eEach person \u003cem\u003ei\u003c/em\u003e is initially seated in position \u003cem\u003ei\u003c/em\u003e in the queue and is characterized by two factors: \u003cstrong\u003ea\u003csub\u003ei\u003c/sub\u003e\u003c/strong\u003e and \u003cstrong\u003eb\u003csub\u003ei\u003c/sub\u003e\u003c/strong\u003e. The boredom of person \u003cem\u003ei\u003c/em\u003e equals the product of \u003cstrong\u003ea\u003csub\u003ei\u003c/sub\u003e\u003c/strong\u003e by the number of people in front of them in the queue, plus the product of \u003cstrong\u003eb\u003csub\u003ei\u003c/sub\u003e\u003c/strong\u003e by the number of people behind them.\u003c/p\u003e\n\n\u003cp\u003eFormally, the boredom of each person \u003cem\u003ei\u003c/em\u003e in position \u003cem\u003ej\u003c/em\u003e can be calculated as:\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e a\u003csub\u003ei\u003c/sub\u003e ⋅ (j−1) + b\u003csub\u003ei\u003c/sub\u003e ⋅ (n−j)\u003c/strong\u003e\u003c/p\u003e\n\n\u003cp\u003e\u003cstrong\u003eYour task:\u003c/strong\u003e Rearrange the seating order to \u003cb\u003eminimize the total boredom of all\u003c/b\u003e the attendees.\u003c/p\u003e\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\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\"\u003eboredom\u003c/span\u003e which can be achieved by rearranging people in the queue.\u003c/p\u003e"}},{"title":"Examples","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":"","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":"","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\"\u003eboredom\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\"\u003eboredom\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\"\u003eboredom\u003c/span\u003e will be equal to $$$6 \\cdot 0+1 \\cdot 2\u003d2$$$. The total \u003cspan class\u003d\"tex-font-style-it\"\u003eboredom\u003c/span\u003e will be $$$12$$$.\u003c/p\u003e\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\"\u003eboredom\u003c/span\u003e will be $$$25$$$.\u003c/p\u003e"}}]}