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 <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>


using namespace std;

struct country_point{
    string country;
    int num;
    int point;
};

bool country_point_compare(country_point l, country_point r){
    if(l.point>r.point)return true;
    if(l.point<r.point)return false;
    if(l.num<r.num)return true;
    return false;
}

int main(){
    int n;
    bool flag=false;
    while(cin>>n){
        if(n==0)break;
        if(flag)cout<<endl;
        flag = true;

        country_point all_country[10];
        for(int i=0; i<n; i++){
            string c;
            cin>>c;
            all_country[i].country = c;
            int win, loss, drow;
            cin>>win;
            all_country[i].point=win*3;
            cin>>loss;
            cin>>drow;
            all_country[i].point+=drow;
            all_country[i].num = i;
        }
        
        sort(all_country, all_country+n, country_point_compare);
        
        for(int i=0; i<n; i++){
            cout<<all_country[i].country<<","<<all_country[i].point<<endl;
        }
    }
    
}

C++: #include<iostream>
#include<string>
using namespace std;
string s[1000000];
int a[1000000][3], score[1000000], cnt;
int n;
int main() {
	while (true) {
		cin >> n;
		if (!n) { break; }
		if (cnt) { cout << endl; }
		cnt++;
		for (int i = 0; i < n; i++) {
			cin >> s[i] >> a[i][0] >> a[i][1] >> a[i][2];
			score[i] = a[i][0] * 3 + a[i][2];
		}
		for (int j = 100000; j >= 0; j--) {
			for (int k = 0; k < n; k++) {
				if (score[k] == j) {
					cout << s[k] << ',' << score[k] << endl;
				}
			}
		}
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        char team[11][21] = {{0}};
        int w[11],d[11],l[11];
        int to[11][2] = {0};

        //in
        for(int i = 0;i < n; i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            to[i][0] = (w[i]*3)+d[i];
            to[i][1] = w[i];
        }
        //out
        for(int i = 0;i < n; i++){
            for(int j = 0;j < n; j++){
                if(to[i][0] > to[j][0]){
                    swap(to[i][0],to[j][0]);
                    swap(team[i],team[j]);
                }
                else if(to[i][0] == to[j][0]){
                    if(to[i][1] > to[i][1]){
                        swap(to[i][0],to[j][0]);
                        swap(team[i],team[j]);
                    }
                }
            }
        }
        for(int i = 0;i < n; i++)printf("%s,%d\n",team[i],to[i][0]);
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	char na[10][21],x[21];
	int n,w[10],l[10],d[10],a[10],i,j,y,flg;
	flg=1;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%s %d %d %d",na[i],&w[i],&l[i],&d[i]);
			l[i]=w[i]*3+d[i];
			a[i]=i;
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(l[i]<l[j] || l[i]==l[j] && a[i]>a[j]){
					y=l[i];  l[i]=l[j];  l[j]=y;
					y=a[i];  a[i]=a[j];  a[j]=y;
					strcpy(x,na[i]);  strcpy(na[i],na[j]);  strcpy(na[j],x);
				}
			}
		}
		if(flg==0)  printf("\n");
		for(i=0;i<n;i++)  printf("%s,%d\n",na[i],l[i]);
		flg=0;
		scanf(" %d",&n);
	}
	return 0;
}

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

using namespace std;

int main()
{
    while( 1 )
    {
        int n;
        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 <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int N, C = 0, X, Y, Z;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		if (C++) { cout << endl; }

		vector<pair<int, string> > R(N);

		for (int i = 0; i < N; i++)
		{
			cin >> R[i].second >> X >> Y >> Z;

			R[i].first = X * 3 + Z;
		}

		for (int i = 0; i < N; i++)
		{
			for (int j = i + 1; j < N; j++)
			{
				if (R[i].first < R[j].first)
				{
					swap(R[i], R[j]);
				}
			}
		}

		for (int i = 0; i < N; i++)
		{
			cout << R[i].second << ',' << R[i].first << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
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()

typedef pair<int, int> pp;
typedef pair<pp, string> ppp;

int main()
{
    int sec = 0, n;
    while(cin >> n && n)
    {
        if(sec) cout << endl;
        vector<ppp> res;
        string t;
        int win, lose, even;
        REP(n)
        {
            cin >> t >> win >> lose >> even;
            res.push_back(ppp(pp(-(win * 3 + even * 1), i), t));
        }
        sort(all(res));
        REP(n) cout <<  res[i].second << "," <<-res[i].first.first << endl;
        sec = 1;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#define mp make_pair
using namespace std;

typedef pair<int,string> P;
typedef pair<int,P> PP;

int main(){
	int n;
	bool flag = false;
	while(cin >> n,n){
		if(flag) cout << endl;
		else flag = true;
		vector<PP> vec;
		for(int i = 0;i < n;i++){
			string s;
			int a,b,c;
			cin >> s >> a >> b >> c;
			vec.push_back(mp(a * 3 + c,mp(-i,s)));
		}
		sort(vec.begin(),vec.end(),greater<PP>());
		for(int i = 0;i < n;i++){
			cout << vec[i].second.second;
			printf(",%d\n",vec[i].first);
		}
	}
	return 0;
}