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 <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int N, K;
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

vi dist;
int d[110][110];

bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
    dist = vector<int>(n, INF);
    dist[s] = 0; // 開始点の距離は0
    for (int i = 0; i < n; i++) {
        for (int v = 0; v < n; v++) {
            for (int u = 0; u < n; u++) {
                if (dist[v] != INF && dist[u] > dist[v] + d[v][u]) {
                    dist[u] = dist[v] + d[v][u];
                    if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
                }
            }
        }
    }
    return false;
}
bool cmp(const pair<int,string>& a, const pair<int,string>& b){
    return a.first < b.first;
}
int main() {
    //cout << fixed << setprecision(15);

    int n;
    while(cin >> n, n){

        vector<pair<int, string>> vp;
        REP(i, n){
            string s;
            cin >> s;
            int q, w, e;
            cin >> q >> w >> e;
            vp.push_back({-(q*3+e), s});
        }

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

        REP(i, n){
            cout << vp[i].second << "," << -vp[i].first << endl;
        }
        cout << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j,k,x,n;
	int win,lose,drow;
	char kuni[10][21];
	int tokuten[10];
	while(1) {
		cin>>n;if(n==0)break;
		for(i=0;i<n;i++) {
			cin>>kuni[i]>>win>>lose>>drow;
			tokuten[i]=win*3+drow;
		}
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				if(tokuten[i]<tokuten[j]) {
					swap(tokuten[i],tokuten[j]);
					swap(kuni[i],kuni[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<kuni[i]<<","<<tokuten[i]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> pii;

int main() {
	int n;
	
	while (cin >> n, n) {
		string str[10];
		vector<pii> v(n);
		
		REP(i, n) {
			int a, b, c;
			cin >> str[i] >> a >> b >> c;
			int score = 3*a + c;
			v[i] = pii(score, -i);
		}
		sort(v.begin(), v.end(), greater<pii>());
		
		REP(i, n) printf("%s,%d\n", str[-v[i].second].c_str(), v[i].first);
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    
    int n;
    int flag=0;
    while(cin >> n && n)
    {
    	string str;
    	int a,b,c;
    	vector<string>list;
    	int num[1000]={};
    	int numberlist[1000]={};
    	int count=0;

    	while(n--)
    	{
    		cin >> str >> a >> b >> c;
    		num[count]=a*3+c;
    		numberlist[count]=count;
    		list.push_back(str);
    		count++;
    	}

    	for(int i=0;i<count;i++)
    	{
    		for(int j=i;j<count;j++)
    		{
    			if(num[i]<num[j])
    			{
    				swap(num[i],num[j]);
    				swap(list[i],list[j]);
    				swap(numberlist[i],numberlist[j]);
    			}
    		}
    	}
    	for(int i=0;i<count;i++)
    	{
    		for(int j=i;j<count;j++)
    		{
    			if( num[i]==num[j] && numberlist[i]>numberlist[j])
    			{
    				swap(num[i],num[j]);
    				swap(list[i],list[j]);
    				swap(numberlist[i],numberlist[j]);    			
    			}
    		}
    	}
    	if(flag)cout << endl;
    	for(int i=0;i<count;i++)
    	{
    		cout << list[i] << "," << num[i] << endl;
    	}
    	flag=1;
    }
    return 0;
}

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

using namespace std;

typedef struct{
  string name;
  int sum;
}TEAM;

int main(){
  int rev = 0;
  int num;
  while(cin >> num && num){
    //if(rev) cout << endl;
    rev++;
    int win, lose, draw;
    TEAM team[num];
    for(int i = 0; i < num; i++){
      cin >> team[i].name >> win >> lose >> draw;
      team[i].sum = win*3 + draw;
    }
    for(int i = 0; i < num-1; i++){
      for(int j = i+1; j < num; j++){
	if(team[i].sum < team[j].sum){
	  TEAM tmp = team[i];
	  team[i] = team[j];
	  team[j] = tmp;
	}
      }
    }
    for(int i = 0; i < num; i++){
      cout << team[i].name <<"," << team[i].sum<<endl;
    }
    cout << endl;
  }
  return 0;
}