Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"sort"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw int
}
type lessFunc func(p1, p2 *Team) bool
type multiSorter struct {
	teams []Team
	less    []lessFunc
}
func (ms *multiSorter) Sort(teams []Team) {
	ms.teams = teams
	sort.Sort(ms)
}
func OrderedBy(less ...lessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}
func (ms *multiSorter) Len() int {
	return len(ms.teams)
}
func (ms *multiSorter) Swap(i, j int) {
	ms.teams[i], ms.teams[j] = ms.teams[j], ms.teams[i]
}
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.teams[i], &ms.teams[j]
	var k int
	for k = 0; k < len(ms.less)-1; k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	win := func(c1, c2 *Team) bool {
		return c1.Win > c2.Win
	}
	lose := func(c1, c2 *Team) bool {
		return c1.Lose < c2.Lose
	}

	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		teams := make([]Team, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			name := buf[0]
			tmp := make([]int, n-1)
			for i := range tmp {
				tmp[i], _ = strconv.Atoi(buf[i+1])
			}
			cntwin, cntlose, cntdraw := 0, 0, 0
			for _, v := range tmp {
				switch v {
				case 1:
					cntlose++
				case 0:
					cntwin++
				case 2:
					cntdraw++
				}
			}
			teams[i] = Team{name, cntwin, cntlose, cntdraw}
		}
		OrderedBy(win, lose).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <sstream>
#include<vector>
using namespace std;


int main(void){
	multimap<int,char,greater<int> > team;
	char t;
	int n;

	while(1)
	{
		cin>>n;
		if(!n) break;
		
		for(int j=0; j<n; j++)
		{
			cin>>t;
			int point=0,r;
			
			for(int i=0; i<n-1; i++)
			{
				cin>>r;
				if(r==0) point+=2;
				else if(r==2) point++;
			}
			team.insert( make_pair( point,t) );
		}

		for(multimap<int,char,greater<int> >::iterator it=team.begin(); it != team.end(); ++it)
			cout<<(*it).second<<endl;
		team.clear();
	}
	return 0;
}

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

struct team {
    char name;
    int win, lose;
};

void mysort(team t[], int n) {
    for (int i = 0; i < n; i++) {
        for (int j = i; j > 0; j--) {
            if (t[j - 1].win < t[j].win || t[j - 1].win == t[j].win 
                && t[j - 1].lose > t[j].lose) {
                team temp = t[j - 1];
                t[j - 1] = t[j];
                t[j] = temp;
            }
        }
    }
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;
        
        team t[n];
        for (int i = 0; i < n; i++) {
            t[i].win = 0;
            t[i].lose = 0;
        }

        for (int i = 0; i < n; i++) {
            cin >> t[i].name;
            for (int j = 0; j < n - 1; j++) {
                int r;
                cin >> r;
                if (r == 0) t[i].win++;
                else if (r == 1) t[i].lose++;
            }
        }
        mysort(t, n);
        for (int i = 0; i < n; i++) {
            cout << t[i].name << endl;
        }
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n, a, d[10], e[10]; char c[10];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> c[i] >> a;
			if (a == 0) d[i]++;
			if (a == 1) e[i]++;
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (d[i] < d[j]) {
					swap(c[i], c[j]);
					swap(d[i], d[j]);
					swap(e[i], e[j]);
				}
				else if (d[i] == d[j] && e[i] > e[j]) {
					swap(c[i], c[j]);
					swap(d[i], d[j]);
					swap(e[i], e[j]);
				}
			}
		}
		for (int i = 0; i < n; i++) printf("%c\n", c[i]);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,k[10],m[10],r,i,j,temp,zyu[10];
	char t[11],te;
	while(1){
		for(i=0;i<10;i++){
			k[i]=0;
			m[i]=0;
		}
		scanf("%d",&n);
		if(n<2)break;
		for(i=0;i<n;i++){
			zyu[i]=i;
			scanf(" %c",&t[i]);
//			printf("%c\n",t[i]);
			for(j=0;j<n-1;j++){
				scanf("%d",&r);
				if(r==0){
					k[i]++;
				}
				if(r==1){
					m[i]++;
				}
//				printf("%d %d\n",r,k[i]);
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(k[i]<k[j]||(k[i]==k[j]&&m[i]>m[j] )|| (k[i]==k[j] && m[i]==m[j] && zyu[i]>zyu[j])){
					temp=k[i];
					k[i]=k[j];
					k[j]=temp;
					
					temp=m[i];
					m[i]=m[j];
					m[j]=temp;
					
					temp=zyu[i];
					zyu[i]=zyu[j];
					zyu[j]=temp;				

					te=t[i];
					t[i]=t[j];
					t[j]=te;
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%c\n",t[i]);
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	
	int n;
	char t;
	int r;
	char x[10];

	while(true){
		cin >> n;
		if(n==0)
			break;
		int win[10],lose[10];
		for(int i=0 ;i<10 ;i++){
				win[i] = 0;
				lose[i] = 0;
		}
		for(int i=0 ;i<n ;i++){
			cin >> t;

			for(int j=1 ;j<n ;j++){
				cin >> r;
				if(r==0){
					win[i]++;
				}
			   if(r==1){
					lose[i]++;
				}

			}
			x[i] = t;
		}
		char y=0,z=0;
		for(int i=0 ;i<n-1 ;i++){
				for(int j=i+1 ;j<n ;j++){
				if(win[i] < win[j]){
					z=win[i];
					win[i]=win[j];
					win[j]=z;
					y=x[i];
					x[i]=x[j];
					x[j]=y;
				}
				else if(win[i] == win[j]){
					if(lose[i] > lose[j]){
						z=win[i];
						win[i]=win[j];
						win[j]=z;
						y=x[i];
						x[i]=x[j];
						x[j]=y;
					}
				}					
			}
		}

		for(int i=0 ;i<n ;i++){
			cout << x[i] << endl;
		}
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        vi v(7,0);
        rep(i,n){
            int gotiusa_is_a_god_especially_tiya;
            cin>>gotiusa_is_a_god_especially_tiya;
            if(gotiusa_is_a_god_especially_tiya>=60)gotiusa_is_a_god_especially_tiya=60;
            v[gotiusa_is_a_god_especially_tiya/10]++;
        }
        rep(i,7)cout<<v[i]<<endl;
    }
}