粘个板子
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 500005
#define ll long long
using namespace std;
ll c[maxn << 2], s[maxn << 2], a[maxn << 2], b[maxn << 2];
ll n;
int lowbit(int x){return x & (-x);}
void update(ll i,int x){
while(i <= n){
c[i] += x;
i += lowbit(i);
}
}
ll Sum(ll x){
ll sum = 0;
while(x > 0){
sum += c[x];
x -= lowbit(x);
}
return sum;
}
int main()
{
while(~scanf("%lld",&n)){
if(n == 0) break;
memset(c, 0, sizeof(c));
ll ans = 0;
int m;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
a[i] += 1000000000;
b[i] = a[i];
}
sort(b + 1, b + n + 1);
int len = unique(b + 1, b + n + 1) - b - 1;
for(int i=1;i<=n;i++){
a[i] = lower_bound(b + 1, b + len + 1, a[i]) - b;
update(a[i], 1);
ans += (ll)i - Sum(a[i]);
}
printf("%lld\n",ans);
}
return 0;
}