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 <map>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    while (true) {
        int n; cin >> n; if (n == 0) break;
        vector<pair<pair<int, int>, string> > v;
        for (int i = 0; i < n; ++i) {
            string t;
            int a, b, c;
            cin >> t >> a >> b >> c;
            v.pb(mp(mp(3*a+c, i), t));
        }
        sort(v.rbegin(), v.rend());
        for (int i = 0; i < n; ++i)
            cout << v[i].second << "," << v[i].first.first << endl;
        cout << endl;
    }
    return 0;
}

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

        int n,q=0;
        cin>>n;
        if(n==0)break;
        int w[20],l[20],d[20];
        int p[20];

        char team[20][20];


        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++;
                }
            }

        }

        cout<<endl;
        }
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        string str[10];
        int num[10];
        for(int i=0,win,lose,draw;i<n;i++){
            cin>>str[i]>>win>>lose>>draw;
            num[i]=win*3+draw;
            str[i]+=',';
        }
        for(int i=0;i<n;i++){
            int ma=0;
            for(int j=0;j<n;j++)if(num[ma]<num[j])ma=j;
            cout<<str[ma]<<num[ma]<<endl;
            num[ma]=-1;
        }
        cout<<endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,string> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

bool cmp(P a, P b) {
  return a.first>b.first;
}

vector<P> m(vector<P> a) {
  if(a.size()==1) return a;
  if(a.size()==2) {
    inplace_merge(a.begin(),a.begin()+1,a.end(),cmp);
    return a;
  }
  vector<P> b,c;
  for(int i=0; i<a.size(); i++) {
    if(i<a.size()/2) b.push_back(a[i]);
    else c.push_back(a[i]);
  }
  b=m(b);
  c=m(c);
  copy(c.begin(), c.end(), back_inserter(b)); 
  inplace_merge(b.begin(),b.begin()+(b.size()-c.size()),b.end(),cmp);
  return b;
}

int main() {
  int n;
  bool ck=false;
  while(cin >> n && n) {
    if(ck) cout << endl;
    ck=true;
    vector<P> a(n);
    rep(i,n) {
      string s;
      int x,y,z;
      cin >> s >> x >> y >> z;
      a[i].F=x*3+z;
      a[i].S=s;
    }
    a=m(a);
    rep(i,n) cout << a[i].S << "," << a[i].F << endl;
  }
  return 0;
}

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

pair<int, string> pa[10];

int main() {
	int N,ff=0;
	while (cin >> N, N) {
		if (ff == 1)cout << endl;
		for (int i = 0; i < N; i++) {
			cin >> pa[i].second;
			int w, l, d;
			cin >> w >> l >> d;
			pa[i].first = w * 3 + d;

		}

		sort(pa, pa + N - 1);

		for (int i = N - 1; i >= 0; i--) {
			cout << pa[i].second << "," << pa[i].first << endl;
		}
		ff = 1;

	}

}

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

int main() {
    int N;
    bool first = true;
    while (cin >> N, N) {
        if (!first) cout << endl;
        first = false;

        set<int> s;
        vector<string> name(N);
        vector<int> score(N);
        for (int i = 0; i < N; i++) {
            cin >> name[i];
            int x, y, z;
            cin >> x >> y >> z;
            score[i] = x * 3 + z;
            s.insert(-score[i]);
        }

        vector<int> idx;
        for (auto i : s) {
            for (int j = 0; j < N; j++) {
                if (score[j] == -i) {
                    idx.push_back(j);
                }
            }
        }

        for (auto i : idx) cout << name[i] << "," << score[i] << endl;
    }

    return 0;
}

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

using namespace std;

int main(void){
	string	team;
	int	w,d,l;

	for(int n;cin >> n,n;){
		pair<string,int> *val,tmp;

		val = new pair<string,int>[n];

		for(int i=0;i<n;i++){
			cin >> team >> w >> l >> d;
			val[i]=make_pair(team,w*3+d);
		}

		for(int i=0;i<n-1;i++)
			for(int j=0;j<n-i-1;j++)
				if(val[j].second<val[j+1].second){
					tmp=val[j];
					val[j]=val[j+1];
					val[j+1]=tmp;
				}

		for(int i=0;i<n;i++)
			cout << val[i].first << "," << val[i].second << endl;
		delete [] val;
	}
	return 0;
}

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

std::pair<std::string,int> team[10];

int main()
{
	int n,win,lose,draw,point;
	std::string name;
	bool first=true;
	
	while(1)
	{
		std::cin>>n;
		if(n==0)break;
		
		for(int i=0;i<n;i++)
		{
			std::cin>>name>>win>>lose>>draw;
			point=win*3+draw;
			team[i].first=name;
			team[i].second=point;
		}
		
		for(int i=0;i<n;i++)
		{
			for(int j=i;j>0&&team[j].second>team[j-1].second;j--)
			{
				std::pair<std::string,int> temp;
				temp=team[j];
				team[j]=team[j-1];
				team[j-1]=temp;
			}
		}
		
		if(first){first=false;}
		else{std::cout<<std::endl;}
		for(int i=0;i<n;i++)
		{
			std::cout<<team[i].first<<','<<team[i].second<<std::endl;
		}
	}
	return 0;
}

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

int main(){
  string str[11],str2;
  int N;
  int po[11][4],sc[11],T;

  while(1){
  cin>>N;
  if(N==0) break;

  for(int i=0;i<N;i++){
    cin>>str[i];
    for(int j=0;j<3;j++){
      cin>>po[i][j];
    }
  }
  
  for(int i=0;i<N;i++){
    sc[i]=po[i][0]*3+po[i][2];
  }
  
  for(int i=0;i<N-1;i++){
    for(int j=N-1;j>i;j--){
      if(sc[j-1]<sc[j]){
	T=sc[j];
	sc[j]=sc[j-1];
	sc[j-1]=T;
	str2=str[j-1];
	str[j-1]=str[j];
	str[j]=str2;
      }
    }
  }

for(int i=0;i<N;i++){
  cout<<str[i]<<","<<sc[i]<<endl;
 }
  }
return 0;
}