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 <iterator>
#include <map>
#include <vector>
#include <functional>
#include <list>


using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

int main(void){
	bool b=false;
	while(1){
		int a,n;
		string s;
		multimap<int, string, greater<int> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		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).first << "," << (*it).second << endl;
			++it;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int main(){
    int n,l=0;
    while(cin>>n,n){
        if(l)cout<<endl;l++;
        map<int,vector<string> >m;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            m[3*a+c].push_back(s);
        }
        for (map<int,vector<string> >::reverse_iterator it=m.rbegin(); it!=m.rend(); ++it){
            vector<string>v=it->second;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<","<<it->first<<endl;
            }
        }
    }
}

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

typedef struct{
  string team;
  int win;
  int lose;
  int drow;
  int point;
}much;
  
int main(){
  while(1){
  much x[11],smp;
  int n;
  cin >> n;
  if(n == 0)break;
  for(int i=0;i<n;i++){
    cin >> x[i].team >> x[i].win >> x[i].lose >> x[i].drow;
  }
  for(int i=0;i<n;i++){
    x[i].point = x[i].win*3 + x[i].drow;
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(x[i].point < x[j].point){
	smp = x[i];
	x[i] = x[j];
	x[j] = smp;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << x[i].team << "," << x[i].point << endl <<endl;;
  }
}
}

C++: #include<iostream>
#include<algorithm>

using namespace std ;

typedef pair< int ,string > pay ;

int main()
{
	int n ,dr ;
	while( cin >> n ,n )
	{
		pay p[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> p[ i ].second >> p[ i ].first >> dr >> dr ;
			p[ i ].first = p[ i ].first * 3 + dr ;
		}

		sort( p ,p + n ) ;

		for( int i = n - 1 ; i >= 0 ; i-- )
			cout << p[ i ].second << "," << p[ i ].first << endl ;
	}
	return 0 ;
}

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

using namespace std;

int main()
{
	vector<pair<int, 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]), make_pair(i, str[i])));

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

		cout << endl;

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

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j;
	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-1;i++){
			for(j=n-1;j>i;j--){
				if(data[j]>data[j-1]){
					temp=data[j];
					data[j]=data[j-1];
					data[j-1]=temp;
					strcpy(temps,tn[j]);
					strcpy(tn[j],tn[j-1]);
					strcpy(tn[j-1],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 <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	bool f=false;
	while(cin>>n){
		if(!n)break;
		if(f)cout<<endl;
		f=true;
		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,team));
		}
		stable_sort(teams.begin(),teams.end());
		for(vector<pair<int,string> >::reverse_iterator it=teams.rbegin();it!=teams.rend();++it) cout<<(*it).second<<","<<(*it).first<<"\n";
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j;
	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=n;j>=i+1;j--){
				if(data[j]>data[j-1]){
					temp=data[j];
					data[j]=data[j-1];
					data[j-1]=temp;
					strcpy(temps,tn[j]);
					strcpy(tn[j],tn[j-1]);
					strcpy(tn[j-1],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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.LMSS", "r", stdin );
	string str = "";
	int i, n;
	vector <multimap <int, string > > res;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if

		multimap <int, string> rank;

		for (i = 0; i < n; ++i){
			string team;
			int win, lose, draw;
			getline (cin, str );
			stringstream ss(str);
			ss >> team >> win >> lose >> draw;
			int point = 3*win + draw;
			rank.insert (make_pair (-point, team ) );
		} // end for
		res.push_back (rank );		
	} // end loop
	int size = res.size();
	
	for (i = 0; i < size; ++i){
		multimap <int, string>::iterator it = res[i].begin();
		for (; it != res[i].end(); ++it ){
			int point = -(*it).first;
			string team = (*it).second;
			cout << team << ',' << point << endl;
		} // end for
		if (i != size - 1){
			cout << endl;
		} // end if
	} // end for
		
	return 0;
}