#include <bits/stdc++.h>
int main(void) {
  int N;
  int i, j;
  int count;
  int box[100];
  int tmp;
  while (1) {
    scanf("%d", &N);
    if (N == 0) {
      break;
    }
    count = 0;
    for (i = 0; i < N; i++) {
      scanf("%d", &box[i]);
    }
    for (i = 0; i < N - 1; i++) {
      for (j = 0; j = N - i - 1; j++) {
        if (box[j] > box[j + 1]) {
          tmp = box[j];
          box[j] = box[j + 1];
          box[j + 1] = tmp;
          count++;
        }
      }
    }
    printf("%d/n", count);
  }
  return (0);
}
