#T347. 光荣的梦想
光荣的梦想
Description
Prince was satisfied with the order he had maintained on this continent and decided to depart from Azeroth. Before setting off, Prince resolved to bestow upon King_Bette the most formidable power to safeguard the world and preserve its balance and harmony. In that era, balance was but a dream. Countless peculiar species possessed various forms of unstable energy, disrupting the equilibrium in an instant. KB decided to seek your help to fulfill this dream.
A sequence of numbers represents the state of the world.
Balance means the sequence is arranged in ascending order. To transform an unordered sequence into an ordered one, adjacent elements must be swapped. KB's power only allows him to swap two adjacent numbers. He wants to know the minimum number of swaps required to sort the sequence.
Input Format
The first line contains an integer n, the number of elements in the sequence.
The second line contains n numbers (where n ≤ 10000), representing the current state of the sequence.
Output Format
Output an integer, indicating the minimum number of swaps needed to achieve a balanced state.
4
2 1 4 3
2