{"raw_statement":[{"iden":"problem statement","content":"We have a sequence $A$ of length $N$.\nOn this sequence, we can perform the following two kinds of operations:\n\n*   Swap two adjacent elements.\n    \n*   Select one element, and increment it by $1$.\n    \n\nWe will repeatedly perform these operations so that $A$ will be a non-decreasing sequence. Find the minimum required number of operations."},{"iden":"constraints","content":"*   $1 ≤ N ≤ 200000$\n*   $1 ≤ A_i ≤ 10^9$\n*   $A_i$ is an integer."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$A_1$\n$A_2$\n$:$\n$A_N$"},{"iden":"sample input 1","content":"5\n4\n1\n8\n8\n7"},{"iden":"sample output 1","content":"2\n\nWe can turn $A$ into a non-decreasing sequence in two operations:\n\n*   Initially, $A = {4, 1, 8, 8, 7}$.\n*   Swap the first two elements. Now, $A = {1, 4, 8, 8, 7}$.\n*   Increment the last element by $1$. Now, $A = {1, 4, 8, 8, 8}$."},{"iden":"sample input 2","content":"20\n8\n2\n9\n7\n4\n6\n7\n9\n7\n4\n7\n4\n4\n3\n6\n2\n3\n4\n4\n9"},{"iden":"sample output 2","content":"62"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}