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<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    int co=0;
    rep(i,n)cin>>in[i];
    rep(i,n){
      rep(j,n-i-1){
	if(in[j]>in[j+1]){
	  co++;
	  swap(in[j],in[j+1]);
	}
      }
    }
    cout<<co<<endl;
  }
}

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

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

C++: #include <iostream>
#include <string.h>
using namespace std;
//BIT
long bit[101],n;
long sum(int i){
	long s=0;
	while(i>0){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}
void add(long i,long x){
	while(i<=n){
		bit[i]+=x;
		i+=i&-i;
	}
}
long a[100];
bool input(){
	cin >> n; if(!n) return false;
	for(int i=0;i<n;i++) cin >> a[i];
	return true;
}
int main() {
	while(input()) {
		long long ans=0;
		for(int i=0;i<n;i++) {
			ans+=i-sum(a[i]);
			add(a[i],1);
		}
		cout << ans << '\n' ;
		memset(bit,0,sizeof(bit));
	}
}

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



//配列の要素数
//#define MAX	1000000
#define MAX	100000

int h_input[MAX] = {0};


int main(void)
{
	//入力変数
	int n = 0;

	while (true)
	{
		cin >> n;
		if (n == 0)	{	return 0;	}

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

		//カウント変数
		int count = 0;

		for (int i = n - 1; i >= 0; i--)
		{
			for (int j = 1; j <= i; j++)
			{
				if (h_input[j - 1] > h_input[j])
				{
					int tmp = h_input[j];
					h_input[j] = h_input[j - 1];
					h_input[j - 1] = tmp;

					count++;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> a(n);
		REP(i, n) scanf("%d", &a[i]);
		
		int ans = 0;
		REP(i, n) FOR(j, 1, n - i) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, m[100], i, j, c;
	while (cin >> n && n)
	{
		c = 0;
		for (i = 0; i < n; i++)
			cin >> m[i];
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (m[j] > m[j+1])
				{
					swap(m[j], m[j+1]);
					c++;
				}
			}
		}
		cout << c << endl;
	}
}

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

int main(void){
	int n;
	while(cin>>n,n){
		int t[n];
		for(int i=0;i<n;i++){
			cin>>t[i];
		}
		if(n == 1){
			cout<<0<<endl;
			continue;
		}
		int ans = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n-i;j++){
				if(t[j] > t[j+1]){
					ans++;
					swap(t[j],t[j+1]);
				}
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

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

const int N = 100;
int bit[N+10];

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;
	}
}

vector<int> compress(vector<int> v){
	map<int, int> mp;
	for(int i=0;i<v.size();i++)mp[i] = 0;

	int id = 1;
	for(map<int,int>::iterator it=mp.begin(); it != mp.end(); it++){
		it->second = id++;
	}

	for(int i=0;i<v.size();i++)v[i] = mp[v[i]];

	return v;
}


int main(){
        int n;
	while(cin >> n && n){
		memset(bit, 0, sizeof(bit));

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

		v = compress(v[i]);

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

		cout << ans << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int d[n], ans = 0;
    rep(i, n) cin >> d[i];
    for (int i = 1; i < n; i++)
      for (int j = 0; j < n - i; j++)
        if (d[j] > d[j + 1]) {
          swap(d[j], d[j + 1]);
          ans++;
        }
    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
	int n;
	int array[100];

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

	return (0);
}