Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw, Index 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
	}
	index := func(c1, c2 *Team) bool {
		return c1.Index < c2.Index
	}

	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, i}
		}
		OrderedBy(win, lose, index).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

typedef pair<int, int> pp;
typedef pair<pp, char> ppp;

const int W = 0, T = 1, L = 1, MAXN = 11;


int main()
{
    int n;
    while(cin >> n && n)
    {

        vector<ppp> ans;
            int w[MAXN] = {}, l[MAXN] = {};
            bool used[MAXN] = {};
            char t[MAXN];

        REP(n)
        {
            int r;//, w = 0, l = 0;
            cin >> t[i];
            rep(j,n - 1)
            {
                cin >> r;
                if(r == W)w[i]++;
                if(r == L)l[i]++;
            }
        }
        rep(j,n)
        {
            int maxw = 0, minl = n, f = n;
            REP(n)
               if(!used[i] &&( (maxw < w[i] ) || (maxw == w[i] && minl > l[i]))){ f = i; maxw = w[i]; minl = l[i];}
            used[f] = true;
            cout << t[f] << endl;
        }
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[11],f[11],g,h,i,j;
	char z[11][11],x[11];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
		d[i]=0;
		f[i]=0;
			scanf("%s",z[i]);
			for(j=0;j<a-1;j++){
				scanf("%d",&s);
				if(s==0) d[i]++;
				if(s==1) f[i]++;
			}
		}
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(d[i]<d[j]){
					g=d[i];
					d[i]=d[j];
					d[j]=g;
					h=f[i];
					f[i]=f[j];
					f[j]=h;
					strcpy(x,z[i]);
					strcpy(z[i],z[j]);
					strcpy(z[j],x);
				}
				else if(d[i]==d[j]){
					if(f[i]>f[j]){
						g=d[i];
						d[i]=d[j];
						d[j]=g;
						h=f[i];
						f[i]=f[j];
						f[j]=h;
						strcpy(x,z[i]);
						strcpy(z[i],z[j]);
						strcpy(z[j],x);
					}
				}
			}
		}
		for(i=0;i<a;i++) printf("%s\n",z[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<functional>
#define MAX 11
using namespace std;
class Team{
public:
  char name;
  int wins;
  int loses;
  int id;
  Team():id(0),wins(0),loses(0){}
  bool operator>(const Team &t)const{
    if( wins == t.wins ){
      if( loses == t.loses ){
	return id < t.id;
      }else return loses < t.loses;
    }else return wins > t.wins;
  }
};
int main()
{
  while(true){
    int n;
    cin >> n;
    if( n == 0 ) break;
    Team teams[n];
    for(int i = 0; i < n; ++i){
      teams[i].id = i;
      char name;
      cin >> name;
      teams[i].name=name;
      for(int j = 0; j < n-1; ++j){
	int r;cin>>r;
	if(r==0)teams[i].wins++;
	if(r==1)teams[i].loses++;
      }
    }
    sort(teams,teams+n,greater<Team>());
    for(int i = 0; i < n; ++i){
      cout << teams[i].name << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(void){
	int a,b,n;
	char t[10];
	int w[10],l[10];
	while(1){
		memset(w,0,sizeof(w));
		memset(l,0,sizeof(l));
		cin >> n;
		for(a=0;a<n;a++){
			cin >> t[a];
			for(b=0;b<n-1;b++){
				int b;
				cin >> b;
				if(b==0)w[a]++;
				if(b==1)l[a]++;
			}
		}
		for(a=0;a<n-1;a++){
			for(b=a+1;b<n;b++){
				if(w[b]>w[a] || w[b]==w[a] && l[b]<l[a])swap(t[a],t[b]),swap(w[a],w[b]),swap(l[a],l[b]);
			}
		}
		for(a=0;a<n;a++){
			cout << t[a] << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,sum[11];
	int data;
	char name[11][11];
	while(1) {
		cin>>n;
		if(!n) break;
		for(i=0;i<n;i++) sum[i]=0;
		for(i=0;i<n;i++) {
			cin>>name[i];
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) sum[i]+=100;
				else if(data==1) sum[i]--;
			}
		}
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				if(sum[i]<sum[j]) {
					swap(sum[i],sum[j]);
					swap(name[i],name[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<name[i]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

using T = tuple<int, int, int, char>;
int main() {
    init();

    int n;
    while (1) {
        cin >> n;
        if (n == 0)break;
        vector<T> team(n);
        FOR(i, 0, n) {
            char t; int w = 0, l = 0, r;
            cin >> t;
            FOR(j, 0, n - 1) {
                cin >> r;
                if (r == 0)w--;
                else if (r == 1)l++;
            }
            team[i] = make_tuple(w, l, i, t);
        }
        SORT(team);
        FOR(i, 0, n)cout << get<3>(team[i]) << "\n";
    }
}

C++: #include<stdio.h>
int main(void)
{
    int n,i,j,a[10][9],b[10],w;
	char name[10],x;
	while(1){
	    scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
		    scanf(" %c",&name[i]);
			for(j=0;j<n-1;j++){
			    scanf(" %d",&a[i][j]);
			}
		}
		for(i=0;i<n;i++) b[i]=0;
		for(i=0;i<n;i++){
		    for(j=0;j<n-1;j++){
			    if(a[i][j]==0) b[i]=b[i]+2;
				else if(a[i][j]==2) b[i]=b[i]+1;
			}
		}	
		for(i=0;i<n-1;i++){
		    for(j=i+1;j<n;j++){
			    if(b[i]<b[j]){
				    w=b[i];
					b[i]=b[j];
					b[j]=w;
					x=name[i];
					name[i]=name[j];
					name[j]=x;
				}
			}
		}
		for(i=0;i<n;i++) printf("%c\n",name[i]);
	}
	return 0;
}