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 <cassert>
//PXjUXeZStdX
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
// #include <boost/foreach.hpp>
// #include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
//#define INF 1e9
#define LINF (1LL<<40)
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};
typedef pair<int,int> P;

const long long MOD=1000000007LL;
bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)||islower(c));}

template<typename T> 
void print(vector<T> v){
    for(int i=0;i<v.size();i++){
        if(i)cout<<" ";
        cout<<v[i];
    }
    cout<<endl;
}
int INF=1e18;

template<typename T>
void printendl(vector<T> v){
    for(auto date:v)cout<<date<<endl;
}

template<typename T>
void printvv(vector<vector<T>> v){
    for(int i=0;i<v.size();i++){
        for(int j=0;j<v[i].size();j++){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}

int powl(int n,int p){
    int ret=1;
    for(int i=0;i<p;i++)ret*=n;
    return ret;
}

struct Edge{
    int to,cost;
};

struct S{
    int score[3];
    char team;
};
signed main (){
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<S> v(n);
        rep(i,0,n){
            char c;
            cin>>c;
            v[i].team=c;
            rep(j,0,n-1){
                int x; cin>>x;
                v[i].score[x]++;
            }
        }

        sort(all(v),[&](S a,S b){
            if(a.score[0]==b.score[0])return a.score[1]<b.score[1];
            else return a.score[0]>b.score[0];
        });

        rep(i,0,n)cout<<v[i].team<<endl;
    }


    

    

    


}

/*

*/

C++: #include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,char> P;
int main(void)
{
	int n,i,j,x;
	P pp[10];
	int kati[10],make[10],zyun[10];
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	{
			scanf(" %c",&pp[i].second);
			zyun[i]=n-i;
			kati[i]=0;
			make[i]=0;
			for(j=0;j<n-1;j++)	{
				scanf("%d",&x);
				if(x==0)	kati[i]++;
				if(x==1)	make[i]++;
			}
			pp[i].first=kati[i]*10000+(1000-make[i])*100+zyun[i];
		}
		sort(pp,pp+n,greater<P>() );
		for(i=0;i<n;i++)	{
			printf("%c\n",pp[i].second);
		}
	}
	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int a,n,k[10],m[10];
  char c[10];
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(k,0,sizeof(k));
    memset(m,0,sizeof(m));
    for(i=0;i<n;i++){
      cin>>c[i];
      for(j=0;j<n-1;j++){
	cin>>a;
	if(a==0)
	  k[i]++;
	else if(a==1)
	  m[i]++;
      }
    }
    do{
      h=0;
      for(i=1;i<n;i++){
	if(k[i-1]<k[i]){
	  swap(k[i-1],k[i]);
	  swap(m[i-1],m[i]);
	  swap(c[i-1],c[i]);
	  h=1;
	}else if(k[i-1]==k[i]){
	  if(m[i-1]>m[i]){
	    swap(k[i-1],k[i]);
	    swap(m[i-1],m[i]);
	    swap(c[i-1],c[i]);
	    h=1;
	  }
	}
      }
    }while(h);
    for(i=0;i<n;i++)
      cout<<c[i]<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long int i,j,k,n,a,b,sum;
	while(1) {
		cin>>n;
		vector<pair<long long int,char> > pp(n);
		
		if(n==0) break;
		for(i=0;i<n;i++) {
			cin>>pp[i].second;
			sum=0;
			for(j=0;j<n-1;j++) {
				cin>>a;
				if(a==0) sum+=10000000;
				if(a==1) sum-=1;
			}
			pp[i].first=sum;
		}
		stable_sort(pp.begin(),pp.end());
		stable_sort(pp.begin(),pp.end());
		for(i=n-1;i>=0;i--) {
			cout<<pp[i].second<<endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long int i,j,k,n,a,b,sum;
	int data;
	while(1) {
		cin>>n;
		vector<pair<int,char> > pp(n);
		
		if(n==0) break;
		for(i=0;i<n;i++) {
			cin>>pp[i].second;
			sum=0;
			for(j=0;j<n-1;j++) {
				cin>>a;
				if(a==0) sum+=10000000;
				if(a==1) sum-=1;
			}
			pp[i].first=sum;
		}
		sort(pp.begin(),pp.end());
		for(i=n-1;i>=0;i--) {
			cout<<pp[i].second<<endl;
		}
	}
	return 0;
}