{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i \u0026lt; j and ai \u0026gt; aj. \n \u003cbr\u003e \n \u003cbr\u003eFor a given sequence of numbers a1, a2, ..., an, if we move the first m \u0026gt;\u003d 0 numbers to the end of the seqence, we will obtain another sequence. There are totally n such sequences as the following: \n \u003cbr\u003e \n \u003cbr\u003ea1, a2, ..., an-1, an (where m \u003d 0 - the initial seqence) \n \u003cbr\u003ea2, a3, ..., an, a1 (where m \u003d 1) \n \u003cbr\u003ea3, a4, ..., an, a1, a2 (where m \u003d 2) \n \u003cbr\u003e... \n \u003cbr\u003ean, a1, a2, ..., an-1 (where m \u003d n-1) \n \u003cbr\u003e \n \u003cbr\u003eYou are asked to write a program to find the minimum inversion number out of the above sequences. \n \u003cbr\u003e \n\u003cp\u003e\n 给定一个由0到n−1组成,长度为n每个元素唯一的序列,可以进行一种操作,把第一个元素放到最后一个位置。求经过若干次操作后的,最小逆序对数。\n\u003c/p\u003e\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input consists of a number of test cases. Each case consists of two lines: the first line contains a positive integer n (n \u0026lt;\u003d 5000); the next line contains a permutation of the n integers from 0 to n-1. \n\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each case, output the minimum inversion number on a single line. \n\u003cbr\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e10\n1 3 6 9 0 8 5 7 4 2\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e16\u003c/pre\u003e"}}]}