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>
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;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }cout<<endl;
    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 <cstdio>
#include <algorithm>

using namespace std;

struct team{
	string name;
	int point;
};

team teams[50];

int main(){
	
	int n;
	
	cin >> n;
	
	while(true){
		if(n == 0){
			break;
		}
		
		int a, b, c;
		for(int i = 0; i < n; i++){
			cin >> teams[i].name;
			cin >> a >> b >> c;
			teams[i].point = a * 3 + c;
		}
		
		for(int i = 0; i < n; i++){
			for(int j = n - 1; j > 0; j--){
				if(teams[j - 1].point < teams[j].point){
					swap(teams[j - 1], teams[j]);
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			cout << teams[i].name << "," << teams[i].point << endl;
		}
		cin >> n;
		if(n != 0){
			cout << endl;
		}
	}
	
	return 0;
}

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

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int f=0;
	while(1){
		int n,a,b,c;
		pii d[10];
		string s[10];
		cin>>n;
		if(n==0) break;
		if(f==1) cout<<endl;
		rep(i,0,n){
			cin>>s[i]>>a>>b>>c;
			d[i].fi=3*a+c; d[i].se=n-i;
		}
		sort(d,d+n);
		reverse(d,d+n);
		rep(i,0,n){
			o(s[n-d[i].se]<<","<<d[i].fi);
		}
		f=1;
	}
}

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

//typedef pair<int, string> pis;

using namespace std;

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

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

}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#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 all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	tuple<int, int, string> a[10];
	for (int n; cin >> n&&n;) {
		rep(i, 0, n) {
			string name; cin >> name;
			int w, l, d; cin >> w >> l >> d;
			a[i] = make_tuple(w * 3 + d, -i, name);
		}
		sort(a, a + n);
		rrep(i, 0, n) {
			cout << get<2>(a[i]) << "," << get<0>(a[i]) << endl;
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>
#include <functional>
using namespace std;
pair<int,pair<int,string>> 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.second>>k>>m>>h;
			team[i].first=k*3+h;
			team[i].second.first=-i;
		}
		sort(team,team+n,greater<pair<int,pair<int,string>>>());
		for(int i=0;i<n;i++){
			cout<<team[i].second.second<<","<<team[i].first<<endl;
		}
		first=false;
	}
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        string str[10];
        int num[10];
        for(int i=0,win,lose,draw;i<n;i++){
            cin>>str[i]>>win>>lose>>draw;
            num[i]=win*3+draw;
            str[i]+=',';
        }
        for(int i=0;i<n;i++){
            int ma=0;
            for(int j=0;j<n;j++)if(num[ma]<num[j])ma=j;
            cout<<str[ma]<<num[ma]<<endl;
            num[ma]=-1;
        }
        cout<<endl;
    }
}

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

using namespace std;

typedef struct {
	int sum;
	char name[20];
} TEAM;

int main()
{
	int n;
	int win, lose, drow;
	bool flg = 0;
	TEAM team[10], tmp;

	while (1){
		scanf("%d", &n);

		if (n == 0){
			break;
		}

		if (flg == false){
			flg = true;
		}
		else {
			cout << endl;
		}

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

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (team[j].sum > team[j - 1].sum){
					strcpy(tmp.name, team[j - 1].name);
					tmp.sum = team[j - 1].sum;

					strcpy(team[j - 1].name, team[j].name);
					team[j - 1].sum = team[j].sum;
					
					strcpy(team[j].name, tmp.name);
					team[j].sum = tmp.sum;
				}
			}
		}

		for (int i = 0; i < n; i++){
			cout << team[i].name << "," << team[i].sum << endl;
		}
	}

	return (0);
}