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;
int main(){
  long long n;
  bool did=false;
  while(cin >> n){
    if(n==0){
      return 0;
    }
    if(did){
      cout << endl;
    }
    string s[n];
    long long win[n],draw[n],lose[n];
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
      cin >> s[i] >> win[i] >> lose[i] >> draw[i];
      p[i]=make_pair(win[i]*3+draw[i],i);
    }
    sort(p,p+n);
    reverse(p,p+n);
    for(int i=0;i<n;i++){
      bool f=true;
      for(int j=i;j<n;j++){
        if(p[j].first<p[i].first){
          for(int k=j-1;k>=i;k--){
            cout << s[p[k].second] << "," << p[k].first << endl;
          }
          f=false;
          i=j-1;
          break;
        }
      }
      if(f){
        for(int j=n-1;j>=i;j--){
          cout << s[p[j].second] << "," << p[j].first << endl;
        }
        break;
      }
    }
    did=true;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        cout<<endl;
        string str[10];
        int num[10];
        for(int i=0,win,lose,draw;i<n;i++){
            cin>>str[i]>>win>>lose>>draw;
            num[i]=win*3+draw;
            str[i]+=',';
        }
        for(int i=0;i<n;i++){
            int ma=0;
            for(int j=0;j<n;j++)if(num[ma]<num[j])ma=j;
            cout<<str[ma]<<num[ma]<<endl;
            num[ma]=-1;
        }
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	int co=0;
	while(cin>>n,n){
		if(co)cout<<endl;
		co++;
		vector<string>s(n);
		vector<int>in(n);
		rep(i,n){
			int a,b,c;
			cin>>s[i]>>a>>b>>c;
			in[i]=a*3+c;
		}
		rep(i,n)for(int j=n-2;j>=i;j--)if(in[j]<in[j+1]){
			swap(s[j],s[j+1]);
			swap(in[j],in[j+1]);
		}
		rep(i,n)cout<<s[i]<<","<<in[i]<<endl;
	}
}

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

void solve(int n){
  string tm[10];
  vector< pair<int,int> > scr;    
  int a,b,c;

  scr.resize(n);
  for(int i=0;i<n;i++){
    cin>>tm[i]>>a>>b>>c;
    scr[i]=make_pair((-1)*(a*3+c),i);
  }
  sort(scr.begin(),scr.end());
  for(int i=0;i<n;i++)
    cout<<tm[scr[i].second]<<","<<(-1)*scr[i].first<<endl;
}

int main (){

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

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

struct P{
    string name;
    int win;
    int lose;
    int even;
    int total;
    static bool more (const P& left,const P& right){
        return left.total > right.total;
    }
};

int main(){
    int n;
    int cnt;
    bool b = false;
    while(1){
        cnt = 0;
        cin >> n;
        if(n == 0) break;
        if(b) cout << endl;
        else b = true;
        vector <P> data;
        P tmp;
        for(int i=0;i<n;i++){
            cin >> tmp.name >> tmp.win >> tmp.lose >> tmp.even;
            tmp.total = tmp.win*3 + tmp.even;
            data.push_back(tmp);
            cnt++;
        }
        sort(data.begin(),data.end(),P::more);
        for(int i=0;i<cnt;i++){
            cout << data[i].name << "," << data[i].total << endl;
        }
    }
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
struct score{
	string str;
	int win;
	int lose;
	int draw;
	int point;
};

int main(){
	int n;
	struct score team[10];
	while(1){
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>team[i].str>>team[i].win>>team[i].lose>>team[i].draw;
			team[i].point = team[i].win*3 + team[i].draw;
		}
		
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(team[i].point < team[j].point){
					struct score t = team[i];
					team[i] = team[j];
					team[j] = t;
				}
			}
		}

		for(int i=0;i<n;i++){
			cout<<team[i].str<<","<<team[i].point<<endl;
		}
		cout<<endl;
	}
	return 0;
}

C++: #include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,f=0;
	while(cin>>n,n){
		if(f)cout<<endl; f=1;
		pair<int,pair<int,char[20]> > team[10];
		int w,l,d; char nm[20];
		rep(i,n){
			cin>>team[i].second.second>>w>>l>>d;
			team[i].first=-w*3-d;
			team[i].second.first=i;
		}
		sort(team,team+n);
		rep(i,n)cout<<team[i].second.second<<","<<-team[i].first<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,num=0,score[1000];
    while(1){
        cout<<endl;
        num++;
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }
    int max=-10000,count=0,j=0,s;bool bo=false;
    while(1){
        if(count==n){
            break;
        }
        for(int i=0;i<n;i++){
            if(score[i]>max){
                max=score[i];
                s=i;
            }
        }
        cout<<name[s]<<","<<score[s]<<endl;
        count++;
        score[s]=-10;
        max=-10000;
    }
    }
    return 0;
}