Mock CCC '18 Contest 5 J4/S2 - Reverse Sort

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 1G

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Given a permutation of the first N positive integers and the ability to swap any two adjacent integers, compute the minimum number of swaps needed to sort the list in decreasing order.

Constraints

1 \le N \le 10^3

v_i form a permutation of the first N positive integers.

Input Specification

The first line of the input consists of a single integer, N.

The next line contains N space-separated integers, the permutation of the first N integers.

Output Specification

Output, on a single line, the minimum number of swaps needed.

Sample Input

3
2 1 3

Sample Output

2

Comments

There are no comments at the moment.