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

int main(){
	int n;
	while(scanf("%d", &n), n){
		vector<int> v(n);
		for(int i = 0; i < n; ++i){
			scanf("%d", &v[i]);
		}

		int ans = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < i; ++j){
				if(v[j] > v[i]){
					++ans;
				}
			}
		}
		printf("%d\n", ans);
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
	int n, sort[100], hoge, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> sort[i];
	}
	for (int i = 0; i < n - 2;i++){
		for (int j = 0; j < n - 1 - i;j++){
			if (sort[j] > sort[j + 1]){
				hoge = sort[j];
				sort[j] = sort[j + 1];
				sort[j + 1] = hoge;
				cnt++;
			}
		}
	}
	cout << cnt << "\n";
	return 0;
}

C++: #include<stdio.h>
 
int main(){
	int a, b[100], i, 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++){
			if(b[i + 1] < b[i]){
					c = b[i];
					b[i] = b[i + 1];
					b[i + 1] = c;
					count++;
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int calc(vector<int>&a){
    int n=a.size();
    if(n<=1)return 0;
    vector<int>b(a.begin(),a.begin()+n/2);
    vector<int>c(a.begin()+n/2,a.end());
    int ret=calc(b)+calc(c);

    int bi=0,ci=0;
    for(int i=0;i<a.size();i++){
        if(bi<b.size()&&(ci==c.size()||b[bi]<=c[ci])){
            a[i]=b[bi++];
        }
        else{
            ret+=n/2-bi;
            a[i]=c[ci++];
        }
    }
    return ret;
}

int main(){
    int N;
    while(cin>>N,N){
        vector<int>a(N);
        for(int i=0;i<N;i++)cin>>a[i];
        cout<<calc(a)<<endl;
    }
    return 0;
}

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 =0;i < n;i++){
		int pos =0;
		while(a[pos]>a[pos+1]&&pos<(n-i-1)){
			swap(a[pos],a[pos+1]);
			pos++;
			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++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


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

	return 0;
}

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


using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)

int BIT[1000001];

int sum(int idx)
{
	int ret = 0;
	while (idx > 0)
	{
		ret += BIT[idx];
		idx -= idx & -idx;
	}
	return ret;
}

const int N = 1000000;
void add(int idx, int num)
{
	while (idx <= N)
	{
		BIT[idx] += num;
		idx += idx & -idx;
	}
}

signed main()
{
	int n;
	while (cin >> n && n)
	{
		memset(BIT, 0, sizeof(BIT));
		int ans = 0;
		vector<int> arr(n);
		rep(i, n) cin >> arr[i];
		rep(i, n)
		{
			ans += sum(arr[n - i - 1]);
			add(arr[n - i - 1], 1);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int arr[100];
		for (int i = 0; i < n; ++i)
			scanf("%d", arr+i);

		int ans = 0;
		for (int i = n-1; i > 0; --i)
		{
			for (int j = 0; j < i; ++j)
			{
				if (arr[j] > arr[j+1])
				{
					swap(arr[j], arr[j+1]);
					++ans;
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

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

int main()
{
  int a[100];
  int n;

  while (cin >> n && n != 0){
    for (int i = 0; i < n; i++){
      cin >> a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n - 1; j++){
        if (a[j] >= a[j + 1]){
          cnt++;
          int c = a[j];
          a[j] = a[j + 1];
          a[j + 1] = c;
        }
      }
    }
    cout << cnt << endl;
  }
}

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

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

    vector<int> a(n);
    for (int i = 0; i < n; ++i)
      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]) {
	  ++ans;
	  swap(a[j], a[j+1]);
	}
      }
    }

    cout << ans << endl;
  }
  return 0;
}