#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline void chkmax(T &x, const T2 &y) {
  if (x < y) x = y;
}
template <class T, class T2>
inline void chkmin(T &x, const T2 &y) {
  if (x > y) x = y;
}
const int MAXN = (1 << 20);
template <class T>
struct fenwick {
  int sz;
  T tr[MAXN];
  void init(int n) {
    sz = n + 1;
    memset(tr, 0, sizeof(tr));
  }
  T query(int idx) {
    idx++;
    T ans = 0;
    for (; idx >= 1; idx -= (idx & -idx)) ans += tr[idx];
    return ans;
  }
  void update(int idx, T val) {
    idx++;
    if (idx <= 0) return;
    for (; idx <= sz; idx += (idx & -idx)) tr[idx] += val;
  }
  T query(int l, int r) { return query(r) - query(l - 1); }
};
int n;
pair<int, int> p[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first;
    if (p[i].first < 0) p[i].first *= -1;
    p[i].second = i + 1;
  }
}
fenwick<int> t;
int bef[MAXN], aft[MAXN];
void solve() {
  t.init((int)1e5 + 42);
  for (int i = n - 1; i >= 0; i--) {
    aft[i] = t.query(p[i].first - 1);
    t.update(p[i].first, 1);
  }
  t.init((int)1e5 + 42);
  for (int i = 0; i < n; i++) {
    bef[i] = t.query(p[i].first - 1);
    t.update(p[i].first, 1);
  }
  int64_t answer = 0;
  for (int i = n - 1; i >= 0; i--) answer += min(bef[i], aft[i]);
  cout << answer << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
