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<complex>
#include<cstring>
#include<sstream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<vector>
#include<string>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<functional>
#include<algorithm>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
struct P{
	int v;
	string r;
};

void swap(P *x,P *y){
	string s=x->r;
	int temp=x->v;
	x->r=y->r;
	x->v=y->v;
	y->r=s;
	y->v=temp;
};
int main(){
	int n,x,y,z,now=0;
	string s;
	while(cin>>n,n){
		P tab[20];
		if(now!=0)
		cout<<endl;
		rep(i,n){
			cin>>tab[i].r>>x>>y>>z;
			tab[i].v=x*3+z;
		}
		rep(i,n-1)
			rep(j,n-1){
				if(tab[j].v<tab[j+1].v)
				swap(&tab[j],&tab[j+1]);
		}
		rep(i,n)
			cout<<tab[i].r<<','<<tab[i].v<<endl;
		now++;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )
#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = (c).begin(); it != (c).end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define PB( n ) push_back( ( n ) )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define fst first
#define snd second

const double p500[] = { 70, 55, 50, 43, 40, 37.5, 35.5 };
const double p1000[] = { 148, 116, 105, 89, 83, 77, 71 };
const string rank[] = {	"NA", "E", "D", "C", "B", "A",	"AA", "AAA" };

struct Team
{
	string name;
	int point;

	Team( string name, int point )
	{
		this -> name = name;
		this -> point = point;

		return;
	}

	bool operator < ( const Team &a ) const
	{
		return point > a.point;
	}
};

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

		if ( n == 0 )
		{
			break;
		}

		vector<Team> teams;

		REP( i, 0, n )
		{
			string name;
			int a, b, c;

			cin >> name >> a >> b >> c;

			teams.PB( Team( name, a * 3 + c ) );
		}

		stable_sort( ALL( teams ) );

		REP( i, 0, n )
		{
			cout << teams[i].name << ',' << teams[i].point << endl;
		}
		cout << endl;
	}

	return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	bool first=true;
	while(cin>>n,n){
		if(!first) cout<<endl;
		first=false;
		vector<pair<pii, string>> v(n);
		rep(i,n){
			string s;
			cin>>s;
			int a,b,c;
			cin>>a>>b>>c;
			v[i] = mkp(pii(-a*3-c,-i),s);
		}
		sort(ALL(v));
		rep(i,n){
			cout<<v[i].S<<","<<-v[i].F.F<<endl;
		}
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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;

  bool flag = false;
  while(cin >> n, n){
    v.clear();
    if(flag)
      cout << endl;
    else
      flag = true;

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

  return 0;
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a, b, c, d; pair<int, string> p[10];
int main() {
	while(scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) {
			cin >> p[i].second >> a >> b >> c;
			p[i].first = i - a * 30 - c * 10;
		}
		sort(p, p + n);
		if(d++) printf("\n");
		for(int i = 0; i < n; i++) {
			cout << p[i].second << ',' << (-p[i].first + 9) / 10 << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

struct league{
	string name;
	int win,lose,draw,point;	
};

int main(){
	int n,cnt=0;
	while(cin>>n,n){
		if(cnt>0)cout<<endl;
		league inp[n],alt;
		string s;
		int w,l,d;
		rep(i,n){
			cin>>s>>w>>l>>d;
			inp[i].name=s;
			inp[i].win=w;
			inp[i].lose=l;
			inp[i].draw=d;
			inp[i].point=inp[i].win*3+inp[i].draw;
		}
		rep(i,n){
			for(int j=n-2;j>=i;j--){
				if(inp[j+1].point>inp[j].point){
					alt=inp[j+1];
					inp[j+1]=inp[j];
					inp[j]=alt;
				}
			}
		}
		rep(i,n){
			cout<<inp[i].name<<","<<inp[i].point<<endl;
		}
		cnt++;
	}
	return 0;
}