#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100;

int a[MAX_N];
int k[MAX_N];
int bit[MAX_N+1],n;
map<int,int> mp;

//i???????????§??????????¨??????????(i???1????????????)
int sum(int i)
{
	int s = 0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
//i???????????????x????????????(i???1????????????)
void add(int i,int x)
{
	while(i <= n){
		bit[i] += x;
		i += i & -i;
	}
}

int main()
{
	while(1){
	cin >> n;
	if(n==0){
		break;
	}
	rep(i,n){
		scanf("%d",&a[i]);
		k[i] = a[i];
		mp[a[i]] = i;
	}
	sort(a,a+n);
	rep(i,n){
		k[mp[a[i]]] = i+1;
	}
	fill(bit,bit+n+1,0);
	ll ans = 0;
	rep(j,n){
		ans += j - sum(k[j]);
		add(k[j],1);
	}
	printf("%lld\n",ans);
	}
	return 0;
}