#include <bits/stdc++.h>
using namespace std;
int BIT[1000001];
int sum(int idx) {
  int ret = 0;
  while (idx != 0) {
    ret += BIT[idx];
    idx -= idx & -idx;
  }
  return ret;
}
int n;
void add(int idx, int num) {
  while (idx <= n) {
    BIT[idx] += num;
    idx += idx & -idx;
  }
}
signed main() {
  while (cin >> n && n) {
    memset(BIT, 0, sizeof(BIT));
    int ans = 0;
    vector<int> arr(n);
    for (int i = 0; i < int(n); i++) cin >> arr[i];
    for (int i = 0; i < int(n); i++) {
      ans += sum(arr[n - i - 1]);
      add(arr[n - i - 1], 1);
    }
    cout << ans << endl;
  }
  return 0;
}
