#include <bits/stdc++.h>
using namespace std;
int a[314159], t[314159];
long long ans = 0;
void marge_count(int s, int g) {
  if (s + 1 == g) {
    return;
  }
  if (s == g) {
  }
  int m = (s + g) / 2;
  marge_count(s, m);
  marge_count(m, g);
  int p = s, q = m, r = s;
  while (p < m && q < g) {
    if (a[p] < a[q]) {
      t[r++] = a[p++];
      ans += q - m;
    } else {
      t[r++] = a[q++];
    }
  }
  if (p < m) {
    while (p < m) {
      t[r++] = a[p++];
      ans += q - m;
    }
  } else {
    while (q < g) t[r++] = a[q++];
  }
  for (int i = s; i < g; i++) {
    a[i] = t[i];
  }
}
int n;
int main() {
  while (cin >> n && n) {
    ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    marge_count(0, n);
    cout << ans << endl;
  }
  return 0;
}
