#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, c = getchar();
  while (c < 48) c = getchar();
  while (c > 47) x = x * 10 + c - '0', c = getchar();
  return x;
}
const int MAXN = 10005;
int a[MAXN], n, ans;
int main(int argc, char const *argv[]) {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1, pre, suf; i <= n; ++i) {
    for (int j = (suf = pre = 0, 1); j < i; ++j) pre += (a[j] < a[i]);
    for (int j = i + 1; j <= n; ++j) suf += (a[j] < a[i]);
    ans += min(pre, suf);
  }
  printf("%d\n", ans);
  return 0;
}
