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<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    bool flg = 0;
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        if(flg == 1) cout << endl;
        char team[20][100] = {0};
        int ten[20] = {0};
        int score[20] = {0};
        for(int i = 0; i < n; i++){
            getchar();
            scanf("%s",team[i]);
            int a,b,c;
            cin >> a >> b >> c;
            ten[i] = 3 * a + c;
            score[i] = ten[i];
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(ten[i] > ten[j]){
                    swap(ten[i],ten[j]);
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(ten[i] == score[j]){
                    cout << team[j] << ',' <<  score[j] << endl;
                    score[j] = -1;
                }
            }
        }

        flg = 1;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)

bool cmp(pair<int,string> a , pair<int,string> b){
	return a.first > b.first;
}
int main(){
	int n,c=0;
	while(cin >> n,n){
		if(c++)cout << endl;
		vector< pair<int,string> >data; 
		rep(i,n){
			int a,b,c;
			string s;
			cin >> s >>  a >> b >> c;
			data.push_back(make_pair(a*3+c,s));
		}
		stable_sort(data.begin(),data.end(),cmp);
		rep(i,n)
			cout << data[i].second << "," << data[i].first << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <strstream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;

int main(){
	int n;
	while(cin>>n)
	{
		multimap<int,string,greater<int> >m;
		for(int i=0; i<n; i++)
		{
			string t;
			int w,l,d;
			cin>>t>>w>>l>>d;
			m.insert( make_pair( w*2+d , t ) );
		}
		for(multimap< int,string,greater<int> >::iterator it=m.begin(); it != m.end(); it++)
			cout<< (*it).second << ',' << (*it).first << endl;
	}
	return 0;
}

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

using namespace std;
typedef pair<int, string> P;

void solve()
{
	bool first = true;
	int n;
	while(cin >> n, n)
	{
		vector<P> data;
		set<int> point;
		for(int i = 0; i < n; ++i)
		{
			string str;
			cin >> str;
			int a, b, c;
			cin >> a >> b >> c;
			int sum = 0;
			sum += a * 3 + c;
			data.push_back(P(sum, str));
			point.insert(sum);
		}
		if(!first)
		{
			cout << endl;
		}
		first = false;
		set<int>::reverse_iterator rit = point.rbegin();
		int pos = 0;
		while(rit != point.rend())
		{
			for(int i = 0; i < n; ++i)
			{
				if(*rit == data[i].first)
				{
					cout << data[i].second << "," << data[i].first << endl;
				}
			}
			++rit;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pint pair<string, int>
bool desc(pint a, pint b) {
	return a.second > b.second;
}
int main() {
	int n;
	while(cin >> n, n) {
		vector<pint> v;
		rep(i,n) {
			string t;
			int tmp, s = 0;
			cin >> t;
			cin >> tmp;
			s += tmp * 3;
			cin >> tmp;
			cin >> tmp;
			s += tmp;
			v.push_back(make_pair(t,s));
		}
		sort(v.begin(), v.end(), desc);
		for(pint p : v) {
			cout << p.first << "," << p.second << endl;
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef struct {
	int sum;
	char name[30];
} TEAM;

int main()
{
	int n;
	int win, lose, drow;
	bool flg = false;
	TEAM team[10], tmp;

	while (1){
		scanf("%d", &n);

		if (n == 0){
			break;
		}

		for (int i = 0; i < n; i++){
			scanf("%s %d %d %d", team[i].name, &win, &lose, &drow);
			team[i].sum = win * 3 + drow;
		}

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (team[j].sum > team[j - 1].sum){
					tmp = team[j - 1];
					team[j - 1] = team[j];
					team[j] = tmp;
				}
			}
		}

		if (flg == true){
			cout << endl;
		}
		
		flg = true;

		for (int i = 0; i < n; i++){
			cout << team[i].name << "," << team[i].sum << endl;
		}
	}

	return (0);
}

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

int main() {
  int n, cnt = 0;
  while(cin >> n, n) {
    if(cnt++ != 0) cout << endl;
    vector<pair<string, int>> p(n);
    for(int i = 0; i < n; i++) {
      string s;
      int w, l, d;
      cin >> s >> w >> l >> d;
      p[i].first = s, p[i].second = w*3 + d;
    }

    for(int i = 0; i < n; i++) {
      int max = 0;
      for(int j = 0; j < n; j++) {
	if(p[j].second > max) max = p[j].second;
      }

      for(int j = 0; j < n; j++) {
	if(p[j].second == max) {
	  cout << p[j].first << ',' << p[j].second << endl;
	  p[j].second = -1;
	}
      }
    }
  }
}

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

int main(){
  int a,b,n,f=0;
  string s;
  for(;cin>>n,n;){
    if(f)cout<<endl;
    vector<pair<int,string> >v;
    for(f=0;f<n;v.push_back(make_pair(a*3+b,s)),f++)
      cin>>s>>a>>b>>b;
    for(a=0;a<n;a++)
      for(b=0;b<n-1;b++)
        if(v[b].first<v[b+1].first)iter_swap(v.begin()+b,v.begin()+b+1);
    for(a=0;a<n;a++)
      cout<<v[a].second<<','<<v[a].first<<endl;
    f=1;
  }
}

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


struct S{
	string name;
	int point;
	bool operator<(const S& a)const{return point>a.point;}
}s[10];

int main(){
	int n;
	if(!(cin>>n&&n))return 0;
	while(1){
		for(int i=0;i<n;i++){
			cin>>s[i].name;
			int a,b,c;
			cin>>a>>b>>c;
			s[i].point=a*3+c;
		}
		stable_sort(s,s+n);
		for(int i=0;i<n;i++){
			cout<<s[i].name<<','<<s[i].point<<endl;
		}
		if(cin>>n&&n)cout<<endl;
		else break;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;

typedef pair<string,int> P; 
bool cmp(const P &p,const P &q){
  return p.S > q.S;
}

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

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