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 <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(!n)break;
		vector<pair<int,string> > teams;
		for(int i=0,w,l,d;i<n;++i){
			string team;
			cin>>team>>w>>l>>d;
			teams.push_back(make_pair(w*3+d*1,team));
		}
		stable_sort(teams.begin(),teams.end());
		for(vector<pair<int,string> >::reverse_iterator it=teams.rbegin();it!=teams.rend();++it) printf("%s,%d\n",(*it).second.c_str(),(*it).first);
		cout<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
typedef struct{
  string first;
  int score,num;
} team;
int main(){
  int n,a,b,c,k=-1,nn[51];
  team t[51][11];
  cin >> n;
  while(n != 0){
    k++;
    nn[k] = n;
    for(int i=0;i<n;i++){
      cin >> t[k][i].first >> a >> b >> c;
      t[k][i].score = a*3+c;
      t[k][i].num = i;
    }
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	if(t[k][i].score < t[k][j].score){
	  team temp = t[k][i];
	  t[k][i] = t[k][j];
	  t[k][j] = temp;
	} else if(t[k][i].score == t[k][j].score && t[k][i].num > t[k][j].num){
	  team temp = t[k][i];
	  t[k][i] = t[k][j];
	  t[k][j] = temp;
	}
      }
    }
    cin >> n;
  }
  for(int j=0;j<=k;j++){
    for(int i=0;i<nn[j];i++){
      cout << t[j][i].first << ',' << t[j][i].score << endl;
    }
    if(j != k) cout << endl;
  }
  return (0);
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int main(){
  int n;
  while(cin>>n,n){
    vector<pair<int,string>> P;
    int w,l,d;
    string s;
    rep(i,n){
      cin>>s>>w>>l>>d;
      P.pb(mp(3*w+d,s));
    }
    sort(all(P));
    for(int i=P.size()-1;i>=0;i--){
        cout<<P[i].sec<<','<<P[i].fir<<endl;
    }
  }
  return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  int n;
  vs out;
  while (cin >> n, n) {
    vector<pair<int, string>> v;
    while (n--) {
      string name;
      int w, l, d;
      cin >> name >> w >> l >> d;
      v.emplace_back(w * 3 + d, name);
    }
    stable_sort(rall(v));
    ostringstream ss;
    for (auto &x : v) ss << x.se << ',' << x.fi << endl;
    out.pb(ss.str());
  }
  cout << join(out, "\n");
}

C++: #include<iostream>
#include<string>
using namespace std;
string s[1000000];
int a[1000000][3], score[1000000];
int n;
int main() {
	while (true) {
		cin >> n;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> s[i] >> a[i][0] >> a[i][1] >> a[i][2];
			score[i] = a[i][0] * 3 + a[i][2];
		}
		for (int j = 100000; j >= 0; j--) {
			for (int k = 0; k < n; k++) {
				if (score[k] == j) {
					cout << s[k] << ',' << score[k] << endl;
				}
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
using namespace std;
int main() {
	int n, i, j, k;
	int z = 0;
	while (1) {
		cin >> n;
		if (n == 0) break;
		vector < pair < int,string  > > x(n);
		for (int q = 0; q < n; q++) {
			cin >> x[q].second;
			cin >> i >> j >> k;
			x[q].first = 3 * i + k;
		}
		for (int w = 0; w < n; w++) {
			for (int q = 0; q+1 < n; q++) {
				if (x[q].first < x[q + 1].first) {
					swap(x[q], x[q + 1]);
				}
			}
		}
		for (int q = 0; q < n; q++) {
			if (q == 0) {
				if (z != 0)	cout << endl;
			}
			cout << x[q].second << ',' << x[q].first << endl;
			z = 1;
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j,flg=0;
	int temp,data[10];
	char tn[11][21],temps[21];
	int k,m,h;
	scanf("%d" ,&n);
	while(n!=0){
		for(j=0;j<10;j++){
			data[j]=0;
		}
		for(j=0;j<n;j++){
			scanf("%s %d %d %d",tn[j],&k,&m,&h);
			data[j]+=k*3;
			data[j]+=h;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(data[j]<data[j+1]){
					temp=data[j+1];
					data[j+1]=data[j];
					data[j]=temp;
					strcpy(temps,tn[j+1]);
					strcpy(tn[j+1],tn[j]);
					strcpy(tn[j],temps);
				}
			}
		}
		for(j=0;j<n;j++){
			printf("%s,%d\n",tn[j],data[j]);
		}
		scanf("%d",&n);
		if(n!=0){
			printf("\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
string str[10];
P t[10];
int n=-1,a,b,c;
int main(){
  cin>>n;
  while(1){
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str[i]>>a>>b>>c;
      t[i].first=(a*3+c)*-1;
      t[i].second=i;
    }
    sort(t,t+n);
     
    for(int i=0;i<n;i++){
      cout<<str[t[i].second]<<','<<t[i].first*-1<<endl;
    }
    cin>>n;
    if(n==0)break;
    cout<<endl;
  }
  return 0;
}