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++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
class Team {
public:
	string name;
	int score;
	bool operator <(const Team &other) {
		return this->score > other.score;
	}
	bool operator >(const Team &other) {
		return other.score < this->score;
	}
	Team(string s, int x) {
		this->name = s;
		this->score = x;
	}
};
signed main() {
	int n, cnt(0);
	while (cin >> n, n) {
		vector<Team>team;
		rep(i, 0, n) {
			string s; int w, l, d;
			cin >> s >> w >> l >> d;
			Team a(s, w * 3 + d);
			team.push_back(a);
		}
		sort(team.begin(), team.end());
		if (cnt++)cout << endl;
		each(it, team)cout << it->name << " " << it->score << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a;
	bool k = false;
	while (cin >> a&&a != 0) {
		if (k)
			cout << endl;
		string s[10];
		int b[10];
		int g[10];
		bool l[10]; 
		for(int i = 0; i < a; i++) {
			string m;
			int c, d, e;
			cin >> m >> c >> d >> e;
			s[i] = m;
			int f = c * 3 + e;
			b[i] = f;
			g[i] = f;
			l[i] = true;
		}
		sort(g, g + a);
		for (int i = a-1; i >=0; i--) {
			int h = g[i];
			for (int j = 0; j < a; j++) {
				if (b[j] == h&&l[j]) {
					cout << s[j] << "," << h << endl;
					l[j] = false;
					break;
				}
			}
		}
		k = true;
	}
}

C++: using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXP = 31;

int main()
{
    string s;
    int n, w, l, e;
    bool sec = false;
    while(cin >> n && n)
    {
        if(sec) cout << endl;
        vector<string> teams[MAXP];
        
        REP(n)
        {
            cin >> s >> w >> l >> e;
            teams[w * 3 + e].push_back(s);
        }
        
        for(int i = MAXP-1;i!= 0; i--)rep(j,teams[i].size())
            cout << teams[i][j] << "," << i << endl;
        
        sec = true;

    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int N,a,b,c;
string s;

int main(){
	bool f=0;
	while(cin>>N){
		if(!N)return 0;
		if(f)cout<<endl;
		pair<int,pair<int,string> > p[10];
		for(int i=0;i<N;i++){
			cin>>s>>a>>b>>c;
			p[i]=make_pair(a*-3-c,make_pair(i,s));
		}
		sort(p,p+N);
		for(int i=0;i<N;i++)cout<<p[i].second.second<<","<<-1*p[i].first<<endl;
		f=1;
	}
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair

using namespace std;

struct Team
{
	int point;
	int num;
	string name;

	bool operator< (const Team& t)const
	{
		return point == t.point ?  num < t.num : point < t.point;
 	}

};

int main()
{
	int n;
	bool fisrt = true;
	while(cin >> n && n)
	{

		if(fisrt)
		{
			fisrt = false;
		}
		else
		{
			cout << endl;
		}
		priority_queue<Team> q;
		string s;
		int a,b,c;
		rep(i,n)
		{
			cin >> s >> a >> b >> c;
			Team t;
			t.point = 3*a + c;
			t.num = 9;
			t.name = s;
			
			q.push(t);
		}

		rep(i,n)
		{
			cout << q.top().name << "," << q.top().point << endl;
			q.pop();
			
		}
		
	}
	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++;
    cin>>n;
        if(n==0){
            break;
        }
        if(num!=1){
            cout<<endl;
        }
    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;
}

C++: #include<iostream>
#include<map>
using namespace std;
int main(){
  int n,p=0;
  while(cin>>n,n){
    multimap<int,string,greater<int> >m;
    if(p)cout<<endl;
    p++;
    while(n--){
    string s;
    int a,b,c;  
    cin>>s>>a>>b>>c;
    a=a*3+c;
    m.insert( make_pair(a,s) );
    }
    for(multimap<int,string,greater<int> >::iterator it=m.begin();it!=m.end();it++){
      cout<<(*it).second<<','<<(*it).first<<endl;
      }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>
#include <functional>
using namespace std;
typedef pair<int,string> p;
p team[10];
int main()
{
	int n;
	bool first=true;
	while(cin>>n&&n){
		if(!first)cout<<endl;
		for(int i=0;i<n;i++){
			int k,m,h;
			cin>>team[i].second>>k>>m>>h;
			team[i].first=(k*3+h)*100+10-i;
		}
		sort(team,team+n,greater<p>());
		for(int i=0;i<n;i++){
			cout<<team[i].second<<","<<(int)team[i].first/100<<endl;
		}
		first=false;
	}
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n,a,b,c,w[10],s[10]={0,1,2,3,4,5,6,7,8,9},i,j,temp;
	char as[10][21];
	while(1){
	scanf("%d",&n); //???????????°
		if(n==0)break;
	for(i=0;i<n;i++){
		scanf("%s%d%d%d",as[i],&a,&b,&c);
		w[i]=a*3+c;
	}
	for(i=1;i<n;i++){
		for(j=0;j<n;j++){
			if(w[i]>w[j]){
				temp=w[i];
				w[i]=w[j];
				w[j]=temp;
				temp=s[i];
				s[i]=s[j];
				s[j]=temp;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s,%d\n",as[s[i]],w[i]);
	}
	}
	return 0;
}