Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			arr[i], _ = strconv.Atoi(scanner.Text())
		}
		cnt := 0
		for i := n-1; i  > 0; i-- {
			for j := 0; j < i; j++ {
				if arr[j] > arr[j+1] {
					// log.Println(arr)
					cnt++
					arr[j], arr[j+1] = arr[j+1], arr[j]
				}
			}
		}
		// log.Println(arr)
		fmt.Println(cnt)
	}
}

C++: #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;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;

int main(){
  int n,i,j,k,c,a[1000000];

  while(cin>>n&&n!=0){
    for(i=0;i<n;i++){
      cin>>a[i];
    }
    
    for(k=0,i=0;i<n-1;i++){
      for(j=i;j<n;j++){
	if(a[i]>a[j]){
	  c=a[i];
	  a[i]=a[j];
	  a[j]=c;
	  k++;
	} 
      }
    }
    cout<<k<<endl;
  }
return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int a[100];
		for(int i=0;i<n;i++)	cin>>a[i];

		int cnt=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n-i-1;j++)
				if(a[j]>a[j+1])	swap(a[j],a[j+1]),cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
	int n;

	while(cin >> n && n)
	{
		int data[100000]={};
		unsigned long long count=0;

		for(int i=0;i<n;i++)
		{
			cin >> data[i];
		}

		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(data[i]>data[j])
				{
					swap(data[i],data[j]);
					count++;
				}
			}
		}
		cout << count << endl;
	}

    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> a(n);
        for(int i=0; i<n; ++i)
            cin >> a[i];

        int ret = 0;
        for(int i=0; i<n; ++i){
            for(int j=i+1; j<n; ++j){
                if(a[i] > a[j])
                    ++ ret;
            }
        }
        cout << ret << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;
	int k[100];
	int kari;
	int counter;

	while(cin >> n) {
		if (n == 0) {
			break;
		}
		counter = 0;
		for (int i = 0; i < n; i++) {
			cin >> k[i];
		}

		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j< i; j++) {
				if (k[j] > k[j+1]) {
					kari = k[j];
					k[j] = k[j+1];
					k[j+1] = kari;
					counter++;
				}
			}
		}

		cout << counter << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

int N;
int n[1000001]={};

while(1){
scanf("%d",&N);

int c=0;

for(int i=0;i<N;i++){
scanf("%d",&n[i];

for(int i=0;i<N;i++)
for(int j=N-1;j>i;j--)
{if(n[j]<n[j-1]){int T=n[j];n[j]=n[j-1];n[j-1]=T;c++}

printf("%d\n",c);
}
return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;

int main(){
  int n,i,j,k,c,a[1000001];

  while(cin>>n&&n!=0){
    
    for(i=0;i<n;i++){
      cin>>a[i];
    }
    k=0;
    for(i=0;i<n-1;i++){
      for(j=i;j<n;j++){
	if(a[i]>a[j]){
	  c=a[i];
	  a[i]=a[j];
	  a[j]=c;
	  k++;
	} 
      }
    }
    //  for(i=0;i<n;i++){
    //cout<<a[i]<<endl;
    //}
    cout<<k<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;

int main() {
  int n;
  while (cin >> n && n) {
    vector<int> v;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      v.push_back(a);
    }
    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        if (v[i] > v[j]) {
          count++;
        }
      }
    }
    cout << count << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

int a[100];
int main() {
	int b;
	while (cin >> b, b) {
		for (int c = 0; c<b; c++)scanf("%d", &a[c]);
		int sum = 0;
		for (int d = 0; d < b - 1; d++) {
			for (int e = d + 1; e < b; e++) {
				if (a[d] > a[e])sum++;
			}
		}
		cout << sum << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
struct BIT
{
	int bit[105];
	BIT(){memset(bit,0,sizeof(bit));}
	void add(int i,int x)
	{
		while(i<=100)
		{
			bit[i]+=x;
			i+=i&-i;
		}
	}
	int sum(int i)
	{
		int res=0;
		while(i>0)
		{
			res+=bit[i];
			i-=i&-i;
		}
		return res;
	}
};
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		vector<int> v(n),zip;
		for(int i=0;i<n;i++)cin >> v[i];
		zip=v;
		sort(all(zip));
		for(int i=0;i<n;i++)v[i]=lower_bound(all(zip),v[i])-zip.begin()+1;
		int ans=0;
		BIT bit;
		for(int i=n-1;i>=0;i--)
		{
			ans += bit.sum(v[i]-1);
			bit.add(v[i],1);
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<iostream>
using namespace std; 
int main (){
  int n,i,a[110],temp,count=0,j;
  while(1){
    count=0;
    cin >> n;
    if(n==0)break;
    for(i=0;i<n;i++){
      cin >> a[i];
    }
    for(i=0;i<n;i++){
      for(j=n-1;j>i;j--){
	if(a[j-1]>a[j]){
	  temp=a[j];
	  a[j]=a[j-1];
	  a[j-1]=temp;
	  count++;
	}
      }
    }
    cout << count << endl;
  }
}