#include <bits/stdc++.h>
inline int read() {
  register int x = 0;
  register int y = 1;
  register char c = std::getchar();
  while (c < '0' || c > '9') {
    if (c == '-') y = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return y ? x : -x;
}
int n;
int a[100006];
struct BIT {
  long long tree[100006];
  int n;
  inline void add(int pos, long long x) {
    for (; pos <= n; pos += (pos & (-pos))) tree[pos] += x;
  }
  inline long long ask(int pos) {
    long long ret = 0;
    for (; pos; pos -= (pos & (-pos))) ret += tree[pos];
    return ret;
  }
} T1, T2;
int main() {
  n = read();
  T1.n = T2.n = 100001;
  for (register int i = 1; i <= n; i++) a[i] = read();
  for (register int i = 1; i <= n; i++)
    a[i] = std::abs(a[i]) + 1, T2.add(a[i], 1);
  long long ans = 0;
  for (register int i = 1; i <= n; i++) {
    T2.add(a[i], -1);
    ans += std::min(T1.ask(a[i] - 1), T2.ask(a[i] - 1));
    T1.add(a[i], 1);
  }
  printf("%lld\n", ans);
  return 0;
}
