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 <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <functional>
#include <list>


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<algorithm>
#include<map>
#include<string>
#include<utility>
#include<vector>
#include<functional>

using namespace std;



int main(void)
{
	//入力変数
	pair<int, string>h_input[10];
	//いくつ入力するか
	int n = 0;
	//入力変数
	char str_input[100] = {NULL};

	bool flag = false;

	while (cin >> n && n != 0)
	{
		if (flag == true)
		{
			cout << endl;
		}

		flag = true;

		//入力変数
		pair<int , pair<int , int> > tokuten;

		for (int i = 0; i < n; i++)
		{
			cin >> str_input;
			h_input[i].second = str_input;
			cin >> tokuten.first >> tokuten.second.first >> tokuten.second.second;
			//勝ちと負けの分だけ加算
			h_input[i].first = tokuten.first * 3 + tokuten.second.second;
		}

		stable_sort(h_input , h_input + n , greater<pair<int , string> >());

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

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

int main()
{
	vector< pair<int, string> > team;

	while (1)
	{
		int n;
		cin >> n;
		if (n == 0) { break; }

		for (int i = 0; i < n; ++i)
		{
			string t;
			int a, b, c;

			cin >> t >> a >> b >> c;

			team.push_back(make_pair(a * 3 + c, t));
		}

		sort(team.begin(), team.end());

		for (int i = team.size() - 1; i >=0; --i)
		{
			cout << team[i].second << "," << team[i].first << endl;
		}
	}

	return 0;
}

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

using namespace std;

int main(){

	int n;
	bool f=false;
	while(cin>>n&&n!=0){
		if(f)
			cout<<endl;
		f=true;
		vector<pair<int,pair<int,string> > > v;
		string team;
		int w,l,d;
		for(int i = 0; i < n; i++){
			cin>>team>>w>>l>>d;
			v.push_back(make_pair(w*3+d*1,make_pair(-i,team)));
		}
		sort(v.begin(),v.end(),greater<pair<int,pair<int,string> > >());
		for(int i = 0; i < v.size(); i++){
			cout<<v[i].second.second<<","<<v[i].first<<endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a, b, c;
vector < pair<ll,string> > v;
string s;

int main(){
	bool f = 0;
	while (cin >> n&&n){
		REP(i, n){
			cin >> s >> a >> b >> c;
			v.push_back(make_pair(a * 3 + c, s));
		}
		REP(i, v.size()-1){
			if (v[i].first < v[i+1].first){
				swap(v[i], v[i + 1]);
			}
		}
		if (f)cout << " " << endl;
		REP(i, v.size()){
			cout << v[i].second << "," << v[i].first << endl;
		}
		f = 1;
		v.clear();
	}
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (int)(count); i++)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 100000 ;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

using namespace std;

bool CMP(const pair<int,string>&x, const pair<int,string>&y){
	return x.first > y.first;
}

int main()
{
	int n;
	bool b = false;
	while(cin>>n,n){
		vector<pair<int,string> > v;
		while(n--){
			string s; int a,b,c;
			cin>>s>>a>>b>>c;
			v.push_back(make_pair(a*3+c,s));
		}

		stable_sort(v.begin(),v.end(),CMP);
		if(b) cout << endl;
		b = true;
		FOR(i,sz(v)){
			cout << v[i].second << "," << v[i].first << endl;
		}
	}

	return 0;
}

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

using namespace std ;

typedef pair< int ,string > pay ;

pay p[ 10 ] ;

int main()
{
	int n ,dr ;
	cin >> n ;
	while( n )
	{
		//pay p[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> p[ i ].second >> p[ i ].first >> dr >> dr ;
			p[ i ].first = p[ i ].first * 3 + dr ;
		}

		sort( p ,p + n ) ;

		for( int i = n - 1 ; i >= 0 ; i-- )
			cout << p[ i ].second << "," << p[ i ].first << endl ;
		if( cin >> n ,n )
			cout << endl ;
	}
	return 0 ;
}

C++: #include<stdio.h>
int main(){
	int n,i,i2,point[10],w,e,l,sum,maxn;
	char team[20][10];
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i!=n;i++){
			scanf("%s%d%d%d",team[i],&w,&e,&l);
			sum=w*3+l;
			point[i]=sum;
		}
		for(i=0;i!=n;i++){
			maxn=0;
			for(i2=0;i2!=n;i2++){
				if(point[i2]>point[maxn]){
				maxn=i2;
				}
			}
			printf("%s,%d\n",team[maxn],point[maxn]);
			point[maxn]=0;
		}
		scanf("%d",&n);
	}
	return 0;
}