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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	int a[110];
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			a[i]=in();
		}
		int j;
		int res=0;
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){
				if(a[i]>a[j])res++;
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;

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

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

int main(){
  int i,n,num[1000001];
  while(1){
  cin >> n;
  if(n==0)break;
  for(i = 0; i < 1000001; i++){
    num[i]=0;
  }
  
  for(i = 0;i < n; i++){
    cin >> num[i];
  }
  
  int cnt=0;

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

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll a[111];
int n;

int main(){
	while (cin >> n&&n){
		REP(i, 100)a[i] = 0;
		int co = 0;
		REP(i,n){
			cin >> a[i];
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < i; j++){
				if (a[j]>a[i]){
					swap(a[j], a[i]);
					co++;
				}
			}
		}
		//cout << "!";
		cout<< co << endl;

	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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

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

constexpr int kaijyou(const int &n) {
  return n == 0 ? 1 : n * factorial(n - 1);
}

int main() {
  int n, t;
  int ans;
  double count;
  while (cin >> n) {
    if (n == 0) return 0;
    int a[n];
    t     = 0;
    ans   = 0;
    count = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int j = 0; t == 0; j++) {
      if (j + 1 == n) {
        j = 0;
        count += 1;
      }
      if (a[j] > a[j + 1]) {
        swap(a[j], a[j + 1]);
        ans += 1;
      }
      if (count > kaijyou(n)) {
        cout << ans << endl;
        t = 1;
      }
    }
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
	int num[100];
	int i,j,k;
	int ch;
	int cnt = 0;
	int n;


while(scanf("%d",&n),n){
	for(i = 0; i < n; i++)
			scanf("%d",&num[i]);
	
	for(j = 0; j < n-1; j++){
		for(k = 0; k < n-1-j; k++){
			if(num[k] > num[k+1]){
				ch = num[k];
				num[k] = num[k+1];
				num[k+1] = ch;
				cnt++;
			}
		}
	}
	
		printf("%d\n",cnt);
		cnt = 0;
	}

	return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<int> a;
		int temp,count = 0;

		rep(i,n)
		{
			cin >> temp;
			a.push_back(temp);
		}

		rep(i,n-1)
		{
			for(int j=n-1;j>i;j--)
			{
				if(a[j] < a[j-1])
				{
					count++;
					swap(a[j],a[j-1]);
				}
			}
		}

		cout << count << endl;
	}
	return 0;
}

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;
    rep(i,n){
      REP(j,i,n){
        if(v[i] > v[j]){
          swap(v[i],v[j]);
          ++ans;
        }
      }
    }
//     rep(i,n){
//       cout << v[i] << " ";
//     }
//     cout << endl;
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int bubble_sort(int date[], int n){
	int count = 0;
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(date[j]<date[j-1]){
				int tmp = date[j];
				date[j] = date[j-1];
				date[j-1] = tmp;
				count++;
			}
		}
	}
	return(count);
}
			

int main(void)
{
	int n;
	int date[100];
	while(cin>>n){
		if(!n) break;
		for(int i = 0; i < n; i++){
			cin >> date[i];
		}
		cout << bubble_sort(date,n) << endl;
	}
	return 0;
}