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;

int main(){

	int n, max_pt, pt[10], win, lose, drow;
	string str[10];

	while(cin >> n){
		if(n == 0) break;
		max_pt = 0;
		for(int i=0; i<n; i++){
			win = 0;
			lose = 0;
			drow = 0;
			cin >> str[i] >> win >> lose >> drow;
			pt[i] = win * 3 + drow;
			max_pt = max(max_pt, pt[i]);
		}
	
		for(int i=max_pt; i>=0; i--){
			for(int j=0; j<n; j++){
				if(pt[j] == i) cout << str[j] << "," << pt[j] << endl;
			}
		}
		cout << endl;
	}

	return 0;

}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct nx { 
string name;
int cost;
};
int main() {
    int n, f=0;
    while (cin>>n) {
        if (!n) break;
        if (f) cout<<endl;
        nx m[n];
        for (int i=0; i<n; i++) {
            cin>>m[i].name;
            int a,b,c; cin>>a>>b>>c;
            m[i].cost=a*3+c*1;
        }
//        for (int i=0; i<n; i++) {
//            for (int j=i+1; j<n; j++) {
//                if (m[i].cost<m[j].cost) swap(m[i],m[j]);
//            }
//        }
        sort(m,m+n);
        for (int i=0; i<n; i++) {
            cout<<m[i].name<<","<<m[i].cost<<endl;
        }
        f++;
    }
}

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;cin>>n;
	while(1){
		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;
		}
		cin>>n;
		if(!n)return 0;
		else cout<<endl;
	}
}

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

struct team{
  int point;
  int mun;
  string name;
};

class LessAn {
public:
    bool operator()(const team& a, const team& b)
    {
      if(a.point==b.point)
        return a.mun < b.mun;
      return a.point > b.point;
    }
};




int main()
{
  bool x=false;
  int n;
  for(;cin>>n,n;)
    {
      if(x)
	cout<<endl;
      else
	x=true;
      vector<team> t;      
      for(int i=1;n--;i++)
      {
	string tt;
	int x,y,z;
	team a;
	cin>>tt>>x>>y>>z;
	a.point=x*3+z;
	a.name=tt;
	a.mun=i;
	t.push_back(a);
      }
      sort(t.begin(), t.end(),LessAn());
	for(int i=0;i<t.size();i++)
	  {
	    cout<<t[i].name<<","<<t[i].point<<endl;
	  }
    }
}

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

using namespace std;

typedef struct {
	int sum;
	char name[20];
} TEAM;

int main()
{
	int n;
	int win, lose, drow;
	bool flg = false;
	TEAM team[10], tmp;

	while (1){
		scanf("%d", &n);

		if (n == 0){
			break;
		}

		for (int i = 0; i < n; i++){
			scanf("%s %d %d %d", team[i].name, &win, &lose, &drow);
			team[i].sum = win * 3 + drow;
		}

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (team[j].sum > team[j - 1].sum){
					tmp = team[j - 1];
					team[j - 1] = team[j];
					team[j] = tmp;
				}
			}
		}

		if (flg == true){
			cout << endl;
		}
		
		flg = true;

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

	return (0);
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

struct team{
    string name;
    int score, id;
};

int main(){
    bool begin = true;
    int n;

    while(cin >> n && n){
        if(!begin) puts("");
        begin = false;

        vector<team> rs(n);
        rep(i,n){
            int a, b, c;
            cin >> rs[i].name >> a >> b >> c;
            rs[i].score = a*3 + c;
            rs[i].id = i;
        }

        sort(all(rs),[](const team& a, const team& b){
                if(a.score != b.score) return a.score > b.score;
                else return a.id < b.id;
            });

        rep(i,n){
            cout << rs[i].name << "," << rs[i].score << endl;
        }
    }

}

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

struct data{

	char name[21];
	int win;
	int lose;
	int draw;
	int score;

};

int main(){

	int teamamo;
	bool check = true;

	while (true){

		cin >> teamamo;

		if (teamamo == 0)
			break;

		data teamdata[10];
		

		for (int i = 0; i<teamamo; i++)
			cin >> teamdata[i].name >> teamdata[i].win >> teamdata[i].lose >> teamdata[i].draw;

		for (int i = 0; i<teamamo; i++)
			teamdata[i].score = teamdata[i].win * 3 + teamdata[i].draw;


		for (int j = 0; j < teamamo - 1; j++){
			for (int i = 0; i < teamamo - 1; i++){

				if (teamdata[i].score < teamdata[i + 1].score){

					data t = teamdata[i];
					teamdata[i] = teamdata[i + 1];
					teamdata[i + 1] = t;

				}

			}


		}

		if (check)
			check = false;
		else
			cout << endl;

		for (int i = 0; i<teamamo; i++)
			cout << teamdata[i].name << "," << teamdata[i].score << endl;

		


	}

	return 0;

}

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

int main()
{
	vector< pair<int, string> > team;

	while (1)
	{
		int n;
		cin >> n;
		if (n == 0) { break; }

		for (int i = 0; i < n; ++i)
		{
			string t;
			int a, b, c;

			cin >> t >> a >> b >> c;

			team.push_back(make_pair(a * 3 + c, t));
		}

		sort(team.begin(), team.end());

		for (int i = team.size() - 1; i >=0; --i)
		{
			cout << team[i].second << "," << team[i].first << endl;
		}

		cout << endl;
	}

	return 0;
}

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

main(){
	string t[21] , tmp ;
	int p[21] , tmp2 ;
	int n , a , b , c ;
	bool r = false ;
	
	while( cin >> n , n ){
		if( r ) cout << endl ;
		r = true ;
		
		map<string,int> x ;
		for( int i=0 ; i<n ; i++ ){
			cin >> t[i] >> a >> b >> c ;
			p[i] = a*3 + c ;
			x[t[i]] = i ;
		}
		
		for( int i=0 ; i<n ; i++ ){
			for( int j=i+1 ; j<n ; j++ ){
				if( p[i] < p[j] || p[i] == p[j] && x[t[i]] > x[t[j]] ){
					tmp = t[i] ;
					t[i] = t[j] ;
					t[j] = tmp ;
					
					tmp2 = p[i] ;
					p[i] = p[j] ;
					p[j] = tmp2 ;
				}
			}
		}
		
		for( int i=0 ; i<n ; i++ ) cout << t[i] << ',' << p[i] << endl ;
	}
}

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

pair<int, string> pa[10];

int main() {
	int N,ff=0;
	while (cin >> N, N) {
		if (ff == 1)cout << endl;
		for (int i = 0; i < N; i++) {
			cin >> pa[i].second;
			int w, l, d;
			cin >> w >> l >> d;
			pa[i].first = w * 3 + d;

		}

		sort(pa, pa + N - 1);

		for (int i = N - 1; i >= 0; i--) {
			cout << pa[i].second << "," << pa[i].first << endl;
		}
		ff = 1;

	}

}