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<bits/stdc++.h>

using namespace std ;

struct s
{
	int p ;
	string tm ;
} ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int p1 ;
		s st[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> st[ i ].tm >> st[ i ].p >> p1 >> p1 ;
			st[ i ].p = st[ i ].p * 3 + p1 ;
		}

		for( int i = 0 ; i < n ; i++ )
		{
			for( int j = i + 1 ; j < n ; j++ )
			{
				if( st[ i ].p < st[ j ].p )
					swap( st[ i ] ,st[ j ] ) ;
			}
		}

		for( int i = 0 ; i < n ; i++ )
			cout << st[ i ].tm << "," << st[ i ].p << endl ;

	}
	return 0 ;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,string> pii;
int main(){
    int n;
    bool f=false;
    while(cin>>n,n){
        if(f)cout<<endl;
        string str;
        int W,L,D;
        vector<pii>V;
        while(n--){
            cin>>str>>W>>L>>D;
            V.push_back(pii(W*3+D,str));
        }
        stable_sort(V.begin(),V.end(),greater<pii>());
        for(int i=0;i<V.size();i++){
            cout<<V[i].S<<","<<V[i].F<<endl;
        }
        f=true;
    }
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <strstream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;

int main(){
	int n;
	while(cin>>n && n)
	{
		multimap<int,string,greater<int> >m;
		for(int i=0; i<n; i++)
		{
			string t;
			int w,l,d;
			cin>>t>>w>>l>>d;
			m.insert( make_pair( w*3+d , t ) );
		}
		for(multimap< int,string,greater<int> >::iterator it=m.begin(); it != m.end(); it++)
			cout<< (*it).second << ',' << (*it).first << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    bool kawa=0;
    while(cin>>n,n){
        if(kawa)cout<<endl;
        string str[10];
        int num[10];
        for(int i=0,win,lose,draw;i<n;i++){
            cin>>str[i]>>win>>lose>>draw;
            num[i]=win*3+draw;
            str[i]+=',';
        }
        for(int i=0;i<n;i++){
            int ma=0;
            for(int j=0;j<n;j++)if(num[ma]<num[j])ma=j;
            cout<<str[ma]<<num[ma]<<endl;
            num[ma]=-1;
        }
        kawa=1;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

typedef pair<int,string> mypair;

int main(void){

int n, k, m, h;
mypair ch[10];
bool kg=false;
	while(cin >>n){
		if(n==0 || cin.eof()) break;
		rep(i,n){
			cin >> ch[i].second;
			cin >> k >> m >> h;
			ch[i].first = (k *3 + h *1) * 100 + 50- i;
		}
		sort(ch, ch+n, greater<mypair>());
		if(kg) cout << endl;
		kg=true;
		rep(i,n) cout << ch[i].second << "," << (int)(ch[i].first/100) << endl;
		
	}
	return 0;
	
}

C++: #include<iostream>
#include<string>
using namespace std;
string team[10];
int point[10];
int main(){
  int n,temp,cur;
  string name;
  while(1){
    cin >> n;
    if(n == 0)return 0;

    for(int i = 0;i < n;i++){
      cin >> team[i];
      cin >> temp;
      point[i] += temp*3;
      cin >> temp;
      cin >> temp;
      point[i] += temp;
    }
    for(int j = 0;j < n;j++){
      for(int i = cur = 0;i < n;i++){
	if(point[i] > point[cur]) cur = i;
      }
      cout << team[cur] << ',' << point[cur] << endl;
      point[cur] = -1;
    }
    cout  << endl;
    for(int i = 0;i < 10;i++){
      point[i] = 0;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string.h>
#include <string>
#include <functional>
using namespace std;
pair<int,pair<int,string>> team[10];
int main()
{
	int n;
	bool first=true;
	while(cin>>n&&n){
		if(!first)cout<<endl;
		for(int i=0;i<n;i++){
			int k,m,h;
			cin>>team[i].second.second>>k>>m>>h;
			team[i].first=k*3+h;
			team[i].second.first=-i;
		}
		sort(team,team+n,greater<pair<int,pair<int,string>>>());
		for(int i=0;i<n;i++){
			cout<<team[i].second.second<<","<<team[i].first<<endl;
		}
		first=false;
	}
    return 0;
}

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

using namespace std ;

struct s
{
	int p ;
	string tm ;
} ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int p1,a ;
		s st[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> st[ i ].tm >> st[ i ].p >> a >> p1 ;
			st[ i ].p = st[ i ].p * 3 + p1 ;
		}

		for( int i = 0 ; i < n ; i++ )
		{
			for( int j = i + 1 ; j < n ; j++ )
			{
				if( st[ i ].p < st[ j ].p )
					swap( st[ i ] ,st[ j ] ) ;
			}
		}

		for( int i = 0 ; i < n ; i++ )
			cout << st[ i ].tm << "," << st[ i ].p << endl ;

	}
	return 0 ;
}