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, 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++;
			}
		}
	}
	for (int i = 0; i < n; i++){
		cout << sort[i] << " ";
	}
	cout << "\n";
	cout << cnt << "\n";
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<time.h>
using namespace std;
#define N 314159
int a[N],t[N];
long long ans=0;
void marge_count(int s,int g){
  if(s+1==g)return;
  int m= (s+g)/2;
  marge_count(s,m);
  marge_count(m,g);
  int p=s,q=m,r=s;
  while(p<m&&q<g){
    if(a[p]<=a[q]){
      t[r++]=a[p++];
    }else{
      t[r++]=a[q++];
      ans+=m-p;
    }
  }
  if(p<m){
    while(p<m)t[r++]=a[p++];
  }else{
    while(q<g){
      t[r++]=a[q++];
    }
  }
  for(int i=s;i<g;i++){
    a[i]=t[i];
  }
}
int n;
int main(){
    while(cin>>n&&n){ans=0;
  for(int i=0;i<n;i++)cin>>a[i];
  marge_count(0,n);
   cout<<ans<<endl;}
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int num;
	int n[100]={0};
	while(cin >> num){
		if(num==0)break;
		for(int i=0;i<num;++i){
			cin >> n[i];
		}
		int count=0;
		for(int i=0;i<num;++i){
			for(int j=i+1;j<num;++j){
				if(n[i]>n[j]){
					int tmp = n[i];
					n[i]=n[j];
					n[j]=tmp;
					++count;
				}
			}
		}
		cout << count << "\n";
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int n, cnt;
int a[100000];

void _swap(int p, int q, int v, int w) {
	int c, d;
	c = p;
	d = q;
	p = d;
	q = c;
	a[v] = p;
	a[w] = q;
}

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

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

int N;

int c=0;
while(1){
scanf("%d",&N);
if(N==0)break;
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<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int data[114];
		for(int i=0;i<n;i++)cin>>data[i];
		int ans=0;
		while(1){
			int flg=1;
			for(int i=0;i<n-1;i++){
				if(data[i]>data[i+1])flg=0;
				}
			if(flg)break;
			
			for(int i=0;i<n-1;i++){
				if(data[i]>data[i+1]){
					swap(data[i],data[i+1]);
					ans++;
					}
				}	
			}
			cout<<ans<<endl;
		}
		return 0;
	}

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

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

		int ans = 0;
		for( int i = 0; i < n - 1; ++i ){
			for( int j = 0; j < n - 1 - i; ++j ){
				if( a[ j ] > a[ j + 1 ] ){
					int t = a[ j + 1 ];
					a[ j + 1 ] = a[ j ];
					a[ j ] = t;
					++ans;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int n;
int v[10000];

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

		int step = 0;

		for(int i=n; i>0; --i){
			for(int j=0; j<i-1; ++j){
				
				if(v[j] > v[j+1]){
					swap(v[j], v[j+1]);
					step++;
				}
			}
		}

		cout << step << endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;
int main(){
	int n,table[100],count;
	while(true){
		scanf("%d",&n);
		if(n == 0)break;
		for(int i=0; i < n; i++){
			scanf("%d",&table[i]);
		}
		count = 0;
		for(int i=n-2; i >= 0; i--){
			for(int k=0; k <= i; k++){
				if(table[k] > table[k+1]){
					swap(table[k],table[k+1]);
					count++;
				}
			}
		}
		printf("%d\n",count);
	}
}

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

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

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

using namespace std;

int main() {
	int n;
	while ( cin >> n, n ) {
		vector<int> v(n);
		for (int i = 0; i < n; ++i) {
			cin >> 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;
			}
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#define MAX 100
using namespace std;

int bubbleCount(int* array, int n);

int main(){
	int n;
	while(scanf("%d", &n)){
		if(n == 0) break;
		int array[MAX];
		fill(array, array + MAX, 0);
		for(int i = 0; i < n; i++) scanf("%d", &array[i]);
		
		printf("%d\n", bubbleCount(array, n));
	}
	return 0;
}

int bubbleCount(int* array, int n){
	bool flag = true;
    int temp, count = 0;
    while(flag){
        flag = false;
        for(int i = n - 1; i > 0; i--)
        	if(array[i] < array[i - 1]){
            	temp = array[i];
            	array[i] = array[i - 1];
            	array[i - 1] = temp;
            	flag = true;
            	count++;
        	}
    	}
    return count;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    int count=0;
    std::deque<int> deq;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            for (int j=0;j<n;j++) {
                for (int k=0;k<n-1;k++) {
                    if (deq[k]>deq[k+1]) {
                        swap(deq[k],deq[k+1]);
                        count++;
                    }
                }
            }
            cout<<count<<endl;
            count=0;
            deq.clear();
        }
    }
}

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

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


#define N (111)
int seg[N+1];

void add(int x,int v){
	for(int i = x ; i < N ; i+=i&-i){
		seg[i] += v;
	}
}

int get(int x){
	int ans = 0;
	for(int i = x ; i > 0 ; i -= i & -i){
		ans += seg[i];
	}
	return ans;
}

int a[101];

int main(){
	int n;
	while(cin >> n && n){
		vector<int> u;
		for(int i = 0 ; i < 101 ; i++) seg[i] = 0;
		
		for(int i = 0 ; i < n ; i++) cin >> a[i] , u.push_back(a[i]);
		sort(u.begin(),u.end());
		u.erase(unique(u.begin(),u.end()),u.end());
		for(int i = 0 ; i < n ; i++)
			a[i] = lower_bound(u.begin(),u.end(),a[i]) - u.begin() + 1;
		int ans = 0;
		for(int i = 0 ; i < n ; i++){
			add(a[i],1);
			ans += (i+1) - get(a[i]);  //a[i]より大きな値
		}
		cout << ans << "<" << endl;
	}
}