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 ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin>>n&&n){
    vary(int,v,n,0);
    rep(i,n){
      cin >> v[i];
    }
    int ans = 0;
    int len = n;
    while(len != 1){
      rep(i,n){
        REP(j,i+1,len){
          if(v[i] > v[j]){
            swap(v[i],v[j]);
            ++ans;
            i = j;
          }
        }
      }
      --len;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

int bubbleSort(int A[], int N) {
    int c = 0;
    bool flag = true;
    for (int i = 0; flag; i++) {
        flag = false;
        for (int j = 1; j < N-i; j++) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                flag = true;
                c++;
            }
        }
    }
    return c;
}

int main()
{
    int A[101];
    int N;

    while (cin >> N) {

        if (N == 0)
            break;

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

        cout << bubbleSort(A, N) << 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 ; 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 <bits/stdc++.h>
using namespace std;

int a[1000001];

void bubble(int *a,int n,int count){
  int ans = count;
  for(int i = 1; i < n; i++){
    if(a[i] < a[i-1]){
      swap(a[i],a[i-1]); count++;
    }
  }
  if(ans != count) bubble(a,n,count);
  else if (ans == count){
    cout << ans << endl;
    return;
  }
}

int main(){
  while(1){
    int n;
    cin >> n; if(n == 0)break;

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

    int count = 0;
    bubble(a,n,count);

    }
    return 0;
}

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(int n = getInt()){
    vector<int> v(n);
    int ans = 0;
    REP(i,n){
      v[i] = getInt();
      REP(j,i){
	if(v[i] < v[j]) ans++;
      }
    }
    print(ans);
  }
  return 0;
}

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

int main(){

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

	return 0;

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		vi d(n);
		rep(i,0,n) cin>>d[i];
		int ans=0,i=0;
		bool f=1;
		while(f){
			f=0;
			for(int j=n-1;j>i;j--){
				if(d[j]<d[j-1]){
					swap(d[j],d[j-1]);
					f=1;
					ans++;
				}
			}
			i++;
		}
		o(ans);
	}
}

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

using namespace std;

int main() {
	int v[100];
	int n;
	int kari;
	int counter;
	
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		counter = 0;
		for (int i = 0; i < n; i++) {
			cin >> v[i];
		}
		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (v[j] > v[j+1]) {
					kari = v[j];
					v[j] = v[j+1];
					v[j+1] = kari;
					counter++;
				}
			}
		}
		cout << counter << endl;
	}
	return 0;
}