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>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;






int main() {
	string s;
	int a, b, c;
	vector<pair<int, string> > v;
	int n;
	bool f = false;
	while (cin >> n && n > 0) {
		v.clear();
		if (f)cout << endl;
		f = true;
		rep(i, n) {
			cin >> s >> a >> b >> c;
			v.push_back(make_pair(a * 3 + c, s));
		}
		sort(all(v));
		reverse(all(v));
		rep(i, n) {
			cout << v[i].second << "," << v[i].first << endl;
		}
	}
}

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

int main(){
    int n;
    while(cin >> n, n){
        string s[10];
        vector<int> d, e;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> s[i] >> a >> b >> c;
            d.push_back(3 * a + c);
        }
        e = d;
        sort(d.begin(), d.end());
        reverse(d.begin(), d.end());
        bool f[10] = {0};
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(d[i] == e[j] && f[j] == false){
                    f[j] = true;
                    cout << s[j] << "," << d[i] << endl;
                    break;
                }
            }
        }
    }
}

C++: #include <functional>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}

		multimap<int, string, greater<int> > team;
		for(int i=0; i<n; i++) {
			int a, b, c;
			char s[32];
			cin >> s >> a >> b >> c;
			team.insert(map<int, string>::value_type((3*a+c), s));
		}
		
		multimap<int, string, greater<int> >::iterator it=team.begin();
		while(it!=team.end()) {
			cout << (*it).second << "," << (*it).first << endl;
			it++;
		}
	}

	return 0;

}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int main(){
    int n,l=0;
    while(cin>>n,n){
        if(l)cout<<endl;l++;
        map<int,vector<string> >m;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            m[3*a+c].push_back(s);
        }
        for (map<int,vector<string> >::reverse_iterator it=m.rbegin(); it!=m.rend(); ++it){
            vector<string>v=it->second;
            for(int i=0;i<v.size();i++){
                cout<<it->first<<","<<v[i]<<endl;
            }
        }
    }
}

C++: #include<iostream>
#include<complex>
#include<cstring>
#include<sstream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<vector>
#include<string>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<functional>
#include<algorithm>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
typedef pair<int,string> P;
int main(){
	int n,x,y,z,now=0;
	vector<P> tab;
	string s;
	while(cin>>n,n){
		if(now!=0)
		cout<<endl;
		rep(i,n){
			cin>>s>>x>>y>>z;
			tab.push_back(P(x*3+z,s));
		}
		stable_sort(tab.begin(),tab.end(),greater<P>());
		vector<P>::iterator ite=tab.begin();
		while(ite!=tab.end()){
			cout<<(*ite).second<<','<<(*ite).first<<endl;
			ite++;
		}
		tab.clear();
		now++;
	}
	return 0;
}

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

using namespace std;

int main(void){
	while(1){
		int a,n;
		string s;
		multimap<int,string,greater<int>> P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		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).second << "," << (*it).first << endl;
			++it;
		}

	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef struct{
  char name[20];
  int kati;
  int make;
  int hiki;
  int total;
}BU;
int main(){
  BU t[10];
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin>>t[i].name>>t[i].kati>>t[i].make>>t[i].hiki;
      t[i].total=0;
      t[i].total+=t[i].kati*3+t[i].hiki;
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(t[j].total>t[j-1].total){
	  BU tmp=t[j];
	  t[j]=t[j-1];
	  t[j-1]=tmp;
	}
      }
    }
    for(int i=0;i<n;i++){
      cout<<t[i].name<<','<<t[i].total<<endl;
    }
    cout<<endl;
  }
}

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

int main(){
  string str[11],str2;
  int N;
  int po[11][4],sc[11],T;

  while(1){
  cin>>N;
  if(N==0) break;

  for(int i=0;i<N;i++){
    cin>>str[i];
    for(int j=0;j<3;j++){
      cin>>po[i][j];
    }
  }


  for(int i=0;i<N;i++){
    sc[i]=po[i][0]*3+po[i][2];
  }
  
  for(int i=0;i<N-1;i++){
    for(int j=N-1;j>i;j--){
      if(sc[j-1]<sc[j]){
	T=sc[j];
	sc[j]=sc[j-1];
	sc[j-1]=T;
	str2=str[j-1];
	str[j-1]=str[j];
	str[j]=str2;
      }
    }
  }

for(int i=0;i<N;i++){
  cout<<str[i]<<","<<sc[i]<<endl;
 } cout<<endl;

  }
return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,N,a,b,c,OZA[10],t;
	char S[20][20],T[20];
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%s %d %d %d",S[i],&a,&b,&c);
		OZA[i] = 3 * a + c;
	}
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			if(OZA[i] < OZA[j]){
				strcpy(T,S[i]);
				strcpy(S[i],S[j]);
				strcpy(S[j],T);
				t = OZA[i];
				OZA[i] = OZA[j];
				OZA[j] = t;
			}
		}
	}
	for(i=0;i<N;i++){
		printf("%s,%d\n",S[i],OZA[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef pair<pair<int, int>, string> p;
int main() {
	int n; bool b = false;
	while (cin >> n, n) {
		if (b)cout << endl;
		p l[11];
		for (int i = 0; i < n; i++) {
			cin >> l[i].second;
			int a, b, c; cin >> a >> b >> c;
			l[i].first = make_pair(a * 3 + c, n - i);
		}
		sort(l, l + n);
		for (int i = n - 1; i >= 0; i--) {
			cout << l[i].second << ',' << l[i].first.first << endl;
		}
		b = true;
	}
}