/*vector_change POJ2299*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#define N 500010
#define LL long long
using namespace std;
struct node
{
int ord;
LL v;
} p[N+1];
int a[N];
int c[N];
int n;
int cmp( node a, node b)
{
return a.v < b.v;
}
int lowbit( int t ) // 2^k
{
return t&(-t);
}
int getsum( int n ) //1...n
{
int sum = 0;
while( n > 0 )
{
sum += c[n];
n -= lowbit(n);
}
return sum;
}
void update(int pos, int val)
{
while( pos <= n)
{
c[pos] += val;
pos += lowbit(pos);
}
}
int main()
{
//freopen("1.txt", "r", stdin);
while( ~scanf("%d", &n) && n )
{
long long sum = 0;
for( int i=1; i<=n; i++)
{
scanf("%lld", &p[i].v);
p[i].ord = i;
}
sort(p+1, p+n+1, cmp);
for( int i=1; i<=n; i++)
{
a[p[i].ord] = i;
}
memset(c, 0, sizeof(c));
for( int i=1; i<=n; i++)
{
update(a[i], 1);
sum += i - getsum(a[i]);
}
printf("%lld\n", sum);
}
return 0;
}