#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
struct BIT
{
	int bit[105];
	BIT(){memset(bit,0,sizeof(bit));}
	void add(int i,int x)
	{
		while(i<=100)
		{
			bit[i]+=x;
			i+=i&-i;
		}
	}
	int sum(int i)
	{
		int res=0;
		while(i>0)
		{
			res+=bit[i];
			i-=i&-i;
		}
		return res;
	}
};
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		vector<int> v(n),zip;
		for(int i=0;i<n;i++)cin >> v[i];
		zip=v;
		sort(all(zip));
		for(int i=0;i<n;i++)v[i]=lower_bound(all(zip),v[i])-zip.begin()+1;
		int ans=0;
		BIT bit;
		for(int i=n-1;i>=0;i--)
		{
			ans += bit.sum(v[i]-1);
			bit.add(v[i],1);
		}
		printf("%d\n",ans);
	}
	return 0;
}