{"raw_statement":[{"iden":"problem statement","content":"You are given a permutation $P=(P_1,P_2,\\cdots,P_N)$ of $(1,2,\\cdots,N)$.\nYou want to perform zero or more swaps of adjacent elements so that $P$ satisfies the following condition:\n\n*   The number of indices $i$ such that $P_i > P_{i+1}$ is at most $1$.\n\nFind the minimum number of swaps required."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 800000$\n*   $(P_1,P_2,\\cdots,P_N)$ is a permutation of $(1,2,\\cdots,N)$.\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$P_1$ $P_2$ $\\cdots$ $P_N$"},{"iden":"sample input 1","content":"3\n3 2 1"},{"iden":"sample output 1","content":"1\n\nSwapping $P_1$ and $P_2$ turns $P$ into $(2,3,1)$, which satisfies the condition."},{"iden":"sample input 2","content":"4\n2 4 1 3"},{"iden":"sample output 2","content":"0"},{"iden":"sample input 3","content":"6\n2 3 1 6 4 5"},{"iden":"sample output 3","content":"1"},{"iden":"sample input 4","content":"20\n8 13 6 11 20 3 12 18 17 4 10 1 7 16 19 5 2 15 14 9"},{"iden":"sample output 4","content":"36"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}