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

class team{
public:
  int win, lose;
  char name;
  bool operator < (const team &s)const{
    if(win==s.win){
      return lose<s.lose;
    }
    else return win>s.win;
  }
};

main(){
  int n;
  team data[10];
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      int c1=0, c2=0, tmp;
      cin >> data[i].name;
      for(int j=0;j<n-1;j++){
	cin >> tmp;
	if(tmp==0) c1++;
	else if(tmp==1) c2++;
      }
      data[i].win=c1;
      data[i].lose=c2;
    }

    stable_sort(data, data+n);

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

C++: #include <stdio.h>
const int N=11;
void swap(int &a,int &b){
    int temp=a;
    a=b;
    b=temp;
    return ;
}
int main(){
    int n,temp,w[N],l[N],f[N];
    char c[10],a[N];
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            scanf("%s",c);
            a[i]=c[0];
            f[i]=i;
            w[i]=l[i]=0;
            for(int j=1;j<n;j++){
                scanf("%d",&temp);
                if(temp==1)l[i]++;
                else if(temp==0)w[i]++;
            }
        }
        for(int i=0;i<n;i++)for(int j=1;j<n;j++)if(w[f[j]]==w[f[j-1]]?l[f[j]]<l[f[j-1]]:w[f[j]]>w[f[j-1]])swap(f[j],f[j-1]);
        
        
        for(int i=0;i<n;i++)printf("%c\n",a[f[i]]);
    }
}

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){
        vector<pii> ujimatsu(n,pii(0,0));
        vc anko(n);
        rep(i,n){
            cin>>anko[i];
            rep(j,n-1){
                int tiya; cin>>tiya;
                if(tiya==0)ujimatsu[i].first+=2;
                else if(tiya==1)ujimatsu[i].second-=1;
                else if(tiya==2)ujimatsu[i].first+=1;
            }
        }
        vector<bool>flag(1000,true);
        rep(i,n){
            int maxi=-INF;
            int ans=0;
            rep(j,n){
                if(!flag[j])continue;
                if(ujimatsu[j].first>maxi){
                    maxi=ujimatsu[j].first;
                    ans=j;
                }else if(ujimatsu[j].first==maxi){
                    if(ujimatsu[ans].second<ujimatsu[j].second){
                        ans=j;
                    }
                }
            }
            flag[ans]=false;
            cout<<anko[ans]<<endl;
        }
    }
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,ii,jj,n,rr[10][3],r,temp,flg;
	char t[11],ctm,tcopy[11];
	while(1){
		cin>>n;
		if(n==0)break;
		for(i=0;i<n;i++){
			cin>>t[i];
			tcopy[i]=t[i];
			rr[i][0]=0; rr[i][1]=0; rr[i][2]=0;
			for(j=0;j<n-1;j++){
				cin>>r;
				rr[i][r]++;
			}
		}
//		for(i=0;i<n;i++)printf("%c ??????%d?????????%d\n",t[i],rr[i][0],rr[i][1]);
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][0]<rr[j][0]){
					temp=rr[i][0];
					rr[i][0]=rr[j][0];
					rr[j][0]=temp;
					
					temp=rr[i][1];
					rr[i][1]=rr[j][1];
					rr[j][1]=temp;
					
					ctm=t[i];
					t[i]=t[j];
					t[j]=ctm;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][1]>rr[j][1]&&rr[i][0]==rr[j][0]){
					temp=rr[i][0];
					rr[i][0]=rr[j][0];
					rr[j][0]=temp;
					
					temp=rr[i][1];
					rr[i][1]=rr[j][1];
					rr[j][1]=temp;
					
					ctm=t[i];
					t[i]=t[j];
					t[j]=ctm;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][1]==rr[j][1]&&rr[i][0]==rr[j][0]){
					flg=0;
					for(k=0;k<n;k++){
						if(t[i]==tcopy[k])flg=1;
						if(t[j]==tcopy[k]&&flg==0){
							temp=rr[i][0];
							rr[i][0]=rr[j][0];
							rr[j][0]=temp;
							
							temp=rr[i][1];
							rr[i][1]=rr[j][1];
							rr[j][1]=temp;
							
							ctm=t[i];
							t[i]=t[j];
							t[j]=ctm;
							break;
						}
					}
				}
			}
		}
		for(i=0;i<n;i++) cout<<t[i]<<endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

typedef pair<P,Ps> PIS;
PIS team[10];

int main(){
	int n;
	while(cin >> n && n){
		rep(i, n){
			cin >> team[i].second.second;
			team[i].second.first = i;
			team[i].first = P(n-1, 0);
			rep(j, n - 1) {
				int num;
				cin >> num;
				if(num == 0) team[i].first.first--;
				if(num == 1) team[i].first.second++;
			}
		}
		sort(team, team + n);
		rep(i, n) cout << team[i].second.second << endl;
	}
	return 0;
}