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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

bool pairCompare(const std::pair<string, int>& firstElem, const std::pair<string, int>& secondElem) {
    return firstElem.second > secondElem.second;
}

int main(){
    int n;
    bool isFirst = true;
    while(cin >>  n, n){
        if(!isFirst) cout << endl;

        vector<pair<string, int> > team;

        for(int i=0; i < n; i++){
            string name; int p, q, r;
            cin >> name >> p >> q >> r;
            team.pb(mp(name, 3*p+r));
        }

        sort(all(team), pairCompare);

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

        isFirst = false;
    }
}

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[29]> > team[10];
		int w,l,d;
		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>
using namespace std;

//勝敗構造体
typedef struct struct_point
{
	int win;
	int loss;
	int drow;
}S_point;

//データ構造体
typedef struct struct_data
{
	char name[21];
	S_point s_point;
	int point;
}S_data;

int main(void)
{
	//入力数
	int n = 0;
	//交換構造体
	S_data s_tmp;
	S_data *ptr_tmp = &s_tmp;

	S_data s_data[10] = {0};

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			return 0;
		}
		for (int i = 0; i < n; i++)
		{
			cin >> s_data[i].name >> s_data[i].s_point.win >> s_data[i].s_point.loss >> s_data[i].s_point.drow;
			s_data[i].point = s_data[i].s_point.win * 3 + s_data[i].s_point.drow;
		}

		//ソート
		for (int i = 0; i < n - 1; i++)
		{
			for (int j = i + 1; j < n; j++)
			{
				if (s_data[i].point < s_data[j].point)
				{
					*ptr_tmp = s_data[i];
					s_data[i] = s_data[j];
					s_data[j] = *ptr_tmp;
				}
			}
		}

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

	return 0;
}

C++: #include <iostream>
using namespace std;
  
struct data{
  
char name;
int win;
int lose;
int draw;
int score;
  
};
  
int main(){
  
int teamamo;
  
while(true){
  
cin>>teamamo;
  
if(teamamo==0)
break;
  
data teamdata[10];
data comp;
  
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 i=0; i<teamamo-1; i++){
  
if(teamdata[i].score<teamdata[i+1].score){
  
char fout; 
fout=teamdata[i].name;
teamdata[i].name=teamdata[i+1].name;
teamdata[i+1].name=fout;
  
int gout;
gout=teamdata[i].win;
teamdata[i].win=teamdata[i+1].win;
teamdata[i+1].win=gout;
  
gout=teamdata[i].lose;
teamdata[i].lose=teamdata[i+1].lose;
teamdata[i+1].lose=gout;
  
gout=teamdata[i].draw;
teamdata[i].draw=teamdata[i+1].draw;
teamdata[i+1].draw=gout;
  
gout=teamdata[i].score;
teamdata[i].score=teamdata[i+1].score;
teamdata[i+1].score=gout;
  
    }
  
  
   }
  
for(int i=0; i<teamamo; i++)
cout<<teamdata[i].name<<','<<teamdata[i].score<<endl;
  
  
 }
  
return 0;
  
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j,k,x,n,setcnt;
	int win,lose,drow;
	char kuni[11][21];
	int tokuten[11];
	setcnt=0;
	while(cin>>n) {
		if(setcnt!=0)cout<<endl;
		for(i=0;i<n;i++) {
			cin>>kuni[i]>>win>>lose>>drow;
			tokuten[i]=win*3+drow;
		}
		for(i=0;i<n;i++) {
			for(j=i+1;j<n;j++) {
				if(tokuten[i]<tokuten[j]) {
					swap(tokuten[i],tokuten[j]);
					swap(kuni[i],kuni[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<kuni[i]<<","<<tokuten[i]<<endl;
		setcnt++;
	}
	return 0;
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct DATA{
  string s;
  int score;
};
int main(){
  int n;
  int cnt=0;
  while(cin>> n,n){
    if(cnt!=0){
      cout<< endl;
    }
    cnt++;
    DATA data[10],temp;
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>> data[i].s>> a>> b>> c;
      data[i].score=a*3+c;
    }

    for(int i=0;i<n;i++){
      for(int j=n-1;j>i;j--){
	if(data[j].score>data[j-1].score){
	  temp=data[j];
	  data[j]=data[j-1];
	  data[j-1]=temp;
	}
      }
    }

    for(int i=0;i<n;i++){
      cout<< data[i].s<< ","<< data[i].score<< endl;
    }
  }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair

using namespace std;

struct Team
{
	int point;
	int num;
	string name;

	bool operator< (const Team& t)const
	{
		return point == t.point ?  num < t.num : point < t.point;
 	}

};

int main()
{
	int n;
	bool fisrt = true;
	while(cin >> n && n)
	{

		if(fisrt)
		{
			fisrt = false;
		}
		else
		{
			cout << endl;
		}
		priority_queue<Team> q;
		string s;
		int a,b,c;
		rep(i,n)
		{
			cin >> s >> a >> b >> c;
			Team t;
			t.point = 3*a + c;
			t.num = 9;
			t.name = s;
			
			q.push(t);
		}

		rep(i,n)
		{
			cout << q.top().point << "," << q.top().name << endl;
			q.pop();
			
		}
		
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair

int main(){
  pair<int,string> data[10];
  int n,d=0;
  while(cin>>n,n){
    if(d!=0)cout<<endl;
    else d=1;
    REP(i,n){
      string s;
      int a,b,c;
      cin>>s>>a>>b>>c;
      data[i]=MP(a*3+c,s);
    }
    sort(data,data+n);
    for(int i=n-1;i>=0;i--){
      cout<<data[i].second<<","<<data[i].first<<endl;
    }
  }
  
}