##### Canadian Computing Olympiad: 2020 Day 1, Problem 2

Bob has programming exercises that he needs to complete before their deadlines. Exercise only takes one time unit to complete, but has a deadline time units from now.

Bob will solve the exercises in an order described by a sequence , such that is the first exercise he solves, is the second exercise he solves, and so on. Bob's original plan is described by the sequence . With one *swap* operation, Bob can exchange two adjacent numbers in this sequence. What is the minimum number of swaps required to change this sequence into one that completes all exercises on time?

#### Input Specification

The first line consists of a single integer . The next line contains space-separated integers .

For 17 of the 25 available marks, .

#### Output Specification

Output a single integer, the minimum number of swaps required for Bob to solve all exercises on time, or `-1`

if this is impossible.

#### Sample Input 1

```
4
4 4 3 2
```

#### Sample Output 1

`3`

#### Explanation for Output for Sample Input 1

One valid sequence is , which can be obtained from by three swaps.

#### Sample Input 2

```
3
1 1 3
```

#### Sample Output 2

`-1`

#### Explanation of Output for Sample Input 2

There are two exercises that are due at time , but only one exercise can be solved by this time.

## Comments

can an editorial be opened for this problem?