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 <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 = 0 ; j < n - i - 1; ++j)
			{
				if(Vec[j] > Vec[j + 1])
				{
					int temp = Vec[j];
					Vec[j] = Vec[j + 1];
					Vec[j + 1] = temp;
					++count;
				}
			}
		}
		cout << count << endl;
	}
}

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

C++: #include<stdio.h>
int main(){
  int n,k;
  int i,j;
  int count;
  while(scanf("%d",&n)){
    if(n==0) break;
    int index[n];
    count = 0;
    for(i=0;i<n;i++) scanf("%d",&index[i]);
    for(i=n-1;i>0;i--){
      for(j=0;j<i;j++){
	if(index[j]>index[j+1]){
	  k = index[j];
	  index[j] = index[j+1];
	  index[j+1] = k;
	  count++;
	}
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

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

using namespace std;

int main(){
  int n,cnt;
  int a[101] = {};
  while(1){
    cin >> n;
    if(n == 0)break;
    cnt = 0;
    for(int i=0;i<n;i++){
      cin >>a[i];
    }
    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]);
	  cnt++;}
      }

    
    cout << cnt << endl;
      }

  }

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int a[120];
int n;
int cnt =0;
void bubblesort(){
	for(int i = n-1;i >0;i--){
		for(int j =0;j < i;j++){
			if(a[j+1]<a[j]){
				swap(a[j],a[j+1]);
				cnt++;
			}
		}
	}
}

int main(){

	while(cin>>n,n){
		cnt = 0;
		for(int i =0;i <120;i++){
			a[i]=0;
		}
		for(int i =0;i < n;i++){
			cin>>a[i];
		}
		/*rep(i,n){
			cout <<a[i];
			if(i!=n-1)cout <<" ";
		}cout <<endl;*/
		bubblesort();
		/*rep(i,n){
			cout <<a[i];
			if(i!=n-1)cout <<" ";
		}
		cout <<endl;*/
		cout <<cnt<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		rep(i,n)cin>>in[i];
		int co=0;
		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 <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> v(N);
        for (auto& i : v) cin >> i;

        int count = 0;
        while (1) {
            bool flag = false;
            for (int i = 0; i < v.size()-1; i++) {
                if (v[i] > v[i+1]) {
                    count++;
                    swap(v[i], v[i+1]);
                    flag = true;
                }
            }
            if (!flag) break;
        }
        cout << count << endl;
    }

    return 0;
}

C++: #include<stdio.h>
 
int main(){
	int a, b[100], i, j, c, count = 0;
	while(scanf("%d", &a) != 0){
		if(a == 0) break;
		for(i = 0; i < a; i++) scanf("%d", &b[i]);
		for(i = 0; i < a - 1; i++){
			for(j = i + 1; j < a; j++){
				if(b[i] < b[j]){
					c = b[i];
					b[i] = b[j];
					b[j] = c;
					count++;
				}
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t,n;
  long long int bell[100],tmp;
  while(1){
    t=0;

    cin >> n;
    if(n==0){
      break;
    }
    for(int i=0;i<n;i++){
      cin >> bell[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(bell[j]<bell[j-1]){
	  tmp=bell[j];
	  bell[j]=bell[j-1];
	  bell[j-1]=tmp;
	  t++;
	}
      }
    }
    cout << t << endl;
  }
}

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 (int i = 0; i < (n); i++)

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

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;

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

C++: #include <stdio.h>

int main(void) {

  int n;
  int a[100];

  int step;

  int temp;
  int i,j;

  while(1) {

    scanf("%d",&n);

    if(n==0) break;

    step=0;

    for(i=0;i<n;i++) {

      scanf("%d",&a[i]);

    }

    for(i=0;i<n-1;i++) {

      for(j=0;j<n-i-1;j++) {

	if(a[j]>a[j+1]) {

	  temp=a[j];
	  a[j]=a[j+1];
	  a[j+1]=temp;

	  step++;

	}

      }

    }

    printf("%d\n",step);

  }

  return 0;

}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
#define PB push_back
#define pb push_back
#define mp make_pair
#define FI first
#define SE second


typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
/*-------------------------------*/

int main(void)
{
  int n;
  int a[108];

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

    int cnt = 0;
    rep(i, n) cin >> a[i];

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

  return 0;
}