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 <bits/stdc++.h>
using namespace std;

int main()
{
	int n, res;
	while (cin >> n, n) {
		vector<int> v;
		v.reserve(n);
		for (int i = 0, tmp; i < n; i++) {
			cin >> tmp;
			v.push_back(tmp);
		}
		bool flag = true;
		res = 0;
		while (flag) {
			flag = false;
			for (int i = 0, tmp;i < v.size() - 1;i++) {
				if (v[i] > v[i + 1]) {
					tmp = v[i];
					v[i] = v[i + 1];
					v[i + 1] = tmp;
					flag = true;
					res++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	int in[100];
	int i, j;
	int ans;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0)break;
		
		for (i = 0; i < n; i++){
			scanf("%d", &in[i]);
		}
		
		for (i = 0; i < n - 1; i++){
			for (j = 0; j < n - i - 1; j++){
				if (in[j] > in[j + 1]){
					in[j] += in[j + 1];
					in[j + 1] = in[j] - in[j + 1];
					in[j] -= in[j + 1];
					
					ans++;
				}
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

int a[102],n;

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int ans=0;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(int i=0;i<n-1;i++){
			for(int j=i;j<n;j++){
				if(a[j]>a[j+1]){
					ans++;
					swap(a[j],a[j+1]);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility> 

using namespace std;

int main()
{
	while (1)
 { 
	int n, k;
	k = 0;
	vector<int> A;
	cin >> n;
	if (n==0)
	{
		break;
	}
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}
	for (int j = 0; j < n;j++)
	{
		for (int i = 0; i < n-1; i++)
		{
			if (A[i]>A[i + 1])
			{
				swap(A[i], A[i + 1]);
				k++;
			}
		}
	}
	cout << k << endl;
 }
	return 0;
}

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

int main(void){
	int n;
	while(cin>>n,n){
		vector<int> sort;
		int inp , cnt = 0;
		for(int i = 0 ; i < n ; i ++){
			cin>>inp;
			sort.push_back(inp);
		}
		for(int i = 0 ; i < n ; i ++)
			for(int j = i ; j < n ; j ++){
				if(sort[i] > sort[j]){
					int work = sort[i];
					sort[i] = sort[j];
					sort[j] = work;
					cnt ++;
				}
			}
			
		cout<< cnt <<endl;
	}
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


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

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

int main(void){
	int n;
	while(cin>>n,n){
		vector<int> sort;
		int inp , cnt = 0;
		for(int i = 0 ; i < n ; i ++){
			cin>>inp;
			sort.push_back(inp);
		}
		for(int i = 0 ; i < n - 1 ; i ++)
			for(int j = i + 1 ; j < n ; j ++){
				if(sort[i] > sort[j]){
					int work = sort[i];
					sort[i] = sort[j];
					sort[j] = work;
					cnt ++;
				}
			}
			
		cout<< cnt <<endl;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(int argc, char **argv){
	int n;
	while (cin >> n && n != 0){
		vector<int> v;
		for (int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp;
			v.push_back(tmp);
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - i - 1; j++) {
				if (v[j] > v[j + 1]) {
					swap(v[j], v[j + 1]);
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> list;
    int x,n,i,s,sum;
    while(1){
        cin >> n;
        if(n==0){break;}
        for(i=0;i<n;i++){
            cin >> x; 
            list.push_back(x);
        }
        sum=0;
        i=0;
        for(int j=0; j<list.size()-1; j++){
        for(i=0; i<list.size()-1; i++){
            if(list[i]>list[i+1]){
                s=list[i];
                list[i]=list[i+1];
                list[i+1]=s;
                sum++;
            }
        }
        }
        cout << sum << endl;
        list.clear();
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    for(int n; cin >> n && n;)
	{
		int res = 0;
		vint v(n);
		
		rep(i, n) cin >> v[i];
		
		for(int j = n - 1; 0 < j; j--) for(int i = 0; i < j; i++) 
		{
			if(v[i] > v[i + 1])
			{
				swap(v[i], v[i + 1]);
				res++;
			}
		}
		
		cout << res << endl;
	}		
}

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

using namespace std;

int main()
{
	int n;

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

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

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

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include <cassert>

using namespace std;

int N, A[100];
int W[100];

int merge_and_count(int l,int r){
	if (l + 1 >= r)return 0;
	if (l + 2 == r){
		if (A[l] <= A[l + 1])return 0;
		swap(A[l], A[l + 1]);
		return 1;
	}
	int m = (l + r) / 2;
	int cl = merge_and_count(l, m);
	int cr = merge_and_count(m, r);
	int c = 0;
	int i = 1, j = m;
	int k = 1;
	while (i < m && j < r){
		if (A[i] <= A[j])W[k++] = A[i++];
		else{
			W[k++] = A[j++];
			c += i-j-1;
		}
	}
	while (i < m)W[k++] = A[i++];
	while (j < r)W[k++] = A[j++];
	assert(k == r);
	return cl + cr + c;
}

int main()
{
	cin >> N;
	for (int n = 0; n < N; n++){
		cin >> A[n];
	}
	cout << merge_and_count(0, N) << endl;
}