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(){

  int n,d = 0;

  while(cin >> n, n){
    if(!d) cout << endl;

    int a,b,c,z[100],tmp;
    string s[100],tmp2;

    for(int i=0;i<n;i++){
      cin >> s[i] >> a >> b >> c;

      z[i] = a * 3 + c;
    }

    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(z[j] > z[j - 1]){

	  tmp = z[j];
	  z[j] = z[j - 1];
	  z[j - 1] = tmp;

	  tmp2 = s[j];
	  s[j] = s[j - 1];
	  s[j - 1] = tmp2;
	}
      }
    }

    for(int i=0;i<n;i++) cout << s[i] << "," << z[i] << endl;
  
    d = 1;
  }
}

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];
				}
			}
		}
		puts("");
		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;
				}
			}
		}
		puts("");
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef struct{
    string cry;
    int po;
}To;
 
int main(){
    int i,j,n,c=0;
    while(cin>>n&&n){
        if(c)cout<<endl;
        c++;
        To t[n];
        for(i=0;i<n;i++){
            int w,l,d;
            cin>>t[i].cry>>w>>l>>d;
            t[i].po=w*3+d;
        }
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(t[i].po<t[j].po){
                    To tmp=t[j];
                    t[j]=t[i];
                    t[i]=tmp;
                }
            }
        }
        for(i=0;i<n;i++){
            cout<<t[i].cry<<","<<t[i].po<<endl;
        }
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

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

struct data{
	int score;
	int id;
	string name;
	data(){};
	data(int s, int id, string n){
		this->score = s;
		this->id = id;
		this->name = n;
	}
};

bool comp(data d1, data d2){
	return d1.score == d2.score ? d1.id < d2.id : d1.score > d2.score;
}

data ds[10];

int main(){
	int n;
	int w, l, d;
	int cnt = 0;
	while(cin >> n && n){
		if(cnt != 0){
			cout << endl;
		}else{
			cnt++;
		}
		rep(i, n){
			cin >> ds[i].name >> w >> l >> d;
			ds[i].score = w * 3 + d;
			ds[i].id = i;
		}
		sort(ds, ds + n, comp);
		rep(i, n) cout << ds[i].name << "," << ds[i].score << endl;
	}
	return 0;
}

C++: #include<algorithm>
#include<string>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,f=0;
	while(cin>>n,n){
		if(f)cout<<endl; f=1;
		pair<int,pair<int,string> > team[10];
		int w,l,d;
		rep(i,n){
			cin>>team[i].second.second>>w>>l>>d;
			team[i].first=-w*3-d;
			team[i].second.first=i;
		}
		sort(team,team+n);
		rep(i,n)cout<<team[i].second.second<<","<<-team[i].first<<endl;
	}
	return 0;
}

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

int main()
{
	pair <string, int> score[10];
	int n, w, l, d;
	int flg = 0;
	while (1)
	{
		cin >> n;
		if (n == 0) break;

		for (int i = 0; i < n; i++)
		{
			cin >> score[i].first >> w >> l >> d;
			score[i].second = w * 3 + d;
		}
		if (flg == 1) cout << endl;
		sort(score, score + n);
		reverse(score, score + n);
		for (int i = 0; i < n; i++)
		{
			cout << score[i].first << "," << score[i].second << endl;
		}
		flg = 1;
	}

	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,x=0;
	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;
		if(x>0&&n!=0)cout<<endl;
		 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]);
	}
		x++;
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair

int main(){
  pair<int,int> data[10];
  char team[10][21];
  int n,d=0;
  while(cin>>n,n){
    if(d!=0)cout<<endl;
    d=1;
    REP(i,n){
      string s;
      int a,b,c;
      cin>>team[i]>>a>>b>>c;
      data[i]=MP(-(a*3+c),i);
    }
    sort(data,data+n);
    REP(i,n){
      cout<<team[data[i].second]<<","<<-data[i].first<<endl;
    }
  }
  
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;


int main()
{
	bool line_break = false;
	int n;
	while (cin >> n && n)
	{
		if (line_break)
			cout << endl;
		else
			line_break = true;

		pair<int, string> team[16];
		for (int i = 0; i < n; ++i)
		{
			string t;
			int a, b, c;
			cin >> t >> a >> b >> c;
			team[i] = make_pair(a*3 + c, t);
		}
		stable_sort(team, team + n, greater<pair<int, string> >());
		for (int i = 0; i < n; ++i)
			cout << team[i].second << ',' << team[i].first << endl;
	}

	return 0;
}