#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 13, M = 1e5 + 13;
inline int qread() {
  int res = 0, flag = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (isdigit(c)) res = res * 10 + (c - '0'), c = getchar();
  return res * flag;
}
int n, m, a[N];
inline int Abs(const int &x) { return x < 0 ? -x : x; }
inline long long min(const long long &x, const long long &y) {
  return x < y ? x : y;
}
inline int max(const int &x, const int &y) { return x > y ? x : y; }
struct BIT {
  int t[M];
  inline int lowbit(int x) { return x & -x; }
  inline void add(int x, int y) {
    while (x <= m) t[x] += y, x += lowbit(x);
  }
  inline int sum(int x) {
    int res = 0;
    while (x) res += t[x], x -= lowbit(x);
    return res;
  }
} T1, T2, T3;
int main() {
  n = qread();
  for (int i = 1, x; i <= n; ++i) {
    x = qread();
    a[i] = Abs(x);
    ++a[i];
    m = max(m, a[i]);
  }
  long long sum = 0;
  for (int i = n; i >= 1; --i) {
    sum += T1.sum(a[i] - 1);
    T1.add(a[i], 1);
  }
  long long ans = sum, tot = 0;
  for (int i = 1; i <= n; ++i) {
    if (T2.sum(a[i] - 1) >= T1.sum(a[i] - 1) - T3.sum(a[i])) {
      T1.add(a[i], -1);
      T3.add(a[i], 1);
      ++tot;
    } else {
      sum -= T1.sum(a[i] - 1) + tot - T3.sum(a[i]);
      T1.add(a[i], -1);
      sum += T2.sum(a[i] - 1) + tot;
      T2.add(a[i], 1);
      ans = min(ans, sum);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
