#include<algorithm>
#include<iostream>
#include<vector>

typedef long long ll;

ll sz;
ll bit[10001];

void init( ll n )
{
	for( ll i = 0; i != n; ++i )
		bit[i] = 0;

	sz = n;

	return;
}

void add( ll i, ll x )
{
	while( i < sz )
	{
		bit[i] += x;
		i += i & -i;
	}

	return;
}

ll sum( ll i )
{
	ll s = 0;

	while( i > 0 )
	{
		s += bit[i];
		i -= i & -i;
	}

	return s;
}

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		std::vector<int> v;

		for( int i = 0; i != n; ++i )
		{
			int t;
			std::cin >> t;
			v.push_back( t );
		}

		std::sort( v.begin(), v.end() );

		init( n );

		ll ans = 0;
		for( int i = 0; i != n; ++i )
		{
			ans += sum( i + 1 );
			add( i + 1, v[i] );
		}

		std::cout << ans << std::endl;
	}
	return 0;
}