{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eFarmer John\u0027s \u003ci\u003eN\u003c/i\u003e (1 ≤ \u003ci\u003eN\u003c/i\u003e ≤ 10,000) cows are lined up to be milked in the evening. Each cow has a unique \"grumpiness\" level in the range 1...100,000. Since grumpy cows are more likely to damage FJ\u0027s milking equipment, FJ would like to reorder the cows in line so they are lined up in increasing order of grumpiness. During this process, the places of any two cows (not necessarily adjacent) can be interchanged. Since grumpy cows are harder to move, it takes FJ a total of \u003ci\u003eX\u003c/i\u003e+\u003ci\u003eY\u003c/i\u003e units of time to exchange two cows whose grumpiness levels are \u003ci\u003eX\u003c/i\u003e and \u003ci\u003eY\u003c/i\u003e.\u003c/p\u003e\u003cp\u003ePlease help FJ calculate the minimal time required to reorder the cows.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Line 1: A single integer: \u003ci\u003eN\u003c/i\u003e.\r\u003cbr\u003eLines 2..\u003ci\u003eN\u003c/i\u003e+1: Each line contains a single integer: line \u003ci\u003ei\u003c/i\u003e+1 describes the grumpiness of cow \u003ci\u003ei\u003c/i\u003e.\r\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Line 1: A single line with the minimal time required to reorder the cows in increasing order of grumpiness."}},{"title":"Sample","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\r\n2\r\n3\r\n1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e7\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"2 3 1 : Initial order. \r\u003cbr\u003e2 1 3 : After interchanging cows with grumpiness 3 and 1 (time\u003d1+3\u003d4). \r\u003cbr\u003e1 2 3 : After interchanging cows with grumpiness 1 and 2 (time\u003d2+1\u003d3). "}}]}