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<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pair<int,string> > country(20);
int n;

void mysort(){
	int i,j;
	for(i=0;i<n;i++){
		for(j=0;j<n-1;j++){
			if(country[j].first<country[j+1].first){
				pair<int,string> buf;
				buf=country[j];
				country[j]=country[j+1];
				country[j+1]=buf;
			}
		}
	}
}

int main() {
	bool f=true;
	while(n=in()){
		if(!f){cout<<endl;}f=false;
		int i;
		int win,lose,draw;
		string str;
		for(i=0;i<n;i++){
			cin>>str>>win>>lose>>draw;
			country[i]=mp(win*3+draw,str);
		}
		mysort();
		for(i=0;i<n;i++){
			cout<<country[i].second<<","<<country[i].first<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>

using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

int main(void){
	while(1){
		int a,n;
		string s;
		vector< pair<int,string> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.push_back(make_pair(w*3+d,s));
		}
		cout << endl;
		stable_sort(P.begin(),P.end(),cmp);
		for(a=0;a<n;a++){
			cout << P[a].second << "," << P[a].first << endl; 
		}
		cout << endl;
	}
	return 0;
}

C++: /*
	2013 08 01
	Miyagi Technical High School
	J1 JK club Taiki F Watanabe
*/

#include<stdio.h>

typedef struct INFO_TEAM
{
	// チーム名
	char name[21];
	
	// 勝の数
	int win;
	// 負の数
	int lose;
	// 引分の数
	int draw;
	// 成績
	int points;
}INFO;

int main(void)
{
	int i = 0, j = 0, num = 0;
	INFO tmp;
	INFO team[10];
	
	while(1)
	{

		scanf("%d", &num);

		if(num == 0)
		{
			break;
		}

		for(i = 0; i < num; i++)
		{
			scanf("%s %d %d %d", &team[i].name, &team[i].win, &team[i].lose, &team[i].draw);

			team[i].points = 0;

			team[i].points += team[i].win * 3;
			team[i].points += team[i].draw;
		}

		for(i = 0; i < num; i++)
		{
			for(j = 0; j < num; j++)
			{
				if(team[i].points > team[j].points)
				{
					tmp = team[i];
					team[i] = team[j];
					team[j] = tmp;
				}
			}
		}

		for(i = 0; i < num; i++)
		{
			printf("%s,%d\n", team[i].name, team[i].points);
		}

		putchar('\n');
	}

	return 0;
}

C++: #include <bits/stdc++.h>

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

struct Team {
    int point;
    string name;
    Team(string name, int win, int lose, int draw) : name(name), point(win * 3 + draw) {}
    bool operator<(const Team& t){
        return point < t.point;
    }
};
bool operator<(const Team& a, const Team& b){
    return a.point < b.point;
}
bool operator>(const Team& a, const Team& b){
    return a.point > b.point;
}

int main()
{
    int n;
    bool space = false;
    while (n = in()){
        if (!space){
            space = true;
        }
        else puts("");

        vector<Team> ts;
        rep(i, n){
            string name;
            int win, lose, draw;
            cin >> name >> win >> lose >> draw;
            ts.push_back(Team(name, win, lose, draw));
        }
        stable_sort(ts.begin(), ts.end(), greater<Team>());
        rep(i, n){
            printf("%s,%d\n", ts[i].name.c_str(), ts[i].point);
        }
    }
    return (0);
}

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

typedef pair<int,string> P;

bool compare(P a,P b){
    return a.first > b.first;
}

int main(){
    int n,a,b,c;
    string str;
    
    while(cin >> n,n){
        vector<P> v;
        for(int i = 0 ; i < n ; i++){
            cin >> str >> a >> b >> c;
            int p = a*3+c;
            v.push_back(P(p,str));
        }
        stable_sort(v.begin(),v.end(),compare);
        
        for(int i = 0 ; i < n ; i++){
            cout << v[i].second << "," << v[i].first << endl;
        }
        puts("");
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>

using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

int main(void){
	bool b=false;
	while(1){
		int a,n;
		string s;
		multimap< int, string, greater<int> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert(make_pair(w*3+d,s));
		}
		multimap< int, string, greater<int>>::iterator it = P.begin();
		while( it != P.end() )	{
			cout << (*it).first << ":" << (*it).second << endl;
			++it;
		}
	}
	return 0;
}

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

int main()
{
	pair <string, int> score[10];
	int n, w, l, d;
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++)
		{
			cin >> score[i].first >> w >> l >> d;
			score[i].second = w * 3 + d;
			//cout << score[i].first << score[i].second << endl;
		}
		sort(score, score + n);
		reverse(score, score + n);
		for (int i = 0; i < n; i++)
		{
			cout << score[i].first << "," << score[i].second << endl << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,num=0,score[1000];
    while(1){
        num++;
        if(num!=1){
            cout<<endl;
        }
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }
    int max=-10000,count=0,j=0,s;bool bo=false;
    while(1){
        if(count==n){
            break;
        }
        for(int i=0;i<n;i++){
            if(score[i]>max){
                max=score[i];
                s=i;
            }
        }
        cout<<name[s]<<","<<score[s]<<endl;
        count++;
        score[s]=-10;
        max=-10000;
    }
    }
    return 0;
}