#P467. 练84.2 光荣的梦想

练84.2 光荣的梦想

Description

Prince was satisfied with the order he maintained on this continent and decided to leave Azeroth. Before his departure, Prince decided to grant King_Bette the most powerful energy to protect the world and maintain its balance and harmony. In that era, balance was a dream. Because there were many strange species with various unstable energies, balance could be broken in an instant. KB decided to seek your help to fulfill this dream.
A sequence of numbers represents the state of a world.
Balance means the sequence is arranged in ascending order. To transform an unordered sequence into an ordered one, elements in the sequence need to be swapped. KB's energy can only swap adjacent numbers. He wants to know the minimum number of swaps needed to make the sequence ordered.

Input Format

The first line contains an integer nn, representing the number of elements in the sequence.
The second line contains nn numbers (n10000n ≤ 10000), representing the current state of the sequence.

Output Format

Output a single integer, representing the minimum number of swaps needed to achieve balance.

Sample

4
2 1 4 3
2