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<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;
typedef pair<int,int> P; 
typedef pair<string,P> PP;
int main(){
  int n;
  bool first = true;
  while(cin >> n && n){
    if(!first)cout << endl;
    string s;
    first = false;  
  vector<PP> vec;
    int a,b,c;
    for(int i=0;i<n;i++){
    cin >> s >> a >> b >> c;
    vec.push_back(PP(s,P(i,a*3+b*0+c*1)));
    }

    sort(vec.begin(),vec.end(),greater<PP>() );
    //reverse(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
      cout << vec[i].F << "," << vec[i].S.S << endl;
    }
 
  }
  return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
using namespace std;

int main() {
	int n;
	while (cin >> n&&n != 0) {
		vector<pair<int ,string>> result;
		string s;
		int a, b, c;
		for (int i = 0; i < n; i++) {
			cin >> s >> a >> b >> c;
			result.emplace_back(a * 3 + c * 1, s);
		}
		sort(result.begin(), result.end());
		for (int i = n-1; i >=0; i--) {
			cout << result[i].second << "," << result[i].first << endl;
		}
	}
}

C++: // Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
bool flg = false;
while(true){
	int n;
	cin >> n;
if(n==0)
break;
	string T[10];
	int P[10];
	int I[10];
	for(int i=0; i<n; i++){
		cin >> T[i];

		int w, l, d;
		cin >> w >> l >> d;
		P[i] = w*3+d;

		I[i] = i;
	}

	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			if(P[i]<P[j]||(P[i]==P[j]&&I[i]>I[j])){
				string s_tmp = T[i];
				T[i] = T[j];
				T[j] = s_tmp;

				int tmp = P[i];
				P[i] = P[j];
				P[j] = tmp;

				tmp = I[i];
				I[i] = I[j];
				I[j] = tmp;
			}
		}
	}
if(flg)
cout << endl;
	for(int i=0; i<n; i++){
		cout << T[i] << ',' << P[i] << '\n';
	}
flg = true;
}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,w,l,d,flag=0;
    string s;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            if (flag!=0) {
                cout<<endl;
            }
            std::multimap<int,string,greater<int>> map;
            int score=0;
            for (int i=0;i<n;i++) {
                cin>>s>>w>>l>>d;
                score=w*3+d;
                map.insert(make_pair(score,s));
            }
            for (auto const& entry: map) {
                cout<<entry.second<<","<<entry.first<<endl;
            }
            flag=1;
        }
    }
    
}

C++: #include<iostream>
#include<string>
using namespace std;
string team[10];
int point[10];
bool isfirst = true;
int main(){
  int n,temp,cur;
  string name;
  while(1){
    cin >> n;
    if(n == 0)return 0;
    if(!isfirst){
      cout << endl;
    }
    for(int i = 0;i < n;i++){
      cin >> team[i];
      cin >> temp;
      point[i] += temp*3;
      cin >> temp;
      cin >> temp;
      point[i] += temp;
    }
    for(int j = 0;j < n;j++){
      for(int i = cur = 0;i < n;i++){
	if(point[i] > point[cur]) cur = i;
      }
      cout << team[cur] << ',' << point[cur] << endl;
      point[cur] = -1;
    }
    for(int i = 0;i < 10;i++){
      point[i] = 0;
    }
    isfirst = false;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

struct hoge {
  int s, n;
  string name;
  hoge(int s,int n, string name) : s(s),n(n),name(name) { }
};
bool operator < (const hoge &a, const hoge &b) {
  return a.s!=b.s ? a.s>b.s : a.n < b.n;
}

int main() {
  int n;
  int f = 0;
  while(cin>>n,n) {
    vector<hoge> v;
    REP(i,n) {
      string name;
      int a,b,c;
      cin >> name;
      cin >> a >> b >> c;
      v.push_back(hoge(a*3+c,i,name));
    }
    sort(ALL(v));
    if (f)
      cout << endl;
    else
      f++;
    FOR(it,v) {
      hoge h=*it;
      cout << h.name << "," << h.s << endl;
    }
  }
}

C++: // 0124
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct team{
	string name;
	int p;
};

int main(){
	while(1){
		int n;
		cin>>n;

		if(n == 0)
			break;

		string str;
		int w, l, d;
		team t;
		vector<team> te;

		for(int i=0;i<n;i++){
			cin>>str>>w>>l>>d;
			t.name = str;
			t.p = 3*w+d;
			te.push_back(t);
		}
		
		for(int i=0;i<te.size();i++){
			for(int j=te.size()-2;j>=i;j--){
				if(te[j].p < te[j+1].p){
					t = te[j];
					te[j] = te[j+1];
					te[j+1] = t;
				}
			}
		}

		for(int i=0;i<n;i++)
			cout<<te[i].name<<","<<te[i].p<<endl;
		
		cout<<endl;
	}
	return 0;
}

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

int main(){
	int n,po;
	int score[10];
	string name[10];
	int d[]={3,0,1};
	while(1){
		cin >> n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin >> name[i];
			score[i] = 0;
			for(int j=0;j<3;j++){
				cin >> po;
				score[i] += po * d[j];
			}
		}
		int top;
		for(int i=0;i<n;i++){
			top = 0;
			for(int j=1;j<n;j++){
				if(score[top]<score[j]){
					top = j;
				}
			}
			cout << name[top] << "," << score[top] << endl;
			score[top] = -1;
		}
	}
}

C++: #include <tuple>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef tuple<string,int> Ttype;

template<int id> class CompTupleBy{
public:
    template<class T>
    bool operator()(const T& a,const T& b) const{
        return get<id>(a) > get<id>(b);
    }
};


int main(){
    int n,w=-1,l,d;
    string s;
    vector<Ttype> v;

    while(cin>>n,n){
        if(w!=-1) cout<<endl;
        for(int i=0;i<n;i++){
            cin>>s>>w>>l>>d;
            cin.ignore();
            v.push_back(Ttype(s,3*w+d));
        }

        stable_sort(v.begin(),v.end(),CompTupleBy<1>());

        for(auto t:v){
            cout<<get<0>(t)<<","<<get<1>(t)<<endl;
        }

        v.clear();
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

int main(void){
  int n, a, b, c;
  string s;
  vector<pair<int, pair<int, string> > > v;

  while(cin >> n, n){
    v.clear();

    for(int i=0; i<n; i++){
      cin >> s >> a >> b >> c;
      v.push_back(make_pair((a * 3) + c, make_pair(n - i, s)));
    }
    sort(v.begin(), v.end(), greater<pair<int, pair<int, string> > >());

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

  return 0;
}