#include <bits/stdc++.h>
using namespace std;
int BIT[200];
int sum(int a) {
  int b = 0;
  while (a > 0) {
    b += BIT[a];
    a -= a & -a;
  }
  return b;
}
void add(int a) {
  while (a < 110) {
    BIT[a]++;
    a += a & -a;
  }
}
int main() {
  int a;
  while (cin >> a, a) {
    memset(BIT, 0, sizeof(BIT));
    int c = 0;
    for (int b = 0; b < a; b++) {
      int d;
      scanf("%d", &d);
      c += b - sum(d);
      add(d);
    }
    cout << c << endl;
  }
}
