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

  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair

int main(){
  pair<int,string> data[10];
  int n,d=0;
  while(cin>>n,n){
    if(d!=0)cout<<endl;
    else d=1;
    REP(i,n){
      string s;
      int a,b,c;
      cin>>s>>a>>b>>c;
      data[i]=MP(a*3+c,s);
    }
    sort(data,data+n);
    for(int i=n-1;i>=0;i--){
      cout<<data[i].second<<","<<data[i].first<<endl;
    }
  }
  
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct DATA{
  string s;
  int score;
};
int main(){
  int n;
  DATA data[10],temp;
  while(cin>> n,n){
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>> data[i].s>> a>> b>> c;
      data[i].score=a*3+c;
    }

    for(int i=0;i<n;i++){
      for(int j=n;j>i;j--){
	if(data[j].score>data[j-1].score){
	  temp=data[j];
	  data[j]=data[j-1];
	  data[j-1]=temp;
	}
      }
    }

    for(int i=0;i<n;i++){
      cout<< data[i].s<< ","<< data[i].score<< endl;
    }
  }
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
pair<int,int> dat[10];
char p[10][21];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			int b,c,d;
			scanf("%s%d%d%d",p[i],&b,&c,&d);
			dat[i]=make_pair(-(b*3+d),i);
		}
		std::sort(dat,dat+a);
		for(int i=0;i<a;i++){
			printf("%s,%d\n",p[dat[i].second],-dat[i].first);
		}
		printf("\n");
	}
}

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;
typedef pair<int,string> P;
int main(){
	int n,x,y,z,now=0;
	priority_queue<P> tab;
	string s;
	while(cin>>n,n){
		if(now!=0)
		cout<<endl;
		rep(i,n){
			cin>>s>>x>>y>>z;
			tab.push(P(x*3+z,s));
		}
		while(!tab.empty()){
			P q=tab.top();
			cout<<q.second<<','<<q.first<<endl;
			tab.pop();
		}
		now++;
	}
	return 0;
}

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

int main() {
	string c;
	int w, l, d;
	int n;
	int x = 0;
	while (cin >> n, n) {
		if (x >= 1) { cout << endl; }
		map<string, int>m;
		map<string, int>::reverse_iterator pm;
		for (int i = 0;i < n;i++) {
			cin >> c >> w >> l >> d;
			m[c] = w * 3 + d;
		}

		pm = m.rbegin();
		while(pm!=m.rend()){
			cout << pm->first << ',' << pm->second << endl;
			pm++;
		}
		x++;
	}
	return 0;
}

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

		for (int i = 0; i < N; i++)
		{
			for (int j = i + 1; j < N; i++)
			{
				if (R[i].first < R[j].first)
				{
					swap(R[i], R[j]);
				}
			}
		}

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

	return 0;
}

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

int N,sum[10],sum2[10];
struct DATA{
	string country;
	int win,lose,drow,sum,flag; 
};
DATA data[10];
int main(void){
	while(1){
		cin>>N;
		if(N==0){break;}
		for(int i=0;i<N;i++){
			cin>>data[i].country>>data[i].win>>data[i].lose>>data[i].drow;
			data[i].sum=data[i].win*3+data[i].drow;
			sum[i]=data[i].sum;
		}
		sort(sum,sum+N);
		for(int i=0;i<N;i++){sum2[i]=sum[N-1-i];}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(sum2[i]==data[j].sum && data[j].flag==0){
					cout<<data[j].country<<","<<data[j].sum<<endl;
					data[j].flag=1;
				}
			}
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		vector <string> team_names(n);
		vector <int> points(n,0);
		vector <int> id(n,0);
		for ( int i = 0; i < n; i++ )
		{
			id[i] = i;
			cin >> team_names[i];
			int point;
			cin >> point;
			points[i] += point * 3;
			cin >> point;
			cin >> point;
			points[i] += point;
		}

		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i + 1; j < n; j++ )
			{
				if ( points[i] < points[j] )
				{
					swap( points[i], points[j] );
					swap( team_names[i], team_names[j] );
					swap( id[i], id[j] );
				}
				else if ( points[i] == points[j] )
				{
					if ( id[i] > id[j] )
					{
						swap( points[i], points[j] );
						swap( team_names[i], team_names[j] );
						swap( id[i], id[j] );
					}
				}
			}
		}

		for ( int i = 0; i < n; i++ )
		{
			cout << team_names[i] << ',' << points[i] << endl;
		}

		cout << endl << endl;

	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, flag = 0;
  while (cin >> n, n) {
    if (flag++) cout << endl;
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    string name[10];
    int w[10], l[10], d[10];
    for (int i = 0; i < n; i++) {
      cin >> name[i] >> w[i] >> l[i] >> d[i];
    }
    stable_sort(ord.begin(), ord.end(), [&](int a, int b) {
      return w[a] * 3 + d[a] > w[b] * 3 + d[b];
    });
    for (int i = 0; i < n; i++) {
      cout << name[ord[i]] << "," << w[ord[i]] * 3 + d[ord[i]] << endl;
    }
  }

  return 0;
}