#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000005];
long long ans;
int main() {
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i];
    a[i] = abs(a[i]);
  }
  for (int i = (1); i <= (n); ++i) {
    int L = 0, R = 0;
    for (int j = (1); j <= (i - 1); ++j) {
      if (a[j] < a[i]) L++;
    }
    for (int j = (i + 1); j <= (n); ++j) {
      if (a[j] < a[i]) R++;
    }
    ans += min(L, R);
  }
  cout << ans;
}

### Prompt

Your task is to create a Cpp solution to the following problem:

Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday.

Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds.

Jeff can multiply some numbers of the sequence p by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get.

Input

The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.

Output

In a single line print the answer to the problem — the minimum number of inversions Jeff can get.

Examples

Input

2
2 1


Output

0


Input

9
-2 0 -1 0 -1 2 1 0 -1


Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000005];
long long ans;
int main() {
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i];
    a[i] = abs(a[i]);
  }
  for (int i = (1); i <= (n); ++i) {
    int L = 0, R = 0;
    for (int j = (1); j <= (i - 1); ++j) {
      if (a[j] < a[i]) L++;
    }
    for (int j = (i + 1); j <= (n); ++j) {
      if (a[j] < a[i]) R++;
    }
    ans += min(L, R);
  }
  cout << ans;
}

```