Mega Inversions
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
The upper bound for any sorting algorithm is easy to obtain: just take two elements that are misplaced with respect to each other and swap them. Conrad conceived an algorithm that proceeds by taking not two, but three misplaced elements. That is, take three elements with and place them in order . Now if for the original algorithm the steps are bounded by the maximum number of inversions , Conrad is at his wits' end as to the upper bound for such triples in a given sequence. He asks you to write a program that counts the number of such triples.
Input
The first line is the length of the sequence .
The next line contains the integer sequence .
Output
Print the number of inverted triples.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 708
Acceptance rate 38%