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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct Team{
    string name;
    int id;
    int point;
    bool operator <(const Team& r) const{
        return point == r.point ? id < r.id : point > r.point;
    }
};


int main(){
    vector< Team > v(10);
    string name;
    int n, a, b, c, i = 0;
    while(cin >> n, n){
        if(i) cout << endl;
        for(i = 0; i < n; i++){
            cin >> name >> a >> b >> c;
            v[i].id = i;
            v[i].name = name;
            v[i].point = a * 3 + c;
        }
        sort(v.begin(), v.end());
        for(i = 0; i < n; i++){
            cout << v[i].name << "," << v[i].point << endl;
        }
    }
    return 0;
}

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

using namespace std;

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

int main(void){
	while(1){
		int a,n;
		string s;
		vector< pair<int,string> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.push_back(make_pair(w*3+d,s));
		}
		stable_sort(P.begin(),P.end(),cmp);
		for(a=0;a<n;a++){
			cout << P[a].second << "," << P[a].first << endl; 
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

typedef struct{
  string name;
  int sum;
}TEAM;

int main(){
  int rev = 0;
  int num;
  while(cin >> num && num){
    //if(rev) cout << endl;
    rev++;
    int win, lose, draw;
    TEAM team[num];
    for(int i = 0; i < num; i++){
      cin >> team[i].name >> win >> lose >> draw;
      team[i].sum = win*3 + draw;
    }
    for(int i = 0; i < num-1; i++){
      for(int j = i+1; j < num; j++){
	if(team[i].sum < team[j].sum){
	  TEAM tmp = team[i];
	  team[i] = team[j];
	  team[j] = tmp;
	}
      }
    }
    for(int i = 0; i < num; i++){
      cout << team[i].name <<"," << team[i].sum<<endl << endl;
    }
  }
  return 0;
}

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

C++: #include <iostream>
using namespace std;
 
struct data{
 
char name;
int win;
int lose;
int draw;
int score;
 
};
 
int main(){
 
int teamamo;
 
while(true){
 
cin>>teamamo;
 
if(teamamo==0)
break;
 
data teamdata[10];
data comp;
 
for(int i=0; i<teamamo; i++)
cin>>teamdata[i].name>>teamdata[i].win>>teamdata[i].lose>>teamdata[i].draw;
 
for(int i=0; i<teamamo; i++)
teamdata[i].score=teamdata[i].win*3+teamdata[i].draw;
 
for(int i=0; i<teamamo-1; i++){
 
if(teamdata[i].score<teamdata[i+1]){
 
char fout; 
fout=teamdata[i].name;
teamdata[i].name=teamdata[i+1].name;
teamdata[i+1].name=fout;
 
int gout;
gout=teamdata[i].win;
teamdata[i].win=teamdata[i+1].win;
teamdata[i+1].win=gout;
 
gout=teamdata[i].lose;
teamdata[i].lose=teamdata[i+1].lose;
teamdata[i+1].lose=gout;
 
gout=teamdata[i].draw;
teamdata[i].draw=teamdata[i+1].draw;
teamdata[i+1].draw=gout;
 
gout=teamdata[i].score;
teamdata[i].score=teamdata[i+1].score;
teamdata[i+1].score=gout;
 
    }
 
 
   }
 
for(int i=0; i<teamamo; i++)
cout<<teamdata[i].name<<','<<teamdata[i].score<<endl;
 
 
 }
 
return 0;
 
}

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

using namespace std ;

typedef pair< int ,string > pay ;

int main()
{
	int n ,dr ;
	cin >> n ;
	while( 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 ;
		if( cin >> n )
			cout << endl ;
	}
	return 0 ;
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pint pair<string, int>
bool desc(pint a, pint b) {
	return a.second > b.second;
}
int main() {
	int n;
	while(cin >> n, n) {
		vector<pint> v;
		rep(i,n) {
			string t;
			int tmp, s = 0;
			cin >> t;
			cin >> tmp;
			s += tmp * 3;
			cin >> tmp;
			cin >> tmp;
			s += tmp;
			v.push_back(make_pair(t,s));
		}
		sort(v.begin(), v.end(), desc);
		for(pint p : v) {
			cout << p.first << "," << p.second << endl;
			cout << endl;
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define REP(i,a,n) for(ll i=n;i>a;i--)

int main(void){
    string name[10] = {};
    ll w[10] = {},l[10] = {},d[10] = {},score[10] = {};
    bool is_used[10] = {false};
    bool temp = false;
    
    while(1){
        ll n = 0;
        cin >> n;
        if(!n) break;
        if(temp)cout << endl;
        
        rep(i,0,10){
            is_used[i] = false;
            score[i] = -1;
        }
        
        rep(i,0,n){
            cin >> name[i] >> w[i] >> l[i] >> d[i];
            score[i] = w[i] * 3 + d[i];
        }
        
        
        rep(i,0,101){
            rep(j,0,n){
                if(score[j] == 100 - i) cout << name[j] << "," << score[j] << endl;
            }

        }
        temp = true;
    }
    
}