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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    int hoge=0;
    while(cin>>n,n){
        if(hoge++)cout<<endl;
        vector<pii>v;
        vector<string>amausa;
        rep(i,n){
            int gotiusa=0;
            string rabit; cin>>rabit;
            amausa.push_back(rabit);
            int kokoa,rize,tino; cin>>kokoa>>rize>>tino;
            gotiusa+=kokoa*3+tino;
            v.push_back(pii(gotiusa,-i));
        }
        sort(all(v),greater<pii>());
        rep(i,n)cout<<amausa[-1*v[i].second]<<","<<v[i].first<<endl;
    }
}

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])));
		
		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>
using namespace std;

typedef struct{
	string name;
	int score;
}Team;

int main(void){
	int n;
	bool firstFlg = true;
	
	while(cin>>n && n){
		if(!firstFlg) cout<<endl;
		else firstFlg = false;
	
		Team t[n];
		for(int i=0;i<n;i++){
			int win,lose,draw;
			
			cin>>t[i].name>>win>>lose>>draw;
			t[i].score = win*3 + draw;
		}
		
		for(int i=0;i<n-1;i++){
			for(int j=i;j<n-1;j++){
				if(t[j].score < t[j+1].score){
					Team tmp = t[j];
					t[j] = t[j+1];
					t[j+1] = tmp;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			cout<<t[i].name<<","<<t[i].score<<endl;
		}
	}

	return 0;
}

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

struct Team{
  string name;
  int win,lose,drow,score,zyun;
};

int main(){
  int i,j,n,max,k,c=0,z;
  Team t[11],tmp;
  while(1){
    cin >> n;
    if(n == 0) break;

    if(c != 0) cout << endl;
    c = 1;

    for(i=0;i<n;i++){
      cin >> t[i].name >> t[i].win >> t[i].lose >> t[i].drow;
      t[i].score = t[i].win * 3 + t[i].drow;
      t[i].zyun = i;
    }

    for(i=0;i<n;i++){
      max = t[i].score;
      for(j=i;j<n;j++){
	if(max < t[j].score) max = t[j].score;
      }
      z = n;
      for(j=i;j<n;j++){
	if(max == t[j].score && z > t[j].zyun){
	  z = t[j].zyun;
	  k = j;
	}
      }
      tmp = t[k];
      t[k] = t[i];
      t[i] = tmp;
    }

    for(i=0;i<n;i++) cout << t[i].name << "," << t[i].score << endl;

  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;
typedef pair<int,string> P;

int main(){
    int n,w=-1,l,d;
    string s;
    priority_queue<P> que;

    while(cin>>n,n){
        if(w!=-1) cout<<endl;
        for(int i=0;i<n;i++){
            cin>>s>>w>>l>>d;
            que.push(P(3*w+d,s));
        }

        while(!que.empty()){
            P p=que.top();que.pop();
            cout<<p.second<<","<<p.first<<endl;
        }
    }

    return 0;
}

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


int main(void){
	int n;
	int cnt = 0;
	while(cin>>n,n){
		if(cnt++)cout<<endl;
		string name[n];
		int sum[n],point;
		int rank[n];
		for(int i = 0 ; i < n ; i ++){
			cin>>name[i];
			cin>>point; //win
			sum[i]=point*3;
			cin>>point;	//lose;
			cin>>point; //drow
			sum[i]+=point;
			rank[i]=i;			
		}
		for(int i = 0 ; i < n ; i ++)
			for(int j = 0 ; j < n ; j ++){
				if(sum[rank[i]]>sum[rank[j]]){
					int t = rank[i];
					rank[i] = rank[j];
					rank[j] = t;
				}
			}
		for(int i = 0 ; i < n ; i ++)
			cout<<name[rank[i]]<<","<<sum[rank[i]]<<endl;
		
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
struct data{
    string str;
    int n,p;
    data(string s,int a,int b){
        str=s;n=a;p=b;
    }
    data(){}

    bool operator>(const data &d)const{
        if(p!=d.p)return (p>d.p);
        else return (n<d.n);
    }
};
int main(){
    int n;
    bool flag=false;
    while(cin>>n,n){
        if(flag)cout<<endl;
        vector<data>V(n);
        for(int i=0;i<n;i++){
            string str;
            int w,l,d;
            cin>>str>>w>>l>>d;
            V[i]=data(str,i,w*3+d);
        }
        sort(V.begin(),V.end(),greater<data>());
        for(int i=0;i<n;i++){
            data d=V[i];
            cout<<d.str<<","<<d.p<<endl;
        }
        flag=true;
    }
}

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(;;){
		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;
}