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 <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;
  while(cin >> n, n){
    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;
    }
    cout << endl;
    Allteam.clear();
  }
  return 0;
}

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

int main(){
	char team[10][21],temp[21];
	int knit,n,win[10],lose[10],drow[10],wpt[10],i,j;
	
	for(;;){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%s%d%d%d",&team[i],&win[i],&lose[i],&drow[i]);
			wpt[i] = win[i] * 3 + drow[i];
		}
		
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(wpt[i]>wpt[j]){
					knit=wpt[j];
					wpt[j]=wpt[i];
					wpt[i]=knit;
					strcpy(temp,team[j]);
					strcpy(team[j],team[i]);
					strcpy(team[i],temp);
				}
			}
		}
		
		for(i=0;i<n;i++){
			printf("%s,%d\n",team[i],wpt[i]);
		}
		puts("");
	}
	
	return 0;
}

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

int N,sum[10],sum2[10];
struct DATA{
	string country;
	int win,lose,drow,sum,flag; 
};
DATA data[10];
int main(void){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>data[i].country>>data[i].win>>data[i].lose>>data[i].drow;
		data[i].sum=data[i].win*3+data[i].drow;
		sum[i]=data[i].sum;
	}
	sort(sum,sum+N);
	for(int i=0;i<N;i++){sum2[i]=sum[N-i];}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(sum2[i]==data[j].sum && data[j].flag==0){
				cout<<data[j].country<<","<<data[j].sum<<endl;
				data[j].flag=1;
			}
		}
	}
	return 0;
}

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

using namespace std;

class Team{
public:
	string name;
	int win;
	int lose;
	int draw;
	int point;

};
bool operator<( const Team& rhs, const Team& lhs ){
	return ( rhs.point < lhs.point );
}
bool operator>( const Team& rhs, const Team& lhs ){
	return ( rhs.point > lhs.point );
}
int main(int argc, char const* argv[])
{
	int num;
	Team team[10];

	while( cin >> num && num != 0 ){
		for( int i = 0;i < num;i++ ){
			cin >> team[i].name >> team[i].win >> team[i].lose >> team[i].draw;
			team[i].point = team[i].win * 3 + team[i].draw;
		}
		stable_sort( team, team + num, greater<Team>() );
		for( int i = 0;i < num;i++ ) cout << team[i].name << "," << team[i].point << endl;
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
struct score{
	string str;
	int win;
	int lose;
	int draw;
	int point;
};

int main(){
	int n,a=0;
	struct score team[10];
	while(1){
		cin>>n;
		if(n==0) break;
		if(a!=0) cout<<endl;
		for(int i=0;i<n;i++){
			cin>>team[i].str>>team[i].win>>team[i].lose>>team[i].draw;
			team[i].point = team[i].win*3 + team[i].draw;
		}
		
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(team[i].point < team[j].point){
					struct score t = team[i];
					team[i] = team[j];
					team[j] = t;
				}
			}
		}

		for(int i=0;i<n;i++){
			cout<<team[i].str<<","<<team[i].point<<endl;
		}
		a++;
	}
	return 0;
}

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

struct Team {
	string name;
	int score, no;
	Team(const string &na, int sc, int no) : name(na), score(sc), no(no) {}

	bool operator <(const Team &t) const {
		if(score != t.score) return score > t.score;
		return no < t.no;
	}
};

int main() {
	bool first = true;
	for(int N; cin >> N, N; ) {
		if(first) first = false;
		else cout << endl;
		vector<Team> v;
		for(int i = 0; i < N; i++) {
			string s;
			int w, l, d;
			cin >> s >> w >> l >> d;
			v.push_back(Team(s, 3 * w + d, i));
		}
		sort(v.begin(), v.end());

		for(auto it : v) {
			cout << it.name << ',' << it.score << endl;
		}
	}
}

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;

ll n, a, b, c;
string s;

vector<string> vs;
vector<P> vi;

bool flag(P i, P j){
	if (i.first == j.first){
		return i.second < j.second;
	}
	else return i.first > j.first;
}

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

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

struct data{
	
	string name;
	int w;
	int l;
	int e;
	int t;
	static bool s  (const data& x,const data& y){
        return x.t>y.t;
    }
};

int main(){
	
	int n;
	int f=0;
	while(cin>>n,n!=0){
		if(f!=0)
		cout<<endl;
		vector<data> m(n);
		for(int i=0;i<n;i++){
			cin>>m[i].name>>m[i].w>>m[i].l>>m[i].e;
			m[i].t=m[i].w*3+m[i].e;
		}
		sort(m.begin(),m.end(),data::s);
		for(int i=0;i<n;i++)
			cout<<m[i].name<<","<<m[i].t<<endl;
		f=1;
	}
}