#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast", "-funroll-all-loops", "-ffast-math")
using namespace std;
using LL = long long;
constexpr LL mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ex_gcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long ret = ex_gcd(b, a % b, y, x);
  y -= a / b * x;
  return ret;
}
LL bin(LL x, LL n, LL MOD) {
  LL ret = MOD != 1;
  for (x %= MOD; n; n >>= 1, x = x * x % MOD)
    if (n & 1) ret = ret * x % MOD;
  return ret;
}
LL norm(LL x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline long long get_inv(long long a) {
  long long x, y;
  ex_gcd(a, mod, x, y);
  return norm(x + mod);
}
template <class T>
inline void umin(T &x, T y) {
  x = x > y ? y : x;
}
template <class T>
inline void umax(T &x, T y) {
  x = x < y ? y : x;
}
template <class T>
inline void dec(T &x, T y) {
  x -= y;
  if (x < 0) x += mod;
}
template <class T>
inline void add(T &x, T y) {
  x += y;
  if (x >= mod) x -= mod;
}
const double PI = acos(-1.0);
constexpr LL INF = 0x3f3f3f3f;
constexpr long long linf = 0x3f3f3f3f3f3f3f3f;
constexpr unsigned long long base = 2333, P_1 = 19260817, P_2 = 999998639;
constexpr LL maxn = 1e6 + 10;
LL n;
struct BIT {
  LL c[maxn];
  LL lowbit(LL i) { return i & (-i); }
  void insert(LL i, LL x) {
    for (; i <= maxn; i += lowbit(i)) {
      c[i] += x;
    }
  }
  LL getsum(LL i) {
    LL sum = 0;
    for (; i; i -= lowbit(i)) {
      sum += c[i];
    }
    return sum;
  }
} T1, T2;
LL a[maxn];
int32_t main() {
  std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),
      cout << fixed << setprecision(10);
  cin >> n;
  for (LL i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = abs(a[i]) + 1;
    T1.insert(a[i], 1);
  }
  long long ans = 0;
  for (LL i = 1; i <= n; i++) {
    ans += min(T1.getsum(a[i] - 1), T2.getsum(a[i] - 1));
    T1.insert(a[i], -1);
    T2.insert(a[i], 1);
  }
  cout << ans << '\12';
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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>
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast", "-funroll-all-loops", "-ffast-math")
using namespace std;
using LL = long long;
constexpr LL mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ex_gcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long ret = ex_gcd(b, a % b, y, x);
  y -= a / b * x;
  return ret;
}
LL bin(LL x, LL n, LL MOD) {
  LL ret = MOD != 1;
  for (x %= MOD; n; n >>= 1, x = x * x % MOD)
    if (n & 1) ret = ret * x % MOD;
  return ret;
}
LL norm(LL x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline long long get_inv(long long a) {
  long long x, y;
  ex_gcd(a, mod, x, y);
  return norm(x + mod);
}
template <class T>
inline void umin(T &x, T y) {
  x = x > y ? y : x;
}
template <class T>
inline void umax(T &x, T y) {
  x = x < y ? y : x;
}
template <class T>
inline void dec(T &x, T y) {
  x -= y;
  if (x < 0) x += mod;
}
template <class T>
inline void add(T &x, T y) {
  x += y;
  if (x >= mod) x -= mod;
}
const double PI = acos(-1.0);
constexpr LL INF = 0x3f3f3f3f;
constexpr long long linf = 0x3f3f3f3f3f3f3f3f;
constexpr unsigned long long base = 2333, P_1 = 19260817, P_2 = 999998639;
constexpr LL maxn = 1e6 + 10;
LL n;
struct BIT {
  LL c[maxn];
  LL lowbit(LL i) { return i & (-i); }
  void insert(LL i, LL x) {
    for (; i <= maxn; i += lowbit(i)) {
      c[i] += x;
    }
  }
  LL getsum(LL i) {
    LL sum = 0;
    for (; i; i -= lowbit(i)) {
      sum += c[i];
    }
    return sum;
  }
} T1, T2;
LL a[maxn];
int32_t main() {
  std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),
      cout << fixed << setprecision(10);
  cin >> n;
  for (LL i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = abs(a[i]) + 1;
    T1.insert(a[i], 1);
  }
  long long ans = 0;
  for (LL i = 1; i <= n; i++) {
    ans += min(T1.getsum(a[i] - 1), T2.getsum(a[i] - 1));
    T1.insert(a[i], -1);
    T2.insert(a[i], 1);
  }
  cout << ans << '\12';
  return 0;
}

```