Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Country struct {
	Name  string
	Score int
}

func (c Country) String() string {
	return fmt.Sprintf("%s,%d", c.Name, c.Score)
}

type ByScore []Country

func (a ByScore) Len() int           { return len(a) }
func (a ByScore) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByScore) Less(i, j int) bool { return a[i].Score > a[j].Score }

func main() {
	// countries := []Country{
	// 	{"japan", 3},
	// 	{"america", 4},
	// 	{"canada", 2},
	// }
	// sort.Sort(ByScore(countries))
	// fmt.Println(countries)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		countries := make([]Country, n)
		for i := range countries {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmp := new(Country)
			tmp.Name = input[0]
			var x int
			for j := 1; j < 4; j++ {
				switch j {
				case 1:
					x, _ = strconv.Atoi(input[j])
				case 2:
					x = 0
				case 3:
					x, _ = strconv.Atoi(input[j])
					x *= 3
				}
				tmp.Score += x
			}
			countries[i] = *tmp
		}
		sort.Sort(ByScore(countries))
		for _, v := range countries {
			fmt.Println(v)
		}
		fmt.Println()
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

struct Data{
	string name;
	int w, l, d,sum,id;
};

int main()
{
	int n,cnt=0;
	
	while (cin >> n, n) {
		if (cnt++)cout << endl;
		vector<Data> s(n);
		for (int i = 0; i < n; i++) {
			s[i].id = i;
			cin >> s[i].name >> s[i].w >> s[i].l >> s[i].d;
			s[i].sum = s[i].w * 3 + s[i].d;
		}

		for (int i = 0; i < n-1; i++) 
			for (int j = i+1; j < n; j++) 
				if (s[i].sum < s[j].sum)swap(s[i], s[j]);
		
		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (i == j)continue;
				if (s[i].sum == s[j].sum) {
					if (s[i].id > s[j].id)swap(s[i], s[j]);
				}
			}
		}

		for (int i = 0; i < n; i++)
			cout << s[i].name << ','<< s[i].sum << endl;
	}
	return 0;
}

C++: //Name: League Match Score Sheet
//Level: 1
//Category: やるだけ
//Note: 

/**
 * 入力時に勝ち点を計算し、ソートする。
 *
 * オーダーは O(N log N)。
 */
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;
    if(!first) cout << endl;

    vector<pair<int,string>> vs;
    for(int i = 0; i < N; ++i) {
        string t;
        int w, l, e;
        cin >> t >> w >> l >> e;
        vs.emplace_back(w*3 + e, t);
    }
    stable_sort(begin(vs), end(vs), greater<pair<int,string>>());
    for (const auto &t : vs) {
        cout << t.second << "," << t.first << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) first = false;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


int main(){
	int n;
	int a,b,c;
	string s;
	bool f=false;
	while(cin>>n){
		vector<pair<pii,string> >v(n);
		rep(i,n){
			cin>>s>>a>>b>>c;
			v[i].fi.fi=a*3+c;
			v[i].fi.se=i*(-1);
			v[i].se=s;
		}
		sort(all(v));
		reverse(all(v));
		if(f)cout<<endl;
		f=true;
		rep(i,n){
			cout<<v[i].se<<","<<v[i].fi.fi<<endl;
		}
	}
}

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

using namespace std;

int main(void){
	string	team;
	int	w,d,l;

	for(int n;cin >> n,n;){
		pair<string,int> *val,tmp;

		val = new pair<string,int>[n];

		for(int i=0;i<n;i++){
			cin >> team >> w >> l >> d;
			val[i]=make_pair(team,w*3+d);
		}

		for(int i=0;i<n-1;i++)
			for(int j=0;j<n-i-1;j++)
				if(val[j].second<val[j+1].second){
					tmp=val[j];
					val[j]=val[j+1];
					val[j+1]=tmp;
				}

		for(int i=0;i<n;i++)
			cout << val[i].first << "," << val[i].second << endl;
		cout << endl;
		delete [] val;
	}
	return 0;
}

C++: #include <cstdio>
#include <utility>
#include <string>
#include <iostream>

using namespace std;

struct team{
    string s;
    int input, point;
};

int main()
{
    bool first = 1;
    while( 1 )
    {
        int n;
        if( !first )
        {
            printf( "\n" );
        }
        else
        {
            first = 0;
        }
        scanf( "%d", &n );
        if( n == 0 ) break;
        team p[10];
        int i = 0;
        while( i < n )
        {
            string s;
            cin >> s;
            int w,l,d;
            cin >> w >> l >> d;
            p[i].s = s;
            p[i].point = 3 * w + d;
            p[i].input = i;
            i++;
        }
        for( int j = 0; j < n; j++ )
        {
            for( int k = j; k < n; k++ )
            {
                if( p[j].point < p[k].point )
                {
                    swap( p[j], p[k] );
                }
            }
        }
        for( int j = 0; j < n; j++ )
        {
            for( int k = j; k < n; k++ )
            {
                if( p[j].point == p[k].point && p[j].input > p[k].input )
                {
                    swap( p[j], p[k] );
                }
            }
        }
        for( int j = 0; j < n; j++ )
        {
            cout << p[j].s << ',' << p[j].point << '\n';
        }
    }   
    return 0; 
}

C++: #include <iostream>
#include <string.h>
using namespace std;
 
struct data{
 
    char name[20];
    int win;
    int lose;
    int draw;
    int score;
 
};
 
int main(){
 
    int teamamo;
 
    while (true){
 
        cin >> teamamo;
 
        if (teamamo == 0)
            break;
 
        data teamdata[10];
         
 
        for (int i = 0; i<teamamo; i++)
            cin >> teamdata[i].name >> teamdata[i].win >> teamdata[i].lose >> teamdata[i].draw;
 
        for (int i = 0; i<teamamo; i++)
            teamdata[i].score = teamdata[i].win * 3 + teamdata[i].draw;
 
 
        for (int j = 0; j < teamamo - 1; j++){
            for (int i = 0; i < teamamo - 1; i++){
 
                if (teamdata[i].score < teamdata[i + 1].score){
 
                    char fout[20];
                    strcpy(fout, teamdata[i].name);
                    strcpy(teamdata[i].name, teamdata[i + 1].name);
                    strcpy(teamdata[i + 1].name, fout);
 
                    int gout;
                    gout = teamdata[i].score;
                    teamdata[i].score = teamdata[i + 1].score;
                    teamdata[i + 1].score = gout;
 
                }
 
            }
 
 
        }
 
        for (int i = 0; i<teamamo; i++)
            cout << teamdata[i].name << ',' << teamdata[i].score << endl;
 
 
    }
 
    return 0;
 
}