#include <iostream>
#define max 80005
using namespace std;
int main()
{
int i,j,n,sum;
int num[max];
sum=0;
while(cin>>n)
{
if(n==0)break;
for(i=1;i<=n;++i)
cin>>num[i];
for (i=1;i<=n-1;++i)
for (j=i+1;j<=n;++j)
{
if(num[j]<num[i])
sum++;
else
j=n+1;
}
}
cout<<sum<<endl;
return 0;
}
#define max 80005
using namespace std;
int main()
{
int i,j,n,sum;
int num[max];
sum=0;
while(cin>>n)
{
if(n==0)break;
for(i=1;i<=n;++i)
cin>>num[i];
for (i=1;i<=n-1;++i)
for (j=i+1;j<=n;++j)
{
if(num[j]<num[i])
sum++;
else
j=n+1;
}
}
cout<<sum<<endl;
return 0;
}