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

int main() {
	int a = 0;

	while (1) {
		int n, w, l, d;
		vector<string> name(10);

		cin >> n;
		if (n == 0) break;
		if (a == 1) cout << endl;
		vector< pair<int, int> > vp(n);

		for (int i = 0; i < n; i++) {
			cin >> name[i];
			cin >> w >> l >> d;
			
			int p = 3 * w + d;

			vp[i].first = p;
			vp[i].second = (-1) * i;
		}
		sort(vp.begin(), vp.end());
		for (int i = n - 1; i >= 0; i--) {
			cout << name[vp[i].second * (-1)] << "," << vp[i].first << endl;
		}
		a = 1;
	}
}

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

int main() {
  int n, W, L, E;
  bool flag = false;
  string T;
  // vector<int> vc;
  //map<int,vector<string> > res;  
  
  while(cin >> n, n) {
    vector<int> vc;
    map<int,vector<string> > res;
    if(flag) cout << endl;
    else flag = true;
    
    for(int i = 0 ; i < n ; i++) {
      cin >> T >> W >> L >> E;
      int P = -(W*3 + E);
      if(count(vc.begin(), vc.end(), P) == 0) {
	vc.push_back(P);
      }
      res[P].push_back(T);
    }
    sort(vc.begin() , vc.end());
    for(int i = 0 ; i < vc.size() ; i++)
      for(int j = 0 ; j < res[vc[i]].size() ; j++)
	cout << res[vc[i]][j] << ',' << -vc[i] << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main(){
	int n,i,i2,point[10],w,e,l,sum,maxn;
	char team[20][10];
	scanf("%d",&n);
	for(i=0;i!=n;i++){
		scanf("%s%d%d%d",team[i],&w,&e,&l);
		sum=w*3+l;
		point[i]=sum;
	}
	for(i=0;i!=n;i++){
		maxn=0;
		for(i2=0;i2!=n;i2++){
			if(point[i2]>point[maxn]){
				maxn=i2;
			}
		}
		printf("%s,%d\n",team[maxn],point[maxn]);
		point[maxn]=0;
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int main(){
    int n,l=0;
    while(cin>>n,n){
        if(l)cout<<endl;l++;
        vector<pair<int,string> >p;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            p.push_back(make_pair(3*a+c, s));
        }
        sort(p.begin(),p.end());
        for(int i=0;i<p.size();i++){
            cout<<p[i].second<<","<<p[i].first<<endl;
        }
    }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a=1;
int main(void){
        for(;;){

        int n,q=0;

        cin>>n;
        if(n==0){
            //cout<<endl;
            break;
        }
        if(a==1);
        else cout<<endl;
        int w[20],l[20],d[20];
        int p[20];

        char team[20][40];


        for(int i=0;i<n;i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            p[i]=w[i]*3+d[i];
        }
        for(int i=3*n;i>=0;i--){
            for(int j=0;j<n;j++){
                if(p[j]==i){
                    cout<<team[j]<<","<<p[j]<<endl;
                    q++,a++;
                }
            }

        }


        }
	return 0;
}

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

struct Country{string name; int wp;};
vector<Country> Allteam;

bool comp(const Country& c1, const Country& c2){
  return (c1.wp > c2.wp);
}

int main(void){
  int n, k = 0;
  while(cin >> n, n){
    if(k != 0) cout << endl;
    for(int i = 0; i < n; i++){
      string tname;
      int w, l, d;
      cin >> tname >> w >> l >> d;
      Country c = {tname, w * 3 + d};
      Allteam.push_back(c);
    }
    sort(Allteam.begin(), Allteam.end(), comp);
    for(int i = 0; i < Allteam.size(); i++){
      cout << Allteam[i].name << "," << Allteam[i].wp << endl;
    }
    Allteam.clear();
    k++;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100],d[100],f[100],g[100],h,i,j,q;
	char z[100][100],x[100];
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
			printf("\n");
		for(i=0;i<a;i++){
			g[i]=0;
			scanf("%s %d %d %d",z[i],&s[i],&d[i],&f[i]);
			g[i]=s[i]*3+f[i];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]<g[j]){
					h=g[i];
					g[i]=g[j];
					g[j]=h;
					strcpy(x, z[i]);
					strcpy(z[i], z[j]);
					strcpy(z[j], x);
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%s,%d\n",z[i],g[i]);
		}

	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    vector<pair<string,int> > s;
    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));
    }
    sort(s.begin(),s.end());
    for(int i=n-1;i>=0;i--)
      cout<<s[i].first<<","<<s[i].second<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

struct Data
{
	int point;
	char name[32];
	
	bool operator> (const Data& d)const
	{
		return point > d.point;
	}
};

int main()
{
	int n;
	bool first = true;
	while(scanf("%d", &n), n){
		if(!first)
			puts("");
		else
			first = false;
		
		vector<Data> data(n);
		rep(i, n){
			int won, lose, tie;
			scanf("%s%d%d%d", data[i].name, &won, &lose, &tie);
			data[i].point = won*3 + tie;
		}
		stable_sort(data.begin(), data.end(), greater<Data>());
		rep(i, n)
			printf("%s,%d\n", data[i].name, data[i].point);
	}
	
	return 0;
}