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>
using namespace std;

struct Team {
    int id, point;
    string name;
    bool operator<(const Team& other) const {
        return point == other.point
               ? id < other.id
               : point > other.point;
    }
};

int main() {
    int n;
    bool first = true;

    while (cin >> n, n) {
        Team team[10];
        if (!first) cout << endl; first = false;
        for (int i = 0; i < n; i++) {
            int w, l, d;
            team[i].id = i;
            cin >> team[i].name >> w >> l >> d;
            team[i].point = w*3 + d;
        }
        sort(team, team+n);
        for (int i = 0; i < n; i++) {
            cout << team[i].name << "," << team[i].point << endl;
        }
    }
    return 0;
}

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

typedef pair<int,string> P;

bool compare(P a,P b){
    return a.first > b.first;
}

int main(){
    int n,a,b,c,t=0;
    string str;
    
    while(cin >> n,n){
        if(t) puts("");
        t++;
        vector<P> v;
        for(int i = 0 ; i < n ; i++){
            cin >> str >> a >> b >> c;
            int p = a*3+c;
            v.push_back(P(p,str));
        }
        stable_sort(v.begin(),v.end(),compare);
        
        for(int i = 0 ; i < n ; i++){
            cout << v[i].second << "," << v[i].first << endl;
        }
    }

    return 0;
}

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

struct Team{
    string name;
    int id;
    int point;
    bool operator <(const Team& r) const{
        return point == r.point ? id < r.id : point > r.point;
    }
};


int main(){
    string name;
    int n, a, b, c, i = 0;
    while(cin >> n, n){
        if(i) cout << endl;
        vector< Team > v(10);
        for(i = 0; i < n; i++){
            cin >> name >> a >> b >> c;
            v[i].id = i;
            v[i].name = name;
            v[i].point = a * 3 + c;
        }
        sort(v.begin(), v.end());
        for(i = 0; i < n; i++){
            cout << v[i].name << "," << v[i].point << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct nx { 
string name;
int cost;
};
int main() {
	int n, f=0;
	while (cin>>n) {
		if (!n) break;
		if (f) cout<<endl;
		nx m[n];
		for (int i=0; i<n; i++) {
			cin>>m[i].name;
			int a,b,c; cin>>a>>b>>c;
			m[i].cost=a*3+c*1;
		}
		for (int i=0; i<n; i++) {
			for (int j=i+1; j<n; j++) {
				if (m[i].cost<m[j].cost) swap(m[i],m[j]);
			}
		}
		for (int i=0; i<n; i++) {
			cout<<m[i].name<<","<<m[i].cost<<endl;
		}
		f++;
	}
}

C++: #include<cstdio>
#include<cstring>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i,j,k;
	int kati,make,hiki,ten[10],ss[10];
	char team[10][21];
	while(1) {
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++) {
			scanf("%s %d %d %d",team[i],&kati,&make,&hiki);
			ten[i]=(kati*3)+(hiki*1);
			ss[i]=(kati*3)+(hiki*1);
		}
		sort(ten,ten+n,greater<int>());
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(ten[i]==ss[j]) {
					printf("%s,%d",team[j],ten[i]);
					break;
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;



//??????
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int i = 1; i < N; i++) cout << ", " << v[i]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()


int main()
{
	bool blank = false;
	while (true) {

		map<int, vector<string>> standings;

		int n;
		cin >> n;
		if (n == 0) break;

		if (blank) cout << endl;

		string name;
		int w, l, d;
		for (int i = 0; i < n; i++) {
			cin >> name >> w >> l >> d;
			int score = w * 3 + d;
			standings[-score].push_back(name);
		}

		for (auto itr = standings.begin(); itr != standings.end(); itr++) {
			for (int i = 0; i < itr->second.size(); i++) {
				cout << itr->second[i] << "," << - itr->first << endl;
			}
		}

		blank = 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;
	while(cin >> n&&n){
		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";
		}
		cout << "\n";
	}
}