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<stdio.h>
#include<string.h>
int main(void)
{
	int n;
	int i,j,temp;
	int w[200],l[200],d[200],a[200];
	int s[200];
	char team[10][21],m[21];
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			s[i]=0;
			scanf("%s %d %d %d",team[i],&w[i],&l[i],&d[i]);
			s[i]=w[i]*3+l[i]*0+d[i]*1;
			a[i]=i;
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(s[i]<s[j]){
					temp=s[i];
					s[i]=s[j];
					s[j]=temp;
					strcpy(m,team[i]);
					strcpy(team[i],team[j]);
					strcpy(team[j],m);
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(s[i]==s[j] && a[i]>a[j]){
					temp=s[i];
					s[i]=s[j];
					s[j]=temp;
					strcpy(m,team[i]);
					strcpy(team[i],team[j]);
					strcpy(team[j],m);
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%s,%d\n",team[i],s[i]);
		}
		scanf("%d",&n);
		if(n!=0){
			printf("\n");
		}
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF            1e9
#define INFLL          1e18
#define EPS            1e-9
#define REP(i,n)       for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)      for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(ll i=(n);i>0;--i)
#define REPC(i,obj)    for(auto i:obj)
#define ALL(obj)       (obj).begin(),(obj).end()
#define SETP(n)        cout<<fixed<<setprecision(n)
#define VV(T,h,w)      move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i)   move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T, ll h, ll w>using vec2 = vector<vector<T>>;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n;
	for (ll h = 0; n = in(); ++h) {
		if (h != 0)cout << endl;
		vector<string>name(n);
		vector<pair<ll, ll>>point(n);
		REP(i, n) {
			ll w, l, d;
			cin >> name[i] >> w >> l >> d;
			point[i] = make_pair(w * 3 + d, -i);
		}
		sort(ALL(point), greater<pair<ll, ll>>());
		REPC(i, point) cout << name[-i.second] << ',' << i.first << endl;
	}
}

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

using namespace std;

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

	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
pair<int,int> dat[10];char p[10][21];
int main(){
	int a;bool saisho=1;
	while(scanf("%d",&a),a){
		if(!saisho)printf("\n");
		saisho=0;
		for(int i=0;i<a;i++){
			int b,c,d;
			scanf("%s%d%d%d",p[i],&b,&c,&d);
			dat[i]=make_pair(-(b*3+d),i);
		}
		std::sort(dat,dat+a);
		for(int i=0;i<a;i++){
			printf("%s,%d\n",p[dat[i].second],-dat[i].first);
		}
	}
}

C++: // 2011/02/02 Tazoe

#include <iostream>
#include <string>
using namespace std;

struct score{
	string nam;
	int win;
	int los;
	int drw;
	int ord;
	int pnt;
};

int main()
{
	bool flg = false;

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

		if(flg)
			cout << endl;
		else
			flg = true;

		struct score tem[10];
		for(int i=0; i<n; i++){
			cin >> tem[i].nam >> tem[i].win >> tem[i].los >> tem[i].drw;
			tem[i].ord = i;
		}

		for(int i=0; i<n; i++)
			tem[i].pnt = tem[i].win*3+tem[i].drw;

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(tem[i].pnt<tem[j].pnt||(tem[i].pnt==tem[j].pnt&&tem[i].ord>tem[j].ord)){
					struct score tmp = tem[i];
					tem[i] = tem[j];
					tem[j] = tmp;
				}

		for(int i=0; i<n; i++)
			cout << tem[i].nam << ',' << tem[i].pnt << endl;
	}

	return 0;
}

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

int main()
{
    auto cmp = [](const pair<string, int> &a, const pair<string, int> &b) {
        return a.second > b.second;
    };
    string str;
    int n, w, e, l;
    for (int t = 0; ; t++) {
        scanf("%d", &n);
        if (n == 0) break;
        if (t) cout << endl;
        pair<string, int> countries[n];
        for (int i = 0; i < n; i++) {
            cin >> str >> w >> l >> e;
            countries[i].first = str;
            countries[i].second = w * 3 + e;
        }
        sort(countries, countries+n, cmp);
        for (int i = 0; i < n; i++) {
            cout << countries[i].first << "," << countries[i].second << endl;
        }
    }
    return 0;
}

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

int main() {
  int it = 0;
  int n;
  string str; int a, b, c;
  while (cin >> n) {
    if (n == 0) break;
    if (it++ != 0) cout << endl;
    vector< pair<pair<int, int>, string> > data(n);
    for (int i = 0; i < n; ++i) {
      cin >> str >> a >> b >> c;
      int val = a*3 + c;
      data[i] = make_pair(make_pair(val, n-i), str);
    }
    sort(data.begin(), data.end());
    for (int i = n-1; i >= 0; --i) {
      cout << data[i].second << "," << data[i].first.first << endl;
    }
  }
}

C++: #include <iostream>
#include <algorithm>
struct team{
	std::string name;
	int point;
	int n;
};

bool tsort(const team& a,const team& b){
	if(a.point - b.point){
		return a.point > b.point;
	}
	return a.n < b.n;
}

int main(){
	int n;
	while(std::cin>>n,n){
		team all[10];
		for(int i = 0;i < n;i++){
			std::string name;
			int w,d,l;
			std::cin>>name>>w>>l>>d;
			team t = {name,w*3+d,i};
			all[i] = t;
		}
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<all[i].point<<std::endl;
		}
		std::cout<<std::endl;
	}
	return 0;
}

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

int main()
{

	while (1)
	{
		vector< pair<int, string> > team;
		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;
		}

		cout << endl;
	}

	return 0;
}