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<algorithm>
#include<string>
#include<vector>
#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()

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!= -1; i--)rep(j,teams[i].size())
            cout << teams[i][j] << "," << i << endl;
        
        sec = true;

    }

    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;


int main(){
	int n;
	bool f=false;
	while(cin >> n&&n){
		if(f) cout << "\n";
		f=true;
		vector<string> name;
		vector<int> point;
		
		for(int i=0; i<n; ++i){
			int win,lose,draw;
			string s;
			cin >> s >> win >> lose >> draw;
			name.push_back(s);
			point.push_back(win*3+draw);
		}
		
		for(int i=1; i<n; ++i){
			string s_tmp=name[i];
			int i_tmp=point[i];
			int j;
			for(j=i; ; --j){
				if(j==0||point[j-1]>=i_tmp) break;
				point[j]=point[j-1];
				name[j]=name[j-1];
			}
			point[j]=i_tmp;
			name[j]=s_tmp;
		}
		
		for(int i=0; i<n; ++i){
			cout << name[i] << "," << point[i] << "\n";
		}
	}
}

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

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

		for (int i = 0; i < n; i++)
		{
			cin >> score[i].first >> w >> l >> d;
			score[i].second = w * 3 + d;
		}
		flg++;

		sort(score, score + n);
		reverse(score, score + n);
		for (int i = 0; i < n; i++)
		{
			cout << score[i].first << "," << score[i].second << endl;
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    bool kawa=0;
    while(cin>>n,n){
        if(kawa)cout<<endl;
        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;
        }
        kawa=1;
        cout<<endl;
    }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

struct Team{
  string name;
  int win,lose,draw;
  int score;
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin>>n&&n){
    vector<Team> v(n);
    rep(i,n){
      cin >> v[i].name >> v[i].win>>v[i].lose >>v[i].draw;
      v[i].score = v[i].win*3 + v[i].draw;
    }
    sort(all(v),[](const Team &a,const Team &b){return a.score>b.score;});
    rep(i,n){
      cout << v[i].name << "," << v[i].score<<endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j;
	int temp,data[10];
	char tn[11][21],temps[21];
	int k,m,h;
	for(j=0;j<10;j++){
		data[j]=0;
	}
	while(scanf("%d",&n)!=0){
		for(j=0;j<n;j++){
			scanf("%s %d %d %d",tn[j],&k,&m,&h);
			data[j]+=k*3;
			data[j]+=h;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(data[j]<data[j+1]){
					temp=data[j+1];
					data[j+1]=data[j];
					data[j]=temp;
					strcpy(temps,tn[j+1]);
					strcpy(tn[j+1],tn[j]);
					strcpy(tn[j],temps);
				}
			}
		}
		for(j=0;j<n;j++){
			printf("%s,%d\n",tn[j],data[j]);
		}
		printf("\n");
		scanf("%d",&n);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{
    int n;
    int cnt = 0;

    while (cin >> n) {
        if (!n)
            break;
        if (cnt++)
            cout << endl;

        vector< pair<int, string> > tourn;

        for (int i = 0; i < n; i++) {
            int win, los, ev;
            string str;
        
            cin >> str >> win >> los >> ev;
            pair<int, string> p(win * 3 + ev, str);
            tourn.push_back(p);
        }
        sort(tourn.rbegin(), tourn.rend());
        
        for (int i = 0; i < tourn.size(); i++)
            cout << tourn[i].second << ',' << tourn[i].first << endl;
    }

    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(){
	while(1){
		int n,a,b,c;
		pii d[10];
		string s[10];
		cin>>n;
		if(n==0) break;
		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);
		}
		cout<<endl;
	}
}