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 <functional>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}

		multimap<int, string, greater<int> > team;
		for(int i=0; i<n; i++) {
			int a, b, c;
			char s[32];
			cin >> s >> a >> b >> c;
			team.insert(map<int, string>::value_type((3*a+c), s));
		}
		
		multimap<int, string, greater<int> >::iterator it=team.begin();
		while(it!=team.end()) {
			cout << (*it).second << "," << (*it).first << endl;
			it++;
		}
		cout << endl;
		team. clear();
	}

	return 0;

}

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

int main(){

  int n,d = 0;

  while(cin >> n, n){
    if(d) cout << endl;

    int a,b,c,z[100],tmp;
    string s[100],tmp2;

    for(int i=0;i<n;i++){
      cin >> s[i] >> a >> b >> c;

      z[i] = a * 3 + c;
    }

    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(z[j] > z[j - 1]){

	  tmp = z[j];
	  z[j] = z[j - 1];
	  z[j - 1] = tmp;

	  tmp2 = s[j];
	  s[j] = s[j - 1];
	  s[j - 1] = tmp2;
	}
      }
    }

    for(int i=0;i<n;i++) cout << s[i] << "," << z[i] << endl;
  
    d = 1;
  }
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    bool f = false;
    while (true) {
        int n; cin >> n; if (n == 0) break;
        if (f) cout << endl;
        else f = true;
        vector<pair<pair<int, int>, string> > v;
        for (int i = 0; i < n; ++i) {
            string t;
            int a, b, c;
            cin >> t >> a >> b >> c;
            v.pb(mp(mp(3*a+c, -i), t));
        }
        sort(v.rbegin(), v.rend());
        for (int i = 0; i < n; ++i)
            cout << v[i].second << "," << v[i].first.first << endl;
    }
    return 0;
}

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

using namespace std;

struct team {
    string name;
    int win, lose, draw;
    int point;

    bool operator<(const team& o) const {
        return (point > o.point);
    }
};

void solve(int n) {
    team teams[n];
    for (int i = 0; i < n; i++) {
        cin >> teams[i].name >> teams[i].win
            >> teams[i].lose >> teams[i].draw;
        teams[i].point = teams[i].win * 3 + teams[i].draw;
    }
    stable_sort(teams, teams+n);
    for (int i = 0; i < n; i++) {
        cout << teams[i].name << ',' << teams[i].point
             << endl;
    }
}

int main() {
    int n;
    cin >> n;
    solve(n);
    while (cin >> n) {
        if (n == 0) break;
        cout << endl;
        solve(n);
    }
    return 0;
}

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

int main(){
  string str[11],str2;
  int N,t=0;
  int po[11][4],sc[11],T;
  
  while(1){
    cin>>N;

    if(N==0) break;

    for(int i=0;i<N;i++){
      cin>>str[i];
      for(int j=0;j<3;j++){
	cin>>po[i][j];
      }
    }
    for(int i=0;i<N;i++){
      sc[i]=po[i][0]*3+po[i][2];
    }
    
    for(int i=0;i<N-1;i++){
      for(int j=N-1;j>i;j--){
	if(sc[j-1]<sc[j]){
	  T=sc[j];
	  sc[j]=sc[j-1];
	  sc[j-1]=T;
	  str2=str[j-1];
	  str[j-1]=str[j];
	  str[j]=str2;
	}
      }
    }
    if(t>0) cout<<endl;
    t++;

    for(int i=0;i<N;i++){
        cout<<str[i]<<","<<sc[i]<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};

struct S
{
	string s;
	int p, id;
	bool operator < (const S&s) const{
		return s.p == p ? id < s.id : p > s.p;
	}
};

int main(){
	int n;
	bool l = false;
	while(cin>>n&&n){
		if(l) cout<<endl;
		else l =true;
		vector<S> v;
		string s;
		int a, b,c;
		rep(i, n){
			cin>>s>>a>>b>>c;
			v.pb({s, a*3+c, i});
		}
		sort(all(v));
		rep(i, n){
			cout<<v[i].s<<","<<v[i].p<<endl;
		}
	}
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	tuple<int, int, string> a[10];
	for (int n, h = 0; cin >> n&&n; h++) {
		if (h > 0)cout << endl;
		rep(i, 0, n) {
			string name; cin >> name;
			int w, l, d; cin >> w >> l >> d;
			a[i] = make_tuple(w * 3 + d, -i, name);
		}
		sort(a, a + n);
		rrep(i, 0, n) {
			cout << get<2>(a[i]) << "," << get<0>(a[i]) << endl;
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
long p[10];
bool cm(const long l, const long r) {
	return p[l] > p[r];
}
int main() {
	long n, i, w, l, d, id[10], f = 0;
	string s[10];
	while (cin >> n) {
		if (n == 0)
			break;
		if (f > 0)
			cout << endl;
		f = 1;
		for (i = 0; i < n; i++)
			p[i] = 0;
		for (i = 0; i < n; i++) {
			cin >> s[i] >> w >> l >> d;
			p[i] += 3 * w + d;
			id[i] = i;
		}
		sort(id, id + n, cm);
		for (i = 0; i < n; i++) {
			cout << s[id[i]] << "," << p[id[i]] << endl;
		}
	}
	return 0;
}