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

int n;
std::multimap<int, std::string, std::greater<int> > m;

int main()
{
	bool fst = true;

	while( std::cin >> n, n )
	{
		m.clear();

		for( int i = 0; i != n; ++i )
		{
			std::string s;
			int a, b, c;
			std::cin >> s >> a >> b >> c;
			
			m.insert( std::make_pair( a * 3 + c, s ) );
		}

		if( !fst )
			std::cout << std::endl;
		for( auto it = m.begin(); it != m.end(); ++it )
			std::cout << it->second << ',' << it->first << std::endl;
	
		fst = false;
	}

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	string team[10];
	int tokuten[10][4];
	string kari;
	int karikari;
	int counter = 0;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		if (counter != 0) {
			cout << endl;
		}
		for (int i = 0; i < n; i++) {
			cin >> team[i] >> tokuten[i][0] >> tokuten[i][1] >> tokuten[i][2];
			tokuten[i][3] = 3 * tokuten[i][0] + tokuten[i][2];
		}

		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (tokuten[j][3] < tokuten[j+1][3]) {
					kari = team[j];
					team[j] = team[j+1];
					team[j+1] = kari;
					karikari = tokuten[j][3];
					tokuten[j][3] = tokuten[j+1][3];
					tokuten[j+1][3] = karikari;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			cout << team[i] << "," << tokuten[i][3] << endl;
		}
		counter = 1;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>

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

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

int main(){

  int n;

  while(cin >> n, n){

    int a,b,c,z[100],tmp;
    string s[100],tmp2;

    for(int i=0;i<n;i++){
      cin >> s[i] >> a >> b >> c;

      z[i] = a * 3 + c;
    }

    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(z[j] > z[j - 1]){

	  tmp = z[j];
	  z[j] = z[j - 1];
	  z[j - 1] = tmp;

	  tmp2 = s[j];
	  s[j] = s[j - 1];
	  s[j - 1] = tmp2;
	}
      }
    }

    for(int i=0;i<n;i++) cout << s[i] << "," << z[i] << endl;
    cout << endl;

  }
}

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

void bubbleSort( int* a, string* b, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
        {
            if( a[j-1] < a[j] )
            {
                int temp = a[j-1];
                a[j-1] = a[j];
                a[j] = temp;

                string temp2 = b[j-1];
                b[j-1] = b[j];
                b[j] = temp2;
            }
        }

}

int main()
{   
    int n, a[10], b, c, cnt = 0;
    string s[10];

    while( cin >> n )
    {
        if( n == 0 )
            break;
        if( cnt != 0 )
            cout << endl;
        cnt++;
        for( int i = 0; i < n; i++ )
        {
            cin >> s[i] >> a[i] >> b >> c;
            a[i] = a[i] * 3 + c;
        }
        bubbleSort( a, s, n );
        for( int i = 0; i < n; i++ )
            cout << s[i] << ',' << a[i] << endl;
    }

    return 0;
}

C++: #include <iostream>
#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])));
		
		cout << endl;
		
		sort(team.begin(), team.end());
		
		for(int i = 0; i < n; i++)
			cout << team[i].second.second << "," << -(team[i].first) << endl;
		
		cout << endl
		
		team.clear();
	}

	return 0;
}

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

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

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;
	for(j=0;j<10;j++){
		data[j]=0;
	}
	while(scanf("%d",&n)!=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]);
		}
		printf("\n");
	}
	return 0;
}

C++: #include <iostream>
#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());

		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<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;
    while(cin>>n,n){
        priority_queue<pair<int,string>, vector<pair<int,string> >, less<pair<int,string> > >p;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            p.push(make_pair(3*a+c, s));
        }
        while(p.size()){
            pair<int,string>r=p.top();
            p.pop();
            cout<<r.second<<","<<r.first<<endl;
        }
        cout<<endl;
    }
}