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>
using namespace std;

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

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(){
	int a[100];
	int n;

	while(scanf("%d",&n) && n != 0){
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		int swap = 0;
		for(int i=n-1;i>0;i--){
			for(int j=0;j<i;j++){
				if(a[j]>a[j+1]){
					int temp = a[j];
					a[j] = a[j+1];
					a[j+1] = temp;
					swap++;
				}
			}
		}
		cout<<swap<<endl;
	}
	return 0;
}

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


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

int main(){
	int a[100],n;
	while(cin>>n&&n){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		cout<<inversion(a,n)<<endl;
	}
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const double EPS = 1e-8;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi data(n);
		rep(i, n)
			scanf("%d", &data[i]);
		
		int cnt = 0;
		rep(i, n-1){
			rep(j, n-i-1){
				if(data[j] > data[j+1]){
					swap(data[j], data[j+1]);
					++cnt;
				}
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

void temp(int *x, int *y)
{
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

int main(void)
{
	int n;
	while(cin >> n && n != 0)
	{
		vector<int> a(n);
		for (int i = 0; i < n; ++i)
			cin >> a[i];

		int counter = 0;

		for (int i = n; i > 0; --i)
		{
			for(int k = 0;k < i-1;k++)
			{
				if(a[k] > a[k+1])
				{
					temp(&a[k], &a[k+1]);
					counter++;
				}
			}
		}

		cout << counter << endl;
	}

	return 0;
}

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

C++: #include<cstdio>
int main(){
	int a[102],i,j,k;
	for(;scanf("%d",a),*a;printf("%d\n",k)){
		for(i=1;i<=*a; i++)scanf("%d",*(a+i++));
		k=0;
		for(j=*a;j>1;j--)
			for(i=2;i<=j;i++)
				if(a[i-1]>a[i])
					a[i-1]^=a[i],a[i]^a[i-1],a[i-1]^=a[i],k++;
	}
}

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

int main(){

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

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

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

	return 0;
}

C++: #include<stdio.h>
int n[1000001]={};
int main(){

int N;

int c=0;
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);
for(int i=0;i<N;i++)
	n[i]=0;

}
return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
void sort(int A[], int C, int N){
	int c=0;
	for(int i=0;i<N-1;i++){
		if(A[i]>A[i+1]){
			swap(A[i],A[i+1]);
			c++;
		}
	}
	if(c==0) cout << C << endl;
	else{
		C+=c;
		sort(A,C,N);
	}
}

int main(){
	int n;
	while(cin >> n,n){
		int a[n],count=0;
		for(int i=0;i<n;i++) cin >> a[i];
		sort(a,count,n);
	}
}

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 += m-i;
		}
	}
	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;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
using namespace std;
#define all(a) a.begin(),a.end()
int main()
{
	int n;
	while(cin>>n&&n)
	{
		vector<int> a;
		for(int i=0;i<n;i++)
		{
			int x;cin>>x;
			a.push_back(x);
		}
		int ans=0;
		bool ok=true;
		while(ok)
		{
			ok=false;
			for(int i=0;i<n-1;i++)
			{
				if(a[i]>a[i+1])
				{
					ans++;ok=true;
					swap(a[i],a[i+1]);
				}
			}
		}
		cout<<ans<<endl;
		
		
		
	}
	
}

C++: #include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int INF=100000000;
int main(){
  int n;
  while(cin>>n,n!=0){
    int a[20];
    int c=0;
    rep(i,n)cin>>a[i];
    for(int i=0;i<n;i++){
      for(int j=0;j<n-1-i;j++){
	if(a[j]>a[j+1]){
	  int temp;
	  temp=a[j];
	  a[j]=a[j+1];
	  a[j+1]=temp;
	  c++;
	}
      }
    }
    cout<<c<<endl;
  }
  return 0;
}

C++: #include<iostream>

int a[100];

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		for( int i = 0; i != n; ++i )
			std::cin >> a[i];

		int ans = 0;
		for( int i = 0; i != n; ++i )
			for( int j = 0; j != n - i - 1; ++j )
				if( a[j] > a[j+1] )
					std::swap( a[j], a[j+1] ), ++ans;

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

	return 0;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >>n, n)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		int count = 0;
		for(int i = 0; i < n; ++i)
		{
			for(int j = i + 1; j < n; ++j)
			{
				if(Vec[i] > Vec[j])
				{
					int temp = Vec[i];
					Vec[i] = Vec[j];
					Vec[j] = temp;
					count++;
				}
			}
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}