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<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n;
    for(int _ = 0; cin >> n,n; _++){
        pair<int,string> p[21];
        if(_) cout << endl;
        rep(i,n){
            string name;
            int a,b,c;
            cin >> name >> a >> b >> c;
            p[i] = make_pair(a * 3 + c, name);
        }
        sort(p, p + n,
                [](pair<int, string> x, pair<int, string> y) -> bool {
                return ( x.first > y.first );
                } );
        for(auto it:p){
            if(it.second.empty()) break;
            cout << it.second <<',' << it.first << endl;
        }
    }
}

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

class data{

public:
char name;
int win;
int lose;
int draw;

int score;

};

int main(){

int teamamo;

while(true){

cin>>teamamo;

if(teamamo==0)
break;

data teamdata[10];
data comp;

for(int i=0; i<teamamo; i++)
cin>>teamdata[i].name>>teamdata[i].win>>teamdata[i].lose>>teamdata[i].draw;

for(int i=0; i<teamamo; i++)
teamdata[i].score=teamdata[i].win*3+teamdata[i].draw;

for(int i=0; i<teamamo-1; i++){

if(teamdata[i].score<teamdata[i+1]){

char fout; 
fout=teamdata[i].name;
teamdata[i].name=teamdata[i+1].name;
teamdata[i+1].name=fout;

int gout;
gout=teamdata[i].win;
teamdata[i].win=teamdata[i+1].win;
teamdata[i+1].win=gout;

gout=teamdata[i].lose;
teamdata[i].lose=teamdata[i+1].lose;
teamdata[i+1].lose=gout;

gout=teamdata[i].draw;
teamdata[i].draw=teamdata[i+1].draw;
teamdata[i+1].draw=gout;

gout=teamdata[i].score;
teamdata[i].score=teamdata[i+1].score;
teamdata[i+1].score=gout;

    }


   }

for(int i=0; i<teamamo; i++)
cout<<teamdata[i].name<<','<<teamdata[i].score<<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;
	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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	bool f=true;
	while(n=in()){
		if(!f){cout<<endl;}f=false;
		vector<pair<int,string> > country(n);
		int i;
		int win,lose,draw;
		string str;
		for(i=0;i<n;i++){
			cin>>str>>win>>lose>>draw;
			country[i]=mp(win*3+draw,str);
		}
		sort(country.begin(),country.end(),greater<pair<int,string> >());
		for(i=0;i<n;i++){
			cout<<country[i].second<<","<<country[i].first<<endl;
		}
	}
	return 0;
}

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

typedef pair<int, string> Team;

int main(void){  
  int n, firstDS=0;
  
  while (cin >> n){
    vector<Team> v;
    if (n==0) break;
    if (firstDS==0) firstDS= 1;
    else cout << endl;
    for (int i=0; i<n; i++){
      string nm;
      int w,l,d;
      Team t;
      cin >> nm >> w >> l >> d;
      t = make_pair(w*3+d, (char)('z'-i)+nm);
      v.push_back(t);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (int i=0; i<n; i++){
      cout << (v[i].second.c_str()+1) << ",";
      cout << v[i].first << endl;
    }
  }
  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++)

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

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a, b, c;
vector < pair<ll,string> > v;
string s;

int main(){
	bool f = 0;
	while (cin >> n&&n){
		REP(i, n){
			cin >> s >> a >> b >> c;
			v.push_back(make_pair(a * 3 + c, s));
		}
		REP(i, v.size()-1){
			FOR(j, i + 1, v.size()){
				if (v[i].first < v[j].first)swap(v[i], v[j]);
			}
		}
		if (f)cout << " " << endl;
		REP(i, v.size()){
			cout << v[i].second << "," << v[i].first << endl;
		}
		f = 1;
		v.clear();
	}
}

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