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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

struct Team{
  string name;
  int win,lose,draw;
  int score;
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  bool f = false;
  while(cin>>n&&n){
    if(f)
      cout << endl;
    vector<Team> v(n);
    rep(i,n){
      cin >> v[i].name >> v[i].win>>v[i].lose >>v[i].draw;
      v[i].score = v[i].win*3 + v[i].draw;
    }
    sort(all(v),[](const Team &a,const Team &b){return a.score>b.score;});
    rep(i,n){
      cout << v[i].name << "," << v[i].score<<endl;
    }
    f = true;
  }
  return 0;
}

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

typedef struct{
	string name;
	int score;
}Team;

int main(void){
	int n;
	bool firstFlg = true;
	
	while(cin>>n && n){
		if(!firstFlg) cout<<endl;
		else firstFlg = false;
	
		Team t[n];
		for(int i=0;i<n;i++){
			int win,lose,draw;
			
			cin>>t[i].name>>win>>lose>>draw;
			t[i].score = win*3 + draw;
		}
		
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(t[i].score < t[j].score){
					Team tmp = t[i];
					t[i] = t[j];
					t[j] = tmp;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			cout<<t[i].name<<","<<t[i].score<<endl;
		}
	}

	return 0;
}

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

struct Team {
	string name;
	int score, no;
	Team(const string &na, int sc, int no) : name(na), score(sc), no(no) {}

	bool operator <(const Team &t) const {
		if(score != t.score) return score > t.score;
		return no < t.no;
	}
};

int main() {
	bool first = true;
	for(int N; cin >> N, N; ) {
		if(first) first = false;
		else cout << endl;
		vector<Team> v;
		for(int i = 0; i < N; i++) {
			string s;
			int w, l, d;
			cin >> s >> w >> l >> d;
			v.push_back(Team(s, 3 * w + d, i));
		}
		sort(v.begin(), v.end());

		for(auto it = v.begin(); it != v.end(); ++it) {
			cout << it->name << ',' << it->score << endl;
		}
	}
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100],d[100],f[100],g[100],h,i,j,q;
	char z[100][100],x[100];
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++){
			g[i]=0;
			scanf("%s %d %d %d",z[i],&s[i],&d[i],&f[i]);
			g[i]=s[i]*3+f[i];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]<g[j]){
					h=g[i];
					g[i]=g[j];
					g[j]=h;
					strcpy(x, z[i]);
					strcpy(z[i], z[j]);
					strcpy(z[j], x);
					q=s[i];
					s[i]=s[j];
					s[j]=q;
				}
			}
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]==g[j]){
					if(s[i]>s[j]){
						q=s[i];
						s[i]=s[j];
						s[j]=q;
						h=g[i];
						g[i]=g[j];
						g[j]=h;
						strcpy(x, z[i]);
						strcpy(z[i], z[j]);
						strcpy(z[j], x);
					}
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%s,%d\n",z[i],g[i]);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,string> pii;
int main(){
    int n;
    int cnt=0;
    while(cin>>n,n){
        string str;
        int W,L,D;
        vector<pii>V;
        while(n--){
            cin>>str>>W>>L>>D;
            V.push_back(pii(W*3+D,str));
        }
        if(cnt)cout<<endl;
        stable_sort(V.begin(),V.end(),greater<pii>());
        for(int i=0;i<V.size();i++){
            cout<<V[i].S<<","<<V[i].F<<endl;
        }
        cnt++;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

typedef pair<int,string> mypair;

int main(void){

int n, k, m, h;
mypair ch[10];

	while(cin >>n){
		if(n==0 || cin.eof()) break;
		rep(i,n){
			cin >> ch[i].second;
			cin >> k >> m >> h;
			ch[i].first = (k *3 + h *1) * 100 + 50- i;
		}
		sort(ch, ch+n, greater<mypair>());
		rep(i,n) cout << ch[i].second << "," << (int)(ch[i].first/100) << endl;
//		cout << endl;
	}
	return 0;
	
}

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

using namespace std;
int main(void){
	bool b=false;
	while(1){
		int a,n;
		string s;
		multimap<int, string, greater<int> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert( pair<int, string>(w*3+d,s));
		}
		multimap<int, string, greater<int> >::iterator it = P.begin();
		while( it != P.end() )	{
			cout << (*it).second << "," << (*it).first << endl;
			++it;
		}
	}
	return 0;
}