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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>


using namespace std;

struct country_point{
    string country;
    int num;
    int point;
};

bool country_point_compare(country_point l, country_point r){
    if(l.point>r.point)return true;
    if(l.point<r.point)return false;
    if(l.num>r.num)return true;
    return false;
}

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        country_point all_country[10];
        for(int i=0; i<n; i++){
            string c;
            cin>>c;
            all_country[i].country = c;
            int win, loss, drow;
            cin>>win;
            all_country[i].point=win*3;
            cin>>loss;
            cin>>drow;
            all_country[i].point+=drow;
            all_country[i].num = i;
        }
        
        sort(all_country, all_country+n, country_point_compare);
        
        for(int i=0; i<n; i++){
            cout<<all_country[i].country<<","<<all_country[i].point<<endl;
        }
        cout<<endl;
    }
    
}

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

using namespace std;

struct country {
  string name;
  int score;
  bool operator < (const country &c) const {
    return score > c.score;
  }
};

int main() {
  int n;
  bool ok = 0;
  while(cin >> n && n) {
    if(ok) cout << endl;
    ok = 1;
    country team[10];
    for(int i=0; i<n; i++) {
      string s; int win, lose, draw;
      cin >> s >> win >> lose >> draw;
      team[i].name = s;
      team[i].score = win*3 + draw*1;
    }
    
    sort(team, team+n);
    
    for(int i=0; i<n; i++) {
      cout << team[i].name << ',' << team[i].score << endl;
    }
  }
  
  return 0;
}

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

using namespace std;

class Team{
public:
	string name;
	int point;
	int pos;
	
	bool operator <(const Team arg) const{
		if(point > arg.point){
			return true;
		}else if(point < arg.point){
			return false;
		}else{
			if(pos < arg.pos){
				return true;
			}else{
				return false;
			}
		}
	}
};

int main(void){
	int n;
	vector<Team> v;
	Team t;
	bool first = true;
	
	while(cin >> n && n){
		string str;
		int w,l,d;
		
		if(!first) cout << endl;
		
		for(int i=0;i<n;i++){
			cin >> str >> w >> l >> d;
			t.name = str;
			t.point = w*3+d;
			t.pos = i;
			v.push_back(t);
		}
	
		sort(v.begin(),v.end());
		
		for(int i=0;i<n;i++){
			cout << v[i].name << "," << v[i].point << endl;
		}
		first = false;
		v.clear();
	}
}

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

int main() {
  int n,f=0;
  while(cin>>n, n) {
    if(f) cout<<endl;
    vector< pair<int, string> > v;
    string s;
    int a,b,c;
    for(int i=0; i<n; ++i) {
      cin>>s>>a>>b>>c;
      v.push_back( pair<int,string>(a*3+c,s) );
    }

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

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

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>

using namespace std;

void Solution()
{
    int n, flag = 0;
    
    while(cin>>n, n)
    {
        if(flag)
        {
            cout<<endl;
        }
        
        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;
                    
                    /*swap the team name and score*/
 
                    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;
        }
        
        flag = 1;
    }
}

int main()
{
    Solution();
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXP = 31;

int main()
{
    string s;
    int n, w, l, e;
    bool sec = false;
    while(cin >> n && n)
    {
        if(sec) cout << endl;
        vector<string> teams[MAXP];
        
        REP(n)
        {
            cin >> s >> w >> l >> e;
            teams[w * 3 + e].push_back(s);
        }
        
        for(int i = MAXP-1;i!= 0; i--)rep(j,teams[i].size())
            cout << teams[i][j] << "," << i << endl;
        
        sec = true;

    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int cnt=0;
  string a[50][50][10];
  for(int i=0;i<50;i++)
    for(int j=0;j<50;j++)
      for(int k=0;k<10;k++)
	a[i][j][k]="";
  while(cin>>n,n!=0){
    //    vector<pair<string,int> > s;
    vector<vector<string> > anspo(50);
    for(int i=0;i<n;i++){
      string str;cin>>str;
      int w,l,d;cin>>w>>l>>d;
      //s.push_back(make_pair(str,w*3+d));
      anspo[w*3+d].push_back(str);
    }
    for(int i=49;i>=0;i--){
      for(int j=0;j<anspo[i].size();j++){
	a[cnt][i][j]=anspo[i][j];
      }
    }
    cnt++;
  }
  for(int i=0;i<cnt;i++){
    for(int j=49;j>=0;j--){
      for(int k=0;k<10;k++){
	if(a[i][j][k]!="")
	  cout<<a[i][j][k]<<","<<j<<endl;
      }
    }
    if(i!=cnt-1)
      cout<<endl;
  }
  return 0;
}