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>
#include <iterator>
#include <map>
#include <vector>
#include <functional>

using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

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

C++: #include<stdio.h> 
#include<string> 
#include<iostream> 
using namespace std;   
struct TA{ 
	string name; int po; int rr;
};     
int main(){ 
	int n; 
	struct TA N[11];  
	bool ty=true;
	while(1){ scanf("%d",&n);
	if(n==0)break; 
		if(ty==false)cout<<endl;
	ty=false;
	for(int i=0;i<n;i++) 

	
	{cin>>N[i].name;int a,b,c; cin>>a>>b>>c; 
	N[i].po=a*3+c*1; N[i].rr=i; } 
	for(int i=0;i<n;i++) for(int j=n-1;j>i;j--) 
		if(N[j].po>N[j-1].po){struct TA T=N[j];N[j]=N[j-1];N[j-1]=T;}   
		for(int i=0;i<n;i++) 
		cout<<N[i].name<<","<<N[i].po<<endl;         
	}
	return 0;
}

C++: #include<stdio.h>

int main()
{
	int score[11],win,lose,draw,point[11];
	int n,i,j;
	char str[11][21];
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",str[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
			point[i]=score[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]>point[j]){
					point[10]=point[i];
					point[i]=point[j];
					point[j]=point[10];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]==score[j]){
					printf("%s,%d\n",str[j],score[j]);
					score[j]=-1;
					break;
				}
			}
		}
//		printf("\n");
	}
	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];
		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;
		}
		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) {
					cout << s[j] << "," << h << endl;
					break;
				}
			}
		}
		k = true;
	}
}

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

struct Tm
{
	int point;
	string name;
	Tm(string s, int p){name=s;point=p;}
	bool operator<(const Tm &t) const
	{
		return point>t.point;
	}
};

int main()
{
	bool f=false;
	int n,a,b,c;
	string str;

	while(cin >> n, n)
	{
		if(f) cout << endl; f=true;

		vector<Tm> v;
		while(n--)
		{
			cin >> str >> a >> b >> c;
			v.push_back(Tm(str,a*3+c));
		}
		stable_sort(v.begin(), v.end());

		for(int i=0; i<v.size(); i++)
		{
			cout << v[i].name << "," << v[i].point << endl;
		}
	}
}

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;
		
		cout << endl;
		
		team.clear();
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    string s;
    int w, l, d;
    bool p = 0;
    while (cin >> n, n)
    {
        if (p)
            cout << endl;
        p = 1;
        multimap<int, string, greater<int>> mp;
        rep(i, n)
        {
            cin >> s >> w >> l >> d;
            mp.insert(make_pair(3 * w + d, s));
        }

        for (auto a : mp)
            cout << a.second << "," << a.first << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <utility>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    bool first = 1;
    while( 1 )
    {
        int n;
        if( !first )
        {
            printf( "\n" );
        }
        else
        {
            first = 0;
        }
        scanf( "%d", &n );
        if( n == 0 ) break;
        pair< string, int > p[10];
        int i = 0;
        while( i < n )
        {
            string s;
            cin >> s;
            int w,l,d;
            cin >> w >> l >> d;
            p[i] = make_pair( s, w * 3 + d );
            i++;
        }
        for( int j = 0; j < n; j++ )
        {
            for( int k = j; k < n; k++ )
            {
                if( p[j].second < p[k].second )
                {
                    swap( p[j], p[k] );
                }
            }
        }
        for( int j = 0; j < n; j++ )
        {
            cout << p[j].first << ',' << p[j].second << '\n';
        }
    }   
    return 0; 
}

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;
}