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>

using namespace std;

struct Team {
	string name;
	int score;
};

int main() {

	int n;

	while (cin >> n && n != 0) {

		Team *team = new Team[n];
		int w, l, d;

		for (int i = 0; i < n; i++) {

			cin >> team[i].name >> w >> l >> d;
			team[i].score = w * 3 + d * 1;


		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (team[i].score > team[j].score)
					swap(team[i], team[j]);
			}
		}

		for (int i = 0; i < n; i++)
			cout << team[i].name << "," << team[i].score << "\n";

	}


	return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>
#include <functional>
using namespace std;
pair<int,string> team[10];
int main()
{
	int n;
	bool first=true;
	while(cin>>n&&n){
		if(!first)cout<<endl;
		for(int i=0;i<n;i++){
			int k,m,h;
			cin>>team[i].second>>k>>m>>h;
			team[i].first=(k*3+h)*100+10-i;
		}
		sort(team,team+n,greater<pair<int,string>>());
		for(int i=0;i<n;i++){
			cout<<team[i].second<<","<<team[i].first/100<<endl;
		}
		first=false;
	}
    return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	bool f=false;
	while(cin>>n){
		if(!n)break;
		vector<pair<int,string> > teams;
		for(int i=0,w,l,d;i<n;++i){
			string team;
			cin>>team>>w>>l>>d;
			teams.push_back(make_pair(w*3+d,team));
		}
		stable_sort(teams.rbegin(),teams.rend());
		if(f)cout<<endl;
		else f=true;
		for(vector<pair<int,string> >::iterator it=teams.begin();it!=teams.end();++it) cout<<(*it).second<<","<<(*it).first<<"\n";
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;
typedef pair<string,int> P; 
bool cmp(const P &p,const P &q){
  if(p.S != q.S)return p.S > q.S;
}

int main(){
  int n;
  while(cin >> n && n){
    string s;
    vector<P> vec;
    int a,b,c;
    for(int i=0;i<n;i++){
    cin >> s >> a >> b >> c;
    vec.push_back(P(s,a*3+b*0+c*1));
    }

    stable_sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
      cout << vec[i].F << "," << vec[i].S << endl;
    }
  }
  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a, b, c;
vector < pair<ll,string> > v;
string s;

int main(){
	bool f = 0;
	while (cin >> n&&n){
		REP(i, n){
			cin >> s >> a >> b >> c;
			v.push_back(make_pair(a * 3 + c, s));
		}
		sort(ALL(v));
		reverse(ALL(v));
		if (f)cout << " " << endl;
		REP(i, v.size()){
			cout << v[i].second << "," << v[i].first << endl;
		}
		f = 1;
		v.clear();
	}
}

C++: #include<stdio.h>

int main()
{
	int score[11],win,lose,draw,point[11];
	int n,i,j;
	char str[11][21];
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",str[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
			point[i]=score[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]>point[j]){
					point[10]=point[i];
					point[i]=point[j];
					point[j]=point[10];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]==score[j]){
					printf("%s,%d\n",str[j],score[j]);
					score[j]=-1;
					break;
				}
			}
		}
		printf("\n\n");
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef struct{
  char name[20];
  int kati;
  int make;
  int hiki;
  int total;
}BU;
int main(){
  BU t[10];
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin>>t[i].name>>t[i].kati>>t[i].make>>t[i].hiki;
      t[i].total=0;
      t[i].total+=t[i].kati*3+t[i].hiki;
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(t[j].total>t[j-1].total){
	  BU 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].total<<endl;
    }
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

struct Team {
  string name;
  int pt, id;
  bool operator<(const Team& a) const {
    if (pt != a.pt) return pt > a.pt;
    return id < a.id;
  }
};

int n;
Team teams[12];

int main() {
  bool flag = false;
  while (cin >> n, n) {
    if (flag) {
      cout << endl;
    }
    int win, lose, draw;
    rep (i,n) {
      cin >> teams[i].name >> win >> lose >> draw;
      teams[i].id = i;
      teams[i].pt = win * 3 + draw;
    } 
    sort(teams, teams + n);
    rep (i,n) {
      cout << teams[i].name << "," << teams[i].pt << endl;
    }
    flag = true;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	
	char coun[11][21];
	int score[11],win,lose,draw;
	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;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(score[i]>score[j]){
					score[10]=score[j];
					score[j]=score[i];
					score[i]=score[10];
					strcpy(coun[10],coun[j]);
					strcpy(coun[j],coun[i]);
					strcpy(coun[i],coun[10]);
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%s,%d\n",coun[i],score[i]);
		}
	}
	return 0;
}