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 <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


int main(){
	int n;
	int a,b,c;
	string s;
	bool f=false;
	while(cin>>n && n>0){
		vector<pair<pii,string> >v(n);
		rep(i,n){
			cin>>s>>a>>b>>c;
			v[i].fi.fi=a*3+c;
			v[i].fi.se=i*(-1);
			v[i].se=s;
		}
		sort(all(v));
		reverse(all(v));
		if(f)cout<<endl;
		f=true;
		rep(i,n){
			cout<<v[i].se<<","<<v[i].fi.fi<<endl;
		}
	}
}

C++: #include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};

int main()
{
	int n;
	while (cin >> n && n)
	{
		vector< pair <int, string> > a;
		for (int i = 0; i < n; i++)
		{
			int p = 0;
			string name;
			cin >> name;
			p += in() * 3; in();
			p += in();

			a.push_back(pair<int, string>(p, name));
		}

		for (int l = 0; l <= n; l++)
		{
			for (int i = 1; i < a.size(); i++)
			{
				if (a[i].first > a[i - 1].first)swap(a[i], a[i - 1]);
			}
		}

		for (int i = 0; i < n; i++)
		{
			cout << a[i].second << "," << a[i].first << endl;
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main(){
	int n;
	bool f=false;
	while(cin>>n){
		if(!n)break;
		multimap<int,string,greater<int> > teams;
		for(int i=0,w,l,d;i<n;++i){
			string team;
			cin>>team>>w>>l>>d;
			teams.insert(multimap<int,string>::value_type(w*3+d,team));
		}
		if(f)cout<<endl;
		f=true;
		for(multimap<int,string>::iterator it=teams.begin();it!=teams.end();++it) cout<<(*it).second<<","<<(*it).first<<"\n";
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,score[1000];
    while(1){
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }
    int max=-10000,count=0,j=0,s;bool bo=false;
    while(1){
        if(count==n){
            break;
        }
        for(int i=0;i<n;i++){
            if(score[i]>max){
                max=score[i];
                s=i;
            }
        }
        cout<<name[s]<<","<<score[s]<<endl;
        count++;
        score[s]=-10;
        max=-10000;
    }
        cout<<endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
	vector<pair<int, string> > team;
	int n, pt[10][3];
	string str[10];

	while(1){
		cin >> n;

		if(n == 0)    break;

		for(int i = 0; i < n; i++)
			cin >> str[i] >> pt[i][0] >> pt[i][1] >> pt[i][2];

		for(int i = 0; i < n; i++)
			team.push_back(make_pair(((pt[i][0] * -3) - pt[i][2]), str[i]));

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

		for(int i = 0; i < n; i++)
			cout << team[i].second << "," << -(team[i].first) << endl;
		
	}

	return 0;
}

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

typedef pair<int, string> c;
vector<c> V;

int main() {
  int N;
  cin >> N;
  while(1) {
    if(N == 0) break;
    for(int i=0;i<N;i++) {
      int win,lose,draw,point;
      string country;
      cin >> country >> win >> lose >> draw;
      point = win * 3 + draw * 1;
      c temp;
      temp.first = point;
      temp.second = country;
      V.push_back(temp);
    }
    stable_sort(V.begin(),V.end(),greater<c>());
    for(int i=0;i<N;i++) {
      cout << V[i].second << "," << V[i].first << endl;
    }
    cin >> N;
    if(N == 0) break;
    else cout << endl;
    V.clear();
  }
}

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

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

int main(){
  int i,j,n,max,k,c=0;
  Team t[10],tmp;
  while(1){
    cin >> n;
    if(n == 0) break;

    if(c != 0) cout << endl;
    c++;

    for(i=0;i<n;i++){
      cin >> t[i].name >> t[i].win >> t[i].lose >> t[i].drow;
      t[i].score = t[i].win * 3 + t[i].drow;
    }

    for(i=0;i<n;i++){
      max = t[i].score;
      for(j=n-1;j>=i;j--){
	if(max <= t[j].score){
	  k = j;
	  max = t[j].score;
	}
      }
      tmp = t[k];
      t[k] = t[i];
      t[i] = tmp;
    }

    for(i=0;i<n;i++) cout << t[i].name << "," << t[i].score << endl;

  }
  return 0;
}

C++: #include<stdio.h>

int main()
{
	int score[11],win,lose,draw,point[11];
	int n,i,j;
	char str[11][21];
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",str[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
			point[i]=score[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]>point[j]){
					point[10]=point[i];
					point[i]=point[j];
					point[j]=point[10];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]==score[j]){
					printf("%s,%d\n",str[j],score[j]);
					score[j]=-1;
					break;
				}
			}
		}
		puts("");
	}
	return 0;
}