#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define Iter(c) __typeof__((c).begin())
#define foreach(i,c) for(Iter(c) i = (c).begin();i != (c).end();++i)
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int n,a[10000000];

int bit[10000001];

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;
    }
}

void solve()
{
  rep(i,10000000)
    {
      bit[i] = 0;
    }
  ll ans = 0;
  rep(j,n)
    {
      ans += j-sum(a[j]);
      add(a[j],1);
    }
  cout << ans << endl;
}

int main(){
  
  while(cin >> n && n)
    {
      rep(i,n)
	{
	  cin >> a[i];
	}
      solve();
    }
  return 0;
}