#include <iostream>
#include <vector>
#include <map>
using namespace std;

const int N = 100;
int bit[N+10];

int sum(int i){
	int s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, int x){
	while(i <= N){
		bit[i] += x;
		i += i & -i;
	}
}

vector<int> compress(vector<int> v){
	map<int, int> mp;
	for(int i=0;i<v.size();i++)mp[i] = 0;

	int id = 1;
	for(map<int,int>::iterator it=mp.begin(); it != mp.end(); it++){
		it->second = id++;
	}

	for(int i=0;i<v.size();i++)v[i] = mp[v[i]];

	return v;
}


int main(){
	while(cin >> n && n){
		memset(bit, 0, sizeof(bit));

		vector<int> v(n);
		for(int i=0;i<n;i++)cin >> v[i];

		v = compress(v[i]);

		int ans = 0;
		for(int i=n-1;i>=0;i--){
			ans += sum(v[i] - 1);
			add(v[i], 1);
		}

		cout << ans << endl;
	}

	return 0;
}