#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int bit[maxn];
int n;
int a[maxn];
void clear() { memset(bit, 0, sizeof(bit)); }
void add(int x) {
  for (; x < maxn; x += x & -x) ++bit[x];
}
int sum(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret += bit[x];
  return ret;
}
int cnt[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i), a[i] = abs(a[i]) + 1;
  clear();
  for (int i = 1; i <= n; ++i) {
    cnt[i] = sum(a[i] - 1);
    add(a[i]);
  }
  clear();
  int ans = 0;
  for (int i = n; i >= 1; --i) {
    ans += min(cnt[i], sum(a[i] - 1));
    add(a[i]);
  }
  printf("%d\n", ans);
}
