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++: /*
	AOJ_0124: League Match Score Sheet
*/
#include	<iostream>
#include	<string>
#include	<algorithm>
#include	<vector>

using namespace std;

class Teams {
private:
	int num;
	string name;
	int score;
public:
	Teams(){
		score = 0;
	}
	Teams(int n, string c, int s){
		num = n;
		name = c;
		score = s;
	}
	void showTeams(void) {
		cout << name << ',' << score << endl;
	}
	bool operator<(const Teams& another) const {
		if (score != another.score) { return score > another.score; }
		return num < another.num;
	}
};

int main(void) {
	int N, c_win, c_draw, c_lose, c_score;
	string c_name;
	while (1) {
		vector<Teams> T;

		cin >> N;
		if (N == 0) { break; }

		for (int i = 0; i < N; i++) {
			cin >> c_name >> c_win >> c_lose >> c_draw;
			c_score = c_win * 3 + c_draw;
			T.push_back( Teams(i, c_name, c_score) );
		}
		sort(T.begin(), T.end());
		vector<Teams>::iterator it = T.begin();
		while (it != T.end()) {
			it->showTeams();
			it++;
		}
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct nx { 
string name;
int cost;
};
class Comp {
	public:
		bool operator() (const nx& a, const nx& b) {
			return a.cost > b.cost;
		}
};
int main() {
	int n;
	while (cin>>n&&n) {
		vector<nx> m(n);
		for (int i=0; i<n; i++) {
			cin>>m[i].name;
			int a,b,c; cin>>a>>b>>c;
			m[i].cost=a*3+c*1;
		}
		sort(m.begin(), m.end(), Comp());
		for (int i=0; i<n; i++) {
			cout<<m[i].name<<","<<m[i].cost<<endl;
		}
		cout<<endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
string str[10];
P t[10];
int n=-1,a,b,c;
int main(){
  cin>>n;
  while(1){
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str[i]>>a>>b>>c;
      t[i].first=(a*3+c)*-1;
      t[i].second=i;
    }
    sort(t,t+n);
    
    for(int i=0;i<n;i++){
      cout<<str[t[i].second]<<','<<t[i].first*-1<<endl;
    }
    cin>>n;
    if(n==0)break;
    cout<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
typedef struct{
  int ans;
  char s[1111];
}Team;

Team team[11111];
int main(){
  int n;
  int flag=0;
  int a,b,c;
  while(1){
    cin >> n;
    if(n==0)break;
    if(flag==1){
      cout << endl;
    }
    flag=1;
    for(int i=0;i<n;i++){
      cin >> team[i].s >> a >> b >> c;
      team[i].ans=a*3 + c;
    }
    for(int i=0;i<n;i++){
      for(int j=n-1;j>i;j--){
	if(team[i].ans<=team[j].ans){
	  Team tmp=team[i];
	  team[i]=team[j];
	  team[j]=tmp;
	}
      }
    }
    for(int i=0;i<n;i++){
      cout << team[i].s << "," << team[i].ans << endl;
    }
  }
}

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

using namespace std ;

struct s
{
	int p ;
	string tm ;
} ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int p1 ;
		s st[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> st[ i ].tm >> st[ i ].p >> p1 >> p1 ;
			st[ i ].p = st[ i ].p * 3 + p1 ;
		}

		for( int i = 0 ; i < n ; i++ )
		{
			for( int j = i + 1 ; j < n ; j++ )
			{
				if( st[ i ].p < st[ j ].p )
					swap( st[ i ] ,st[ j ] ) ;
			}
		}

		for( int i = 0 ; i < n ; i++ )
			cout << st[ i ].tm << ", " << st[ i ].p << endl ;

	}
	return 0 ;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define SCORE first
#define TEAM second.second

using namespace std;

typedef pair<int, pair<int, string> > piis;

int main(void){
    for(int n, end = 0; cin >> n, n;){
        if(end ++) cout << endl; 
        vector<piis> table;
        while(n --){
            int w, l, d;
            string team;
            cin >> team >> w >> l >> d;
            table.push_back(make_pair(3 * w + d, make_pair(n, team)));
        }
        sort(ALL(table), greater<piis>());

        rep(i, table.size())
            cout << table[i].TEAM << ',' << table[i].SCORE << endl;
    }

}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	int n, win, lose, draw;
	string team;
	
	bool first = true;
	
	while (cin >> n, n)
	{
		vector<pair<pair<int, int>, string> > v;
		rep(i, n)
		{
			cin >> team >> win >> lose >> draw;
			v.push_back(mp(mp(win * 3 + draw, -i), team));
		}
		
		sort(v.rbegin(), v.rend());
		
		if (first)
		{
			first = false;
		} else {
			cout << endl;
		}
		
		rep(i, v.size())
		{
			cout << v[i].second << "," << v[i].first.first << endl;
		}
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

struct Team{
	char name[21];
	int score;
};

int main(){

	int n,win,lose,even;
	bool First = true;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		if(!First)printf("\n");

		Team array[n];

		for(int i=0; i < n; i++){
			scanf("%s %d %d %d",array[i].name,&win,&lose,&even);
			array[i].score = 3*win+even;
		}

		for(int i=1; i <= n-1; i++){
			for(int k=n-1; k >= i; k--){
				if(array[k].score > array[k-1].score)swap(array[k],array[k-1]);
			}
		}
		for(int i=0; i< n; i++){
			printf("%s,%d\n",array[i].name,array[i].score);
		}

		if(First)First = false;
	}

    return 0;
}