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 <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<pair<int,pair<int,string> > > v;
		string team;
		int w,l,d;
		for(int i = 0; i < n; i++){
			cin>>team>>w>>l>>d;
			v.push_back(make_pair(w*3+d*1,make_pair(-i,team)));
		}
		sort(v.begin(),v.end(),greater<pair<int,pair<int,string> > >());
		for(int i = 0; i < v.size(); i++){
			cout<<v[i].second.second<<","<<v[i].first<<endl;
		}
		cout<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <utility>


using namespace std;

int main(void){
	while(1){
		int a,n;
		string s;
		multimap<int,string,greater<int>> P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert(pair<int, string>(w*3+d,s));
		}
		multimap<int, string,greater<int>>::iterator it =P.begin();
		while( it !=P.end() ){
			cout << (*it).second << "," << (*it).first << endl;
			++it;
		}

	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
typedef struct{
  int ans;
  char s[1111];
}Team;

int comp( const void *c1, const void *c2 );

Team team[11111];
int main(){
  int n;
  int flag=0;
  int a,b,c;
  while(1){
    cin >> n;
    if(n==0)break;
    cout << endl;
    /*if(flag==1){
      cout << endl;
      }*/
    flag=1;
    for(int i=0;i<n;i++){
      cin >> team[i].s >> a >> b >> c;
      team[i].ans=a*3 + c;
    }
    qsort( team, n, sizeof(Team), comp );
    for(int i=0;i<n;i++){
      cout << team[i].s << "," << team[i].ans << endl;
    }
  }
}

/* 比較関数 */
int comp( const void *c1, const void *c2 )
{
  Team test1 = *(Team *)c1;
  Team test2 = *(Team *)c2;
  
  int tmp1 = test1.ans;
  int tmp2 = test2.ans;
  
  return tmp2 - tmp1;
}

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

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

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

        stable_sort(v.begin(),v.end(),greater<P>());

        for(auto p:v){
            cout<<p.second<<","<<p.first<<endl;
        }

        v.clear();
    }

    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; 
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
pair<int,int> dat[10];
char p[10][21];
int main(){
	int a;
	bool saisho=true;
	while(scanf("%d",&a),a){
		if(!saisho)printf("\n");
		saisho=false;
		for(int i=0;i<a;i++){
			int b,c,d;
			scanf("%s%d%d%d",p[i],&b,&c,&d);
			dat[i]=make_pair(-(b*3+d),i);
		}
		std::sort(dat,dat+a);
		for(int i=0;i<a;i++){
			printf("%s,%d\n",p[dat[i].second],-dat[i].first);
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef struct{
  string team;
  int win;
  int lose;
  int drow;
  int point;
}much;
  
int main(){
  while(1){
  much x[11],smp;
  int n;
  cin >> n;
  if(n == 0)break;
  for(int i=0;i<n;i++){
    cin >> x[i].team >> x[i].win >> x[i].lose >> x[i].drow;
  }
  for(int i=0;i<n;i++){
    x[i].point = x[i].win*3 + x[i].drow;
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(x[i].point < x[j].point){
	smp = x[i];
	x[i] = x[j];
	x[j] = smp;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << x[i].team << "," << x[i].point << endl;
  }
}
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  bool h=false;
  while(cin>>n,n){
    if(h)cout<<endl;
	h=true;
    vector<string>s(n);
	vector<int>t(n);
	rep(i,n){
	  int a,b,c;
	  cin>>s[i]>>a>>b>>c;
	  t[i]=3*a+c;
	}
	rep(i,n){
	  rep(j,n-i-1){
	    if(t[j]<t[j+1]){
		  swap(t[j],t[j+1]);
		  swap(s[j],s[j+1]);
		}
      }
	}
	rep(i,n)cout<<s[i]<<','<<t[i]<<endl;
	
  }
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,N,a,b,c,OZA[10],t;
	char S[10][10],T[10];
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%s %d %d %d",S[i],&a,&b,&c);
		OZA[i] = 3 * a + c;
	}
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			if(OZA[i] < OZA[j]){
				strcpy(T,S[i]);
				strcpy(S[i],S[j]);
				strcpy(S[j],T);
				t = OZA[i];
				OZA[i] = OZA[j];
				OZA[j] = t;
			}
		}
	}
	for(i=0;i<N;i++){
		printf("%s,%d\n",S[i],OZA[i]);
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main()
{
	int team,win,lose,draw,point[10];
	char name[10][21],b[21];
	while(1){
		scanf("%d",&team);
		if(team==0)
			break;
		for(int i=0;i<team;i++){
			scanf("%s %d %d %d",name[i],&win,&lose,&draw);
			point[i]=win*3+draw;
		}
		for(int i=0;i<team-1;i++){
			for(int j=i+1;j<team;j++){
				if(point[i]<point[j]){
					int a=point[i];
					point[i]=point[j];
					point[j]=a;
					strcpy(b,name[i]);
					strcpy(name[i],name[j]);
					strcpy(name[j],b);
				}
			}
		}
		for(int i=0;i<team;i++)
			printf("%s,%d\n",name[i],point[i]);
		printf("\n");
	}
	return 0;
}

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

using namespace std;

typedef struct {
	int sum;
	char name[20];
} TEAM;

int main()
{
	int n;
	int win, lose, drow;
	TEAM team[10];

	while (1){
		scanf("%d", &n);

		if (n == 0){
			break;
		}

		for (int i = 0; i < n; i++){
			scanf("%s %d %d %d", team[i].name, &win, &lose, &drow);
			team[i].sum = win * 3 + drow;
		}

		char tmp[10];
		int n_tmp;

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (team[j].sum > team[j - 1].sum){
					strcpy(tmp, team[j - 1].name);
					n_tmp = team[j - 1].sum;

					strcpy(team[j - 1].name, team[j].name);
					team[j - 1].sum = team[j].sum;
					
					strcpy(team[j].name, tmp);
					team[j].sum = n_tmp;
				}
			}
		}

		for (int i = 0; i < n; i++){
			cout << team[i].name << "," << team[i].sum << endl;
		}

		if (n != 0){
			cout << endl;
		}
	}

	return (0);
}