#include <bits/stdc++.h>
using namespace std;
const int LIM = 200001, FAT = 100001;
int c[2][200005], a[1000005];
int read() {
  int A;
  bool K;
  char C;
  C = A = K = 0;
  while (C < '0' || C > '9') K |= C == '-', C = getchar();
  while (C > '/' && C < ':') A = (A << 3) + (A << 1) + (C ^ 48), C = getchar();
  return (K ? -A : A);
}
void add(bool rem, int x, int v) {
  while (x <= LIM) c[rem][x] += v, x += ((x) & -(x));
}
int sum(bool rem, int x) {
  int s = 0;
  while (x) s += c[rem][x], x -= ((x) & -(x));
  return s;
}
int main() {
  int n, i;
  long long tot = 0;
  n = read();
  for (i = 1; i <= (n); i++) a[i] = abs(read());
  for (i = n; i >= (1); i--) add(0, a[i] + FAT, 1);
  for (i = 1; i <= (n); i++) {
    add(0, a[i] + FAT, -1);
    if (i - 1 - sum(1, a[i] + FAT) + sum(0, a[i] + FAT - 1) >
        i - 1 - sum(1, FAT - a[i]) + sum(0, FAT - a[i] - 1))
      a[i] = -a[i];
    tot += i - 1 - sum(1, a[i] + FAT);
    add(1, a[i] + FAT, 1);
  }
  cout << tot;
  return 0;
}
