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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
struct Team
{
	string team;
	int num,point;
};
bool comp(Team a,Team b)
{
	if(a.point!=b.point)return a.point>b.point;
	return a.num < b.num;
}
int main()
{
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n==0)break;
		vector<Team> vec;
		for(int i=0;i<n;i++)
		{
			string team;
			int win,lose,tie;
			cin >> team >> win >> lose >> tie;
			int point=win*3+tie;
			Team a;
			a.team=team;
			a.num=i;
			a.point=point;
			vec.pb(a);
		}
		sort(vec.begin(),vec.end(),comp);
		for(int i=0;i<vec.size();i++)
		{
			cout << vec[i].team << ',' << vec[i].point << endl;
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;
        vector< pair<int, string> > tourn;

        for (int i = 0; i < n; i++) {
            int win, los, ev;
            string str;
        
            cin >> str >> win >> los >> ev;
            pair<int, string> p(win * 2 + ev, str);
            tourn.push_back(p);
        }
        sort(tourn.rbegin(), tourn.rend());
        
        for (int i = 0; i < tourn.size(); i++)
            cout << tourn[i].second << ',' << tourn[i].first << endl;
        cout << endl;
    }

    return 0;
}

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

#define fi first
#define se second

int main() {
	int n;
	bool flag = false;

	while(cin >> n, n) {
		priority_queue<pair<pair<int,int>,string> > q;
		if(flag) {
			cout << endl;
		}
		for(int i = 0; i < n; i++) {
			pair<pair<int,int>, string> tmp;
			int win, lose, draw;
			string team;
			cin >> team >> win >> lose >> draw;
			
			tmp.fi.fi = win * 3 + draw;
			tmp.fi.se = n - i;
			tmp.se = team;

			q.push(tmp);
		}

		while(!q.empty()) {
			pair<pair<int,int>, string> tmp;
			tmp = q.top(); q.pop();
			cout << tmp.se << "," << tmp.fi.fi << endl;
		}
		flag = true;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j;
	int temp,data[10];
	char tn[11][21],temps[21];
	int k,m,h;
	scanf("%d" ,&n);
	while(n!=0){
		for(j=0;j<10;j++){
			data[j]=0;
		}
		for(j=0;j<n;j++){
			scanf("%s %d %d %d",tn[j],&k,&m,&h);
			data[j]+=k*3;
			data[j]+=h;
		}
		for(i=0;i<n;i++){
			for(j=n;j>0;j--){
				if(data[j]>data[j-1]){
					temp=data[j];
					data[j]=data[j-1];
					data[j-1]=temp;
					strcpy(temps,tn[j]);
					strcpy(tn[j],tn[j-1]);
					strcpy(tn[j-1],temps);
				}
			}
		}
		for(j=0;j<n;j++){
				printf("%s,%d\n",tn[j],data[j]);
		}
		scanf("%d",&n);
		if(n!=0){
			printf("\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<complex>
#include<cstring>
#include<sstream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<vector>
#include<string>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<functional>
#include<algorithm>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
typedef pair<int,string> P;
int main(){
	int n,x,y,z;
	priority_queue<P> tab;
	string s;
	while(cin>>n,n){
		rep(i,n){
			cin>>s>>x>>y>>z;
			tab.push(P(x*3+z,s));
		}
		while(!tab.empty()){
			P q=tab.top();
			cout<<q.second<<','<<q.first<<endl;
			tab.pop();
		}
	}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++;
        priority_queue<pair<int,string>, vector<pair<int,string> >, less<pair<int,string> > >p;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            p.push(make_pair(3*a+c, s));
        }
        while(p.size()){
            pair<int,string>r=p.top();
            p.pop();
            cout<<r.second<<","<<r.first<<endl;
        }
    }
}

C++: 
#include <iostream>
#include <algorithm>
struct team{
	std::string name;
	int point;
	int n;
};

bool tsort(const team& a,const team& b){
	if(a.point - b.point){
		return a.point > b.point;
	}
	return a.n < b.n;
}

int main(){
	int n;
	while(std::cin>>n,n){
		team all[10];
		for(int i = 0;i < n;i++){
			std::string name;
			int w,d,l;
			std::cin>>name>>w>>l>>d;
			team t = {name,w*3+d,i};
			all[i] = t;
		}
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<all[i].point<<std::endl;
		}
		std::cout<<std::endl;
	}
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct DATA{
  string s;
  int score;
};
int main(){
  int n;
  while(cin>> n,n){
    DATA data[10],temp;
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>> data[i].s>> a>> b>> c;
      data[i].score=a*3+c;
    }

    for(int i=0;i<n;i++){
      for(int j=n-1;j>i;j--){
	if(data[j].score>data[j-1].score){
	  temp=data[j];
	  data[j]=data[j-1];
	  data[j-1]=temp;
	}
      }
    }

    for(int i=0;i<n;i++){
      cout<< data[i].s<< ","<< data[i].score<< endl;
    }
    cout<< endl;
  }
}

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