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 <algorithm>

struct Team {
	std::string country;
	int score;
};
bool operator > (const Team& t1, const Team& t2) { return t1.score > t2.score; }

int main()
{
	int n; std::string sn;
	bool first = true;
	while (getline(std::cin, sn)) {
		n = std::stoi(sn);
		if (n==0) break;
		if (!first) std::cout << std::endl;
		if (first) first = false;
		Team* teams = new Team[n];
		std::string country;
		int w, l, d;
		std::string buf;
		for (int i=0; i<n; i++) {
			getline(std::cin, buf);
			int offset = 0;
			int pos = buf.find(' ', 0);
			country = buf.substr(0, pos);
			offset = pos + 1;
			pos = buf.find(' ', offset);
			w = std::stoi(buf.substr(offset, pos-offset));
			offset = pos + 1;
			pos = buf.find(' ', offset);
			l = std::stoi(buf.substr(offset, pos-offset));
			d = std::stoi(buf.substr(pos+1));
			
			teams[i].country = country;
			teams[i].score = 0;
			teams[i].score += 3*w;
			teams[i].score += d;
		}
		std::sort(teams, teams + n, std::greater<Team>() );
		for (int i=0; i<n; i++) {
			std::cout << teams[i].country << "," << teams[i].score << std::endl;
		}
		
		delete[] teams;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,b[100],c[100],x,y,z,j,max,cnt;
	char a[100][100];
	scanf("%d",&n);
	cnt=0;
	while(n!=0){
		if(0<cnt) printf("\n");
		for(i=0;i<n;i++) b[i]=0;
		for(i=0;i<n;i++){
			scanf("%s %d %d %d",a[i],&x,&y,&z);
			b[i]=x*3+z;
		}
		for(i=0;i<n;i++){
			max=-1;
			for(j=0;j<n;j++){
				if(max<b[j]) max=b[j];
			}
			for(j=0;j<n;j++){
				if(max==b[j]){
					printf("%s,%d\n",a[j],b[j]);
					b[j]=-2;
				}
			}	
		}
		cnt++;
		scanf("%d",&n);
	}
	return 0;
}

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

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

typedef pair<int, string> P;
bool comp(P a, P b){
	return a.first > b.first;
}

int main(){
	string s;
	int n, w, l, d, f = 0;
	while(cin >> n, n){
		if(f)cout << endl;f = 1;
		vector<P> v;
		for(int i = 0;i < n;i++){
			cin >> s >> w >> l >> d;
			int x = w*3 + d;
			v.push_back(P(x, s));
		}
		stable_sort(v.begin(), v.end(), comp);
		for(int i = 0;i < n;i++){
			cout << v[i].second << "," << v[i].first << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

struct team{
	string name;
	int point;
};

team teams[50];

int main(){
	
	int n;
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		int a, b, c;
		for(int i = 0; i < n; i++){
			cin >> teams[i].name;
			cin >> a >> b >> c;
			teams[i].point = a * 3 + c;
		}
		
		for(int i = 0; i < n; i++){
			for(int j = n - 1; j > 0; j--){
				if(teams[j - 1].point < teams[j].point){
					swap(teams[j - 1], teams[j]);
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			cout << teams[i].name << "," << teams[i].point << endl;
		}
		cout << endl;
	}
	
	return 0;
}

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::cout<<std::endl;
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<all[i].point<<std::endl;
		}
	}
}

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

#define	score	first
#define	id		second

using namespace std;

typedef	pair<int,int>	pii;

bool cmp(const pii& a,const pii& b)
{
	if(a.score>b.score)	return true;
	if(a.score==b.score && a.id<b.id)	return true;
	return false;
}

int main()
{
	int n;

	while(cin>>n,n){
		vector<pii> scvec;
		map<int,string> namemap;

		for(int i=0;i<n;i++){
			string name;
			int w,l,d;
			cin>>name>>w>>l>>d;
			scvec.push_back(make_pair(3*w+d,i));
			namemap[i]=name;
		}

		sort(scvec.begin(),scvec.end(),cmp);

		for(int i=0;i<scvec.size();i++){
			cout<<namemap[scvec[i].id]<<","<<scvec[i].score<<endl;
		}
		cout<<endl;
	}

	return 0;
}

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

struct Team{
    string name;
    int id;
    int point;
    bool operator <(const Team& r) const{
        return point == r.point ? id < r.id : point > r.point;
    }
};


int main(){
    string name;
    int n, a, b, c, i = 0;
    while(cin >> n, n){
        if(i) cout << endl;
        vector< Team > v(n);
        for(i = 0; i < n; i++){
            cin >> name >> a >> b >> c;
            v[i].id = i;
            v[i].name = name;
            v[i].point = a * 3 + c;
        }
        sort(v.begin(), v.end());
        for(i = 0; i < n; i++){
            cout << v[i].name << "," << v[i].point << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct nx { 
string name;
int cost;
};
class Comp {
	public:
		bool operator() (const nx& a, const nx& b) {
			return a.cost > b.cost;
		}
};
int main() {
	int n, f=0;
	while (cin>>n) {
		if (n&&f) cout<<endl;
		else break;
		vector<nx> m(n);
		for (int i=0; i<n; i++) {
			cin>>m[i].name;
			int a,b,c; cin>>a>>b>>c;
			m[i].cost=a*3+c*1;
		}
		sort(m.begin(), m.end(), Comp());
		for (int i=0; i<n; i++) {
			cout<<m[i].name<<","<<m[i].cost<<endl;
		}
		f++;
	}
}