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<string>
using namespace std;
string s[1000000];
int a[1000000][3], score[1000000];
int n;
int main() {
	while (true) {
		cin >> n;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> s[i] >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
			score[i] = a[i][0] * 3 + a[i][1];
		}
		for (int j = 1000000; j >= 0; j--) {
			for (int k = 0; k < n; k++) {
				if (score[k] == j) {
					cout << s[k] << ',' << score[k] << endl;
				}
			}
		}
	}
}

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()
{
	bool first=true;
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n==0)break;
		if(!first) cout << endl;
		else first=false;
		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>
using namespace std;
string s[1000000];
int a[1000000][3], score[1000000];
int n;
int main() {
	while (true) {
		cin >> n;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> s[i] >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
			score[i] = a[i][0] * 3 + a[i][1];
		}
		for (int j = 100000; j >= 0; j--) {
			for (int k = 0; k < n; k++) {
				if (score[k] == j) {
					cout << s[k] << ',' << score[k] << endl;
				}
			}
		}
	}
}

C++: #include <iostream>
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int N;
typedef pair<int, int> P;
vector<string> mp;
vector<P> wp;

int comp(P a, P b) {
	return a.second > b.second;
}

int main() {
	while (true) {
		cin >> N;
		if (N == 0) {return 0;}
		mp.clear();
		wp.clear();
		for (int i = 0; i < N; i++) {
			string country;
			cin >> country;
			int w, d, l;
			cin >> w >> l >> d;
			mp.push_back(country);
			wp.push_back(P(i, 3 * w + d));
		}
		stable_sort(wp.begin(), wp.end(), comp);
		for (int i = 0; i < wp.size(); i++) {
			cout << mp[wp[i].first] << "," << wp[i].second << endl;
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;


int main(){
	int n;
	while(cin >> n&&n){
		vector<string> name;
		vector<int> point;
		
		for(int i=0; i<n; ++i){
			int win,lose,draw;
			string s;
			cin >> s >> win >> lose >> draw;
			name.push_back(s);
			point.push_back(win*3+draw);
		}
		
		for(int i=1; i<n; ++i){
			string s_tmp=name[i];
			int i_tmp=point[i];
			int j;
			for(j=i; ; --j){
				if(j==0||point[j-1]>=i_tmp) break;
				point[j]=point[j-1];
				name[j]=name[j-1];
			}
			point[j]=i_tmp;
			name[j]=s_tmp;
		}
		
		for(int i=0; i<n; ++i){
			cout << name[i] << "," << point[i] << "\n";
		}
	}
}

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

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;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

struct Team{
	string name;
	int n,s;
	bool operator <(const Team t)const{
		if(s==t.s) return n<t.n;
		return s>t.s;
	}
};

int main(){
	Team T[10];
	int N,W,L,D;
	for(int ds=0; cin>>N,N; ds++){
		if(ds!=0) puts("");
		for(int i=0;i<N;i++){
			cin>>T[i].name>>W>>L>>D;
			T[i].n = i; T[i].s = W*3+D;
		}
		sort(T,T+N);
		for(int i=0;i<N;i++){
			cout<<T[i].name;
			printf(",%d\n",T[i].s);
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(!n)break;
		vector<pair<int,string> > teams;
		for(int i=0,w,l,d;i<n;++i){
			string team;
			cin>>team>>w>>l>>d;
			teams.push_back(make_pair(w*3+d*1,team));
		}
		stable_sort(teams.begin(),teams.end());
		for(vector<pair<int,string> >::reverse_iterator it=teams.rbegin();it!=teams.rend();++it) printf("%s,%d\n",(*it).second.c_str(),(*it).first);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,string>P;

int main() {
	int n;
	while(cin>>n,n){
		vector<P>v;
		rep(i,n){
			string s;int a,b,c;
			cin>>s>>a>>b>>c;
			v.push_back(P(a*3+c*1,s));
		}
		stable_sort(v.begin(),v.end(),[](P a,P b){return a.first>b.first;});
		for(P p:v){
			cout<<p.second<<','<<p.first<<endl;
		}
	}
}