{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eThe \u003cspan class\u003d\"tex2jax_process\"\u003e$n^2$\u003c/span\u003e upper bound\n for any sorting algorithm is easy to obtain: just take two\n elements that are misplaced with respect to each other and swap\n them. Conrad conceived an algorithm that proceeds by taking not\n two, but \u003ci class\u003d\"it\"\u003ethree\u003c/i\u003e misplaced elements. That is,\n take three elements \u003cspan class\u003d\"tex2jax_process\"\u003e$a_{i} \u0026gt;\n a_{j} \u0026gt; a_{k}$\u003c/span\u003e with \u003cspan class\u003d\"tex2jax_process\"\u003e$i\n \u0026lt; j \u0026lt; k$\u003c/span\u003e and place them in order \u003cspan class\u003d\"tex2jax_process\"\u003e$a_{k},a_{j},a_{i}$\u003c/span\u003e. Now if for the\n original algorithm the steps are bounded by the maximum number\n of inversions \u003cspan class\u003d\"tex2jax_process\"\u003e$\\frac{n(n-1)}{2}$\u003c/span\u003e, Conrad is at his\n wits’ end as to the upper bound for such triples in a given\n sequence. He asks you to write a program that counts the number\n of such triples.\u003c/p\u003e\n\n \u003ch2\u003eInput\u003c/h2\u003e\n\n \u003cp\u003eThe first line of the input is the length of the sequence,\n \u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\leq n \\leq 10^5$\u003c/span\u003e. The\n next line contains the integer sequence \u003cspan class\u003d\"tex2jax_process\"\u003e$a_{1},a_{2},\\ldots ,a_{n}$\u003c/span\u003e. You can\n assume that all \u003cspan class\u003d\"tex2jax_process\"\u003e$a_{i} \\in [1,\n n]$\u003c/span\u003e.\u003c/p\u003e\n\n \u003ch2\u003eOutput\u003c/h2\u003e\n\n \u003cp\u003eOutput the number of inverted triples.\u003c/p\u003e\n\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\n1 2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\n3 3 2 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}