#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T Dist(T x1, T y1, T x2, T y2) {
  return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
long long int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
struct z {
  int x, id;
  z() {}
  z(int _, int __) { x = _, id = __; }
  bool operator<(const z &p) const {
    if (x < p.x)
      return true;
    else if (x == p.x)
      return (id < p.id);
    return false;
  }
};
z ar[2002];
int n, LftChoto[2002], RgtChoto[2002], dp[2002][2002];
int Solve(int pos, int neg) {
  if (pos < 0) return 0;
  int &res = dp[pos][neg];
  if (res != -1) return res;
  if (ar[pos + 1].x != ar[pos].x) neg = 0;
  res = Solve(pos - 1, neg + 1) + LftChoto[ar[pos].id];
  res = min(res, Solve(pos - 1, neg) + neg + RgtChoto[ar[pos].id]);
  return res;
}
int main() {
  n = in<int>();
  for (int i = 0; i < n; i++) {
    int x;
    x = in<int>();
    x = abs(x);
    ar[i] = z(x, i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (ar[i].x > ar[j].x) LftChoto[i]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (ar[i].x > ar[j].x) RgtChoto[i]++;
    }
  }
  sort(ar, ar + n);
  for (int i = 0; i < n; i++) {
  }
  ar[n].x = (1 << 28);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", Solve(n - 1, 0));
  return 0;
}

### Prompt

Create a solution in Cpp for 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;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T Dist(T x1, T y1, T x2, T y2) {
  return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
long long int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
struct z {
  int x, id;
  z() {}
  z(int _, int __) { x = _, id = __; }
  bool operator<(const z &p) const {
    if (x < p.x)
      return true;
    else if (x == p.x)
      return (id < p.id);
    return false;
  }
};
z ar[2002];
int n, LftChoto[2002], RgtChoto[2002], dp[2002][2002];
int Solve(int pos, int neg) {
  if (pos < 0) return 0;
  int &res = dp[pos][neg];
  if (res != -1) return res;
  if (ar[pos + 1].x != ar[pos].x) neg = 0;
  res = Solve(pos - 1, neg + 1) + LftChoto[ar[pos].id];
  res = min(res, Solve(pos - 1, neg) + neg + RgtChoto[ar[pos].id]);
  return res;
}
int main() {
  n = in<int>();
  for (int i = 0; i < n; i++) {
    int x;
    x = in<int>();
    x = abs(x);
    ar[i] = z(x, i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (ar[i].x > ar[j].x) LftChoto[i]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (ar[i].x > ar[j].x) RgtChoto[i]++;
    }
  }
  sort(ar, ar + n);
  for (int i = 0; i < n; i++) {
  }
  ar[n].x = (1 << 28);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", Solve(n - 1, 0));
  return 0;
}

```