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 a[10];
int p[10];
int main(){
	int n,b,z,c;
	bool first=true;
	while(true){
	cin>>n;
	if(!first)cout<<endl;
	first=false;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b>>z>>c;
		p[i]=b*3+c*1;
	}
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(p[j]>p[j-1]){
				string tmps=a[j];
				a[j]=a[j-1];
				a[j-1]=tmps;
				int tmp=p[j];
				p[j]=p[j-1];
				p[j-1]=tmp;
			}
		}
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<","<<p[i]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;
typedef pair<string,int> P; 

int main(){
  int n;
  bool first = true;
  while(cin >> n && n){
    if(!first)cout << endl;
    string s;
    first = false;  
  vector<P> vec;
    int a,b,c;
    for(int i=0;i<n;i++){
    cin >> s >> a >> b >> c;
    vec.push_back(P(s,a*3+b*0+c*1));
    }

    stable_sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
      cout << vec[i].F << "," << vec[i].S << endl;
    }
 
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <functional>

using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

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(make_pair(w*3+d,s));
		}
		multimap< int, string, greater<int>>::iterator it = P.begin();
		while( it != P.end() )	{
			cout << (*it).first << ":" << (*it).second << endl;
			++it;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <functional>
#include <list>


using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

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).first << ":" << (*it).second << endl;
			++it;
		}
	}
	return 0;
}

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

struct league {
	string name;
	int w, l, d, p;

	bool operator < (const league & rhs) const {
		return p > rhs.p;
	}
};

int main()
{
	int n;

	cin >> n;

	while (n > 0) {
		league sc[10];

		for (int i = 0; i < n; i++) {
			cin >> sc[i].name >> sc[i].w >> sc[i].l >> sc[i].d;
			sc[i].p = sc[i].w * 3 + sc[i].d;
		}

		sort(sc, sc + n);

		for (int i = 0; i < n; i++)
			cout << sc[i].name << "," << sc[i].p << endl;

		cin >> n;

		if (n > 0)
			cout << endl;
	}

	return 0;
}

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

typedef struct
{
  string name;
  int point, index;
} Team;

class GreaterPoint
{
public:
  bool operator() (const Team& lhs, const Team& rhs)
  {
    if (lhs.point == rhs.point)
      return lhs.index < rhs.index;
    return lhs.point > rhs.point;
  }
};

int main()
{
  int n;
  bool first = true;
  while (cin >> n) {
    if (n == 0)
      break;

    if (!first)
      cout << endl;

    vector<Team> team(n);
    for (int i = 0; i < n; ++i) {
      int win, draw;
      cin >> team[i].name >> win >> draw >> draw;
      team[i].point = win*3+draw;
      team[i].index = i;
    }

    sort(team.begin(), team.end(), GreaterPoint());
    for (int i = 0; i < n; ++i)
      cout << team[i].name << "," << team[i].point << endl;
    first = false;
  }
  return 0;
}

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

#define	score	first
#define	id		second

using namespace std;

typedef	pair<int,int>	pii;

bool cmp(const pii& a,const pii& b)
{
	if(a.score>b.score)	return true;
	if(a.score==b.score && a.id<b.id)	return true;
	return false;
}

int main()
{
	int n;

	for(int k=0;cin>>n,n;k++){
		if(k>0)	cout<<endl;

		vector<pii> scvec;
		map<int,string> namemap;

		for(int i=0;i<n;i++){
			string name;
			int w,l,d;
			cin>>name>>w>>l>>d;
			scvec.push_back(make_pair(3*w+d,i));
			namemap[i]=name;
		}

		sort(scvec.begin(),scvec.end(),cmp);

		for(int i=0;i<scvec.size();i++){
			cout<<namemap[scvec[i].id]<<","<<scvec[i].score<<endl;
		}
	}

	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;
    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));
        }
        stable_sort(V.begin(),V.end(),greater<pii>());
        for(int i=0;i<V.size();i++){
            cout<<V[i].S<<","<<V[i].F<<endl;
        }
    }
}

C++: #include<stdio.h>
int main(){
	int n,i,i2,point[10],w,e,l,sum,maxn;
	char team[20][10];
	scanf("%d",&n);
	for(i=0;i!=n;i++){
		scanf("%s%d%d%d",team[i],&w,&e,&l);
		sum=w*3+l;
		point[i]=sum;
	}
	for(i=0;i!=n;i++){
		maxn=0;
		for(i2=0;i2!=n;i2++){
			if(point[i2]>point[maxn]){
				maxn=i2;
			}
		}
		printf("%s, %d\n",team[maxn],point[maxn]);
		point[maxn]=0;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,score[1000];
    while(1){
    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;
}