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<string>
#include<algorithm>
#include<map>

using namespace std;

int main(void){
	while(1){
		int a,n;
		string s;
		multimap<int,string,greater<int>> P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert(pair<int, string>(w*3+d,s));
		}
		multimap<int, string,greater<int>>::iterator it =P.begin();
		while( it !=P.end() ){
			cout << (*it).second << "," << (*it).first << endl;
			++it;
		}

	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

struct Team{
  string name;
  int win,lose,draw;
  int score;
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin>>n&&n){
    vector<Team> v(n);
    rep(i,n){
      cin >> v[i].name >> v[i].win>>v[i].lose >>v[i].draw;
      v[i].score = v[i].win*3 + v[i].draw;
    }
    sort(all(v),[](const Team &a,const Team &b){return a.score>b.score;});
    rep(i,n){
      cout << v[i].name << "," << v[i].score<<endl;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
typedef pair< int , string> P;
//実装案　勝たなかった試合＆負けた試合のベクター　照準ソートして上から
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
bool pairCompare(const P& firstElof, const P& secondElof)
{
  if(firstElof.first!= secondElof.first)    return firstElof.first> secondElof.first;

else return false;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
string k;
bool a=false;
while(1){

  std::cin >> x;
  if(x==0)return 0;
  if(a){
      std::cout << '\n';
  }
  std::vector< pair <int,string> > v(x);
  Rep(j,x){
      std::cin >> k;
    v[j].second=k;
    v[j].first=0;
std::cin >> y>>z>>w;
v[j].first=y*3+w;
    }

  sort(all(v),pairCompare);
  rep(i,x){
    std::cout << v[i].second<<","<<v[i].first<< '\n';
  }
if(!a)a=true;
}
}

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

int main(){
	int n,po;
	int score[10];
	string name[10];
	int d[]={3,0,1};
	int cou=0;
	while(1){
		cin >> n;
		if(n==0) break;
		if(cou != 0) cout << endl;
		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;
		}
		cou++;
	}
}

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

using namespace std;

int main()
{
	int N, C = 0, X, Y, Z;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		if (C++) { cout << endl; }

		vector<pair<int, string> > R(N);

		for (int i = 0; i < N; i++)
		{
			cin >> R[i].second >> X >> Y >> Z;

			R[i].first = X * 3 + Z;
		}

		sort(R.begin(), R.end());

		for (int i = 0; i < N; i++)
		{
			cout << R[i].second << ',' << R[i].first << endl;
		}
	}

	return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
string s[11];
int w[11], l[11], d[11], p[11];
bool used[11];

int main() {
	while (cin >> n&&n) {
		REP(i, n) {
			used[i] = false;
			cin >> s[i] >> w[i] >> l[i] >> d[i];
			p[i] = 3 * w[i] + d[i];
		}
		REP(i, n) {
			int maxp = -2;
			string maxc;
			int maxj = 0;
			REP(j, n) {
				if (maxp < p[j]&&!used[j]) {
					maxp = p[j];
					maxc = s[j];
					maxj = j;
				}
			}
			cout << maxc << "," << maxp << endl;
			used[maxj] = true;
		}
		cout << endl;
	}
}