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>
using namespace std;

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

int main() {
    int n;

    while (cin >> n, n) {
        Team team[10];
        for (int i = 0; i < n; i++) {
            int w, l, d;
            team[i].id = i;
            cin >> team[i].name >> w >> l >> d;
            team[i].point = w*3 + d;
        }
        sort(team, team+n);
        for (int i = 0; i < n; i++) {
            cout << team[i].name << "," << team[i].point << endl;
        }
        cout << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
struct Team
{
	string team;
	int num,point;
};
bool comp(Team a,Team b)
{
	if(a.point!=b.point)return a.point>b.point;
	return a.num < b.num;
}
int main()
{
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n==0)break;
		vector<Team> vec;
		for(int i=0;i<n;i++)
		{
			string team;
			int win,lose,tie;
			cin >> team >> win >> lose >> tie;
			int point=win*3+tie;
			Team a;
			a.team=team;
			a.num=i;
			a.point=point;
			vec.pb(a);
		}
		sort(vec.begin(),vec.end(),comp);
		for(int i=0;i<vec.size();i++)
		{
			cout << vec[i].team << ',' << vec[i].point << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int cnt=0;
  string a[50][50][10];
  for(int i=0;i<50;i++)
    for(int j=0;j<50;j++)
      for(int k=0;k<10;k++)
	a[i][j][k]="";
  while(cin>>n,n!=0){
    //    vector<pair<string,int> > s;
    vector<vector<string> > anspo(50);
    for(int i=0;i<n;i++){
      string str;cin>>str;
      int w,l,d;cin>>w>>l>>d;
      //s.push_back(make_pair(str,w*3+d));
      anspo[w*3+d].push_back(str);
    }
    for(int i=49;i>=0;i--){
      for(int j=0;j<anspo[i].size();j++){
	a[cnt][i][j]=anspo[i][j];
      }
    }
    cnt++;
  }
  for(int i=0;i<cnt;i++){
    for(int j=49;j>=0;j--){
      for(int k=0;k<10;k++){
	if(a[i][j][k]!="")
	  cout<<a[i][j][k]<<","<<j<<endl;
      }
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cctype>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;if(n<0)pcu('-'),n*=-1;
	if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10; while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

struct T { string s; int r; };

int main() {
	function<void()> f = [&]{f = []{outl();};};
	for (int n; (n = in());) {
		f();
		vector<T> v(n);
		for (T &x: v) {
			int w, l, d;
			scan(x.s, w, l, d);
			x.r = w * 3 + d;
		}
		stable_sort(v.begin(), v.end(), [](T a, T b){return a.r > b.r;});
		for (T x: v)
			outl(x.s, ',', x.r);
	}
}

C++: #include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


vector<pair<int,string> > sort(vector<pair<int,string> > data){
	int len = data.size();
	for(int i=1;i<len;i++){
		for(int j=len-1;j>=i;j--){
			if( data[j-1].first < data[j].first ){
				swap(data[j-1],data[j]);
			}
		}
	}
	return data;
}





int main(){
    int n;
    bool f = false;
    while(cin>>n){
        if(n==0)break;
        if(f)cout<<endl;
        else f=true;
        
        vector< pair<int,string> > data;
        rep(i,n){
            string s;int w,l,d;
            cin>>s>>w>>l>>d;
            int p = w*3+d*1;
            data.pb(make_pair(p,s));
        }
		
		data = sort(data);        
        rep(i,data.size()){
            cout<<data[i].second<<","<<data[i].first<<endl;
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

struct Team {
  int point;
  string name;
  Team(string name, int win, int lose, int draw)
      : name(name), point(win * 3 + draw) {}
  void print() { cout << name << "," << point << endl; }
  bool operator>(const Team& t) const { return point > t.point; }
};

int main() {
  int n;
  int nlf = 0;
  while (scanf("%d", &n), n) {
    if (nlf++) puts("");

    vector<Team> ts;
    for (int i = 0; i < n; i++){
      string name;
      int win, lose, draw;
      cin >> name >> win >> lose >> draw;
      ts.push_back(Team(name, win, lose, draw));
    }
    stable_sort(ts.begin(), ts.end(), greater<Team>());
    for (int i = 0; i < n; i++) ts[i].print();
  }
  return (0);
}