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>
using namespace std;

struct Team{
	string name;
	int win;
	int lose;
	int draw;
	int point;
};

void sort( Team* teams, int n )
{
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j < n - 1; ++j ){
			if( teams[ j ].point < teams[ j + 1 ].point ){
				Team t = teams[ j ];
				teams[ j ] = teams[ j + 1 ];
				teams[ j + 1 ] = t;
			}
		}
	}
}

int main()
{
	int teamQuantity;

	while( cin >> teamQuantity ){
		if( teamQuantity == 0 ){
			break;
		}
		Team* teams = new Team[ teamQuantity ];
		for( int i = 0; i < teamQuantity; ++i ){
			cin >> teams[ i ].name >> teams[ i ].win >> teams[ i ].lose >> teams[ i ].draw;
			teams[ i ].point = teams[ i ].win * 3 + teams[ i ].draw;
		}
		sort( teams, teamQuantity );

		for( int i = 0; i < teamQuantity; ++i ){
			cout << teams[ i ].name << "," << teams[ i ].point << endl;
		}
		delete[] teams;
	}
	return 0;
}

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;
	
	while (cin >> n, n) {

		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++: #include<iostream>
#include<vector>
#include<algorithm>
#include <functional>
#include<string>
using namespace std;struct k{string s;int n;};bool x(const k&left,const k&right){return left.n>right.n;}int main(){vector<k> t;k c;int n,i=0,w,d;string s;while(cin>>n,n){if(i)cout<<endl;t.clear();for(i=0;i++<n;){cin>>s>>w>>d>>d;c.s=s;c.n=3*w+d;t.push_back(c);}sort(t.begin(),t.end(),x);for(i=0;i<n;i++)cout<<t[i].s<<","<<t[i].n<<endl;}return 0;}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
    int n, f=0;
    while (cin>>n) {
        if (!n) break;
        if (f) cout<<endl;
        pair<int,string> m[n];
        for (int i=0; i<n; i++) {
            cin>>m[i].second;
            int a,b,c; cin>>a>>b>>c;
            m[i].first=a*3+c*1;
        }
//        for (int i=0; i<n; i++) {
//            for (int j=i+1; j<n; j++) {
//                if (m[i].first<m[j].first) swap(m[i],m[j]);
//            }
//        }
        sort(m,m+n);
        for (int i=n-1; i>=0; i--) {
            cout<<m[i].second<<","<<m[i].first<<endl;
        }
        f++;
    }
}

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

using namespace std;

int main()
{
	vector<pair<int, pair<int, string> > > team;
	int n, pt[10][3];
	string str[10];

	while(1){
		cin >> n;

		if(n == 0)    break;

		for(int i = 0; i < n; i++)
			cin >> str[i] >> pt[i][0] >> pt[i][1] >> pt[i][2];

		for(int i = 0; i < n; i++)
			team.push_back(make_pair(((pt[i][0] * -3) - pt[i][2]), make_pair(i, str[i])));
		
		cout << endl;
		
		sort(team.begin(), team.end());
		
		for(int i = 0; i < n; i++)
			cout << team[i].second.second << "," << -(team[i].first) << endl;
		
		team.clear();
	}

	return 0;
}

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

pair<int, string> pa[10];

int main() {
	int N,ff=0;
	while (cin >> N, N) {
		if (ff == 1)cout << endl;
		for (int i = 0; i < N; i++) {
			cin >> pa[i].second;
			int w, l, d;
			cin >> w >> l >> d;
			pa[i].first = w * 3 + d;

		}

		sort(pa, pa + N );

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

	}

}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	vector<string> s;
	vector<pii> v;
	char c[21];
	int n,w,l,d,p,f=0;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		if(f)puts("");
		v.clear();
		s.clear();
		rep(i,n){
			scanf("%s%d%d%d",c,&w,&l,&d);
			p=w*3+d;
			s.push_back(string(c));
			v.push_back(make_pair(p,n-i));
		}
		sort(v.rbegin(),v.rend());
		f=1;
		rep(i,n)printf("%s,%d\n",s[n-v[i].second].c_str(),v[i].first);
	}
	return 0;
}

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

using namespace std;

class TeamInfo {
public:
	string name;
	int totalScore;
};

TeamInfo TeamData[10];

bool cmp(const TeamInfo &t1, const TeamInfo &t2) {
	return t1.totalScore > t2.totalScore;
}

int main() {
	int n, w, l, d;
	bool flag = false;

	while (cin >> n, n) {
		//memset(TeamData, 0, sizeof(TeamData));
		if (flag) {
			cout << endl;
		}
		for (int i = 0; i < n; i++) {
			cin >> TeamData[i].name;
			cin >> w >> l >> d;
			TeamData[i].totalScore = w * 3 + d;
		}
		sort(TeamData, TeamData + n, cmp);
		for (int i = 0; i < n; i++) {
			cout << TeamData[i].name << "," << TeamData[i].totalScore << endl;
		}
		flag = true;
	}

	return 0;
}

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

using namespace std;

int main()
{
	vector<pair<int, pair<int, string> > > team;
	int n, pt[10][3];
	string str[10];

	while(1){
		cin >> n;

		if(n == 0)    break;

		for(int i = 0; i < n; i++)
			cin >> str[i] >> pt[i][0] >> pt[i][1] >> pt[i][2];

		for(int i = 0; i < n; i++)
			team.push_back(make_pair(((pt[i][0] * -3) - pt[i][2]), make_pair(i, str[i])));

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

		for(int i = 0; i < n; i++)
			cout << team[i].second.second << "," << -(team[i].first) << endl;

		cout << endl;
		
		team.clear();
	}

	return 0;
}