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<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j;
	int temp,data[10];
	char tn[11][21],temps[21];
	int k,m,h;
	scanf("%d" ,&n);
	while(n!=0){
		for(j=0;j<10;j++){
			data[j]=0;
		}
		for(j=0;j<n;j++){
			scanf("%s %d %d %d",tn[j],&k,&m,&h);
			data[j]+=k*3;
			data[j]+=h;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(data[j]<data[j+1]){
					temp=data[j+1];
					data[j+1]=data[j];
					data[j]=temp;
					strcpy(temps,tn[j+1]);
					strcpy(tn[j+1],tn[j]);
					strcpy(tn[j],temps);
				}
			}
		}
		for(j=0;j<n;j++){
			if(j==n-1){
				printf("%s,%d\n",tn[j],data[j]);
			}
		}
		scanf("%d",&n);
		if(n!=0){
			printf("\n");
		}
	}
	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 <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;
    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);
    REP(i,n){
      cout<<data[i].second<<","<<-data[i].first<<endl;
    }
  }
  
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<string, int> T;

int main() {
  int n;
  bool f = false;
  while (cin >> n, n) {
    string s;
    int w, L, d;
    vector<T> v;
    for (int i = 0; i < n; i++) {
      cin >> s >> w >> L >> d;
      v.emplace_back(s, w * 3 + d);
    }
    sort(v.begin(), v.end(), [](const auto& x, const auto& y) {return x.second > y.second;});
    if (f) cout << "\n";
    for (auto& e : v) {
      cout << e.first << "," << e.second << "\n";
    }
    f = true;
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int n,i,win,draw,lose,point[10],tn;
	string str[10],tstr;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			cin >> str[i] >> win >> lose >> draw;
			point[i] = (win*3)+(draw*1);
		}
		for(i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(point[i] < point[j]){
					tstr = str[i];
					str[i] = str[j];
					str[j] = tstr;
					tn = point[i];
					point[i] = point[j];
					point[j] = tn;
				}
			}
		}
		for(i=0;i<n;i++){
			cout << str[i] << "," << point[i] << endl;
		}
	}
	return 0;
}

C++: // Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
bool flg = false;
while(true){
	int n;
	cin >> n;
if(n==0)  break;
	string T[10];
	int P[10];
	int I[10];
	for(int i=0; i<n; i++){
		cin >> T[i];

		int w, l, d;
		cin >> w >> l >> d;
		P[i] = w*3+d;

		I[i] = i;
	}

	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			if(P[i]<P[j]||(P[i]==P[j]&&I[i]>I[j])){
				string s_tmp = T[i];
				T[i] = T[j];
				T[j] = s_tmp;

				int tmp = P[i];
				P[i] = P[j];
				P[j] = tmp;

				tmp = I[i];
				I[i] = I[j];
				I[j] = tmp;
			}
		}
	}

if(flg)
cout << endl;
else
flg = true;

	for(int i=0; i<n; i++){
		cout << T[i] << ',' << P[i] << '\n';
	}
}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#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;
        priority_queue<pii>Q;
        while(n--){
            cin>>str>>W>>L>>D;
            Q.push(pii(W*3+D,str));
        }
        while(!Q.empty()){
            pii p=Q.top();Q.pop();
            cout<<p.S<<","<<p.F<<endl;
        }
        cout<<endl;
    }
}

C++: #include <iostream>
#include <string>
using namespace std;
struct {string n; int w, l, d, p;} t[10], x;
int main()
{
	int n, i, j;
	while (cin >> n, n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> t[i].n >> t[i].w >> t[i].l >> t[i].d;
			t[i].p = t[i].w * 3 + t[i].d;
		}
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (t[j].p < t[j+1].p)
				{
					x = t[j];
					t[j] = t[j+1];
					t[j+1] = x;
				}
			}
		}
		for (i = 0; i < n; i++)
			cout << t[i].n << "," << t[i].p << endl;
		cout << endl;
	}
}

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

using namespace std ;

typedef pair< int ,string > pay ;

int main()
{
	int n ,dr ;
	cin >> n ;
	while( n )
	{
		pay p[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> p[ i ].second >> p[ i ].first >> dr >> dr ;
			p[ i ].first = p[ i ].first * 3 + dr ;
		}

		sort( p ,p + n ) ;

		for( int i = n - 1 ; i >= 0 ; i-- )
			cout << p[ i ].second << "," << p[ i ].first << endl ;
		if( cin >> n ,n )
			cout << endl ;
	}
	return 0 ;
}

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

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

int main(){
	string s;
	int n, w, l, d, f = 0;
	while(cin >> n, n){
		if(f)cout << endl;f = 1;
		vector<P> v;
		for(int i = 0;i < n;i++){
			cin >> s >> w >> l >> d;
			int x = w*3 + d;
			v.push_back(P(x, s));
		}
		sort(v.begin(), v.end(), comp);
		for(int i = 0;i < n;i++){
			cout << v[i].second << "," << v[i].first << 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&&f) cout<<endl;
		else if (f) break;
		vector<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]);
			}
		}
		for (int i=0; i<n; i++) {
			cout<<m[i].name<<","<<m[i].cost<<endl;
		}
		f++;
	}
}