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

int main(){
  int n;
  bool notfirst = false;
  while(cin >> n && n){
    if(notfirst){
      cout << "\n";
    }
    else{
      notfirst = true;
    }
    vector<pair<int, pair<int, string> > > v(n);
    for(int i = 0; i < n; i++){
      string team;
      int w, l, d;
      cin >> team >> w >> l >> d;
      v[i] = make_pair(-(w * 3 + d), make_pair(i, team));
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++){
      cout << v[i].second.second << "," << -v[i].first << "\n";
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
    int n, f=0;
    while (cin>>n) {
        if (!n) break;
        if (f) cout<<endl;
        pair<int,string> m[n];
        for (int i=0; i<n; i++) {
            cin>>m[i].second;
            int a,b,c; cin>>a>>b>>c;
            m[i].first=a*3+c*1;
        }
//        for (int i=0; i<n; i++) {
//            for (int j=i+1; j<n; j++) {
//                if (m[i].first<m[j].first) swap(m[i],m[j]);
//            }
//        }
        sort(m,m+n);
        for (int i=n; i>=0; i--) {
            cout<<m[i].second<<","<<m[i].first<<endl;
        }
        f++;
    }
}

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])));

		stable_sort(team.begin(), team.end());

		for(int i = 0; i < n; i++)
			cout << team[i].second.second << "," << -(team[i].first) << endl;

		cout << endl << endl;
		
		team.clear();
	}

	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N;
	cin >> N;
	while (1) {
		vector<pair<int, string>>ps;
		for (int i = 0; i < N; ++i) {
			string st; int a, b, c; cin >> st >> a >> b >> c;
			int score = a * 3 + c;
			ps.emplace_back(score*100-i+99, st);
		}
		sort(ps.begin(), ps.end(),greater<pair<int,string>>());
		for (auto p : ps) {
			cout << p.second << "," << p.first/100 << endl;
		}
		cin >> N;
		if (!N)break;
		cout << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

#define rep(i, n) for(int i = 0; i < n; i++)

struct data{
	int score;
	int id;
	string name;
	data(){};
	data(int s, int id, string n){
		this->score = s;
		this->id = id;
		this->name = n;
	}
};

bool comp(data d1, data d2){
	return d1.score == d2.score ? d1.id < d2.id : d1.score > d2.score;
}

data ds[10];

int main(){
	int n;
	int w, l, d;
	while(cin >> n && n){
		rep(i, n){
			cin >> ds[i].name >> w >> l >> d;
			ds[i].score = w * 3 + d;
			ds[i].id = i;
		}
		sort(ds, ds + n, comp);
		rep(i, n) cout << ds[i].name << "," << ds[i].score << endl;
		cout << endl;
	}
	return 0;
}

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;
				}
			}
		}
		puts("");
	}
	return 0;
}

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

typedef pair<int,int> P;
typedef pair<P,string> PP;

int main(void)
{

	int n;


	while(cin >> n,n){

	int win,lost,draw;
	PP team[10] = {};
	for(int i = 0; i < n; i++){
		cin >> team[i].second;
		cin >> win >> lost >> draw;
		team[i].first.first = win*3+draw;
		team[i].first.second= 10-i;
	}
	sort( team, team+10 );

	for(int i = 9; 10-i <= n; i--)
		cout << team[i].second << ',' << team[i].first.first << endl;

	}

	return 0;
}

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

int main()
{
	int count = 0;
	while (1)
	{
		vector< pair<int, string> > team;
		int n;
		cin >> n;
		if (n == 0) { break; }
		if (count != 0) { cout << endl; }

		for (int i = 0; i < n; ++i)
		{
			string t;
			int a, b, c;

			cin >> t >> a >> b >> c;

			team.push_back(make_pair(a * 3 + c, t));
		}

		sort(team.begin(), team.end());

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

		count++;
	}

	return 0;
}

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

using namespace std;

struct Team {
	string name;
	int score;
};

int main() {

	int n;
	bool test = true;

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

		if (!test)
			cout << "\n";

		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;


		}

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

		if (test)
			test = false;

	}


	return 0;

}