#include <bits/stdc++.h>
using namespace std;
void File() {
  freopen("inverse.in", "r", stdin);
  freopen("inverse.out", "w", stdout);
}
template <typename T>
void read(T &_) {
  _ = 0;
  T f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) _ = (_ << 1) + (_ << 3) + (c ^ '0');
  _ *= f;
}
const int maxn = 1e6 + 10;
const int N = 1e6;
int n, a[maxn];
long long ans;
struct BIT {
  int sum[maxn];
  int lowbit(int x) { return x & (-x); }
  void add(int p, int x) {
    for (; p <= N; p += lowbit(p)) sum[p] += x;
  }
  int query(int p) {
    int ret = 0;
    for (; p >= 1; p -= lowbit(p)) ret += sum[p];
    return ret;
  }
} T1, T2;
int main() {
  read(n);
  for (int i = 1, i_end_ = n; i <= i_end_; ++i)
    read(a[i]), a[i] = abs(a[i]) + 1;
  for (int i = 1, i_end_ = n; i <= i_end_; ++i) T1.add(a[i], 1);
  for (int i = 1, i_end_ = n; i <= i_end_; ++i) {
    ans += min(T1.query(a[i] - 1), T2.query(a[i] - 1));
    T1.add(a[i], -1);
    T2.add(a[i], 1);
  }
  printf("%lld\n", ans);
  return 0;
}
