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<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef struct{
    string cry;
    int po;
}To;
 
int main(){
    int i,j,n,c=0;
    while(cin>>n&&n){
        if(c)cout<<endl;
        c++;
        To t[n];
        for(i=0;i<n;i++){
            int w,l,d;
            cin>>t[i].cry>>w>>l>>d;
            t[i].po=w*3+d;
        }
        for(i=0;i<n-1;i++){
            for(j=0;j<n-1;j++){
                if(t[j].po<t[j+1].po){
                    To tmp=t[j];
                    t[j]=t[j+1];
                    t[j+1]=tmp;
                }
            }
        }
        for(i=0;i<n;i++){
            cout<<t[i].cry<<","<<t[i].po<<endl;
        }
    }
    return 0;
}

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

struct TA{
string name;
int po;
int rr;};


int main(){
int n;
struct TA N[11]; 
while(1){
scanf("%d",&n);if(n==0)break;
for(int i=0;i<n;i++)
{cin>>N[i].name;
int a,b,c;
cin>>a>>b>>c;
N[i].po=a*3+c*1;
N[i].rr=i;
}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(N[j].po>N[j-1].po){struct TA T=N[j];N[j]=N[j-1];N[j-1]=T;}

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




}
return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pint pair<string, int>
bool desc(pint a, pint b) {
	return a.second > b.second;
}
int main() {
	int n;
	bool f = 0;
	while(cin >> n, n) {
		if(f) cout << endl;
		f = 1;
		vector<pint> v;
		rep(i,n) {
			string t;
			int tmp, s = 0;
			cin >> t;
			cin >> tmp;
			s += tmp * 3;
			cin >> tmp;
			cin >> tmp;
			s += tmp;
			v.push_back(make_pair(t,s));
		}
		sort(v.begin(), v.end(), desc);
		for(pint p : v) {
			cout << p.first << "," << p.second << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>

typedef struct{
	char name[30];
	int ten;
}team;

int main(){
	int n,i,j,k,m,h,f;
	team soccer[10],t;
	f=1;
	while(~scanf("%d",&m)){
		if(m==0)break;
		if(f!=1)printf("\n");
		f=2;
		for(i=0;i<m;i++){
			scanf(" %s %d %d %d ",soccer[i].name,&k,&n,&h);
			soccer[i].ten=3*k+h;
		}
		
		for(i=0;i<m;i++){
			for(j=0;j<m-1;j++){
				if(soccer[j].ten<soccer[j+1].ten){
					t=soccer[j];
					soccer[j]=soccer[j+1];
					soccer[j+1]=t;
				}
			}
		}
		for(i=0;i<m;i++){
			printf("%s,%d\n",soccer[i].name,soccer[i].ten);
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <utility>
#include <string>
#include <iostream>

using namespace std;

struct team{
    string s;
    int input, point;
};

int main()
{
    bool first = 1;
    while( 1 )
    {
        int n;
        scanf( "%d", &n );
        if( n == 0 ) break;
        if( !first )
        {
            printf( "\n" );
        }
        else
        {
            first = 0;
        }
        team p[10];
        int i = 0;
        while( i < n )
        {
            string s;
            cin >> s;
            int w,l,d;
            cin >> w >> l >> d;
            p[i].s = s;
            p[i].point = 3 * w + d;
            p[i].input = i;
            i++;
        }
        for( int j = 0; j < n; j++ )
        {
            for( int k = j; k < n; k++ )
            {
                if( p[j].point < p[k].point )
                {
                    swap( p[j], p[k] );
                }
            }
        }
        for( int j = 0; j < n; j++ )
        {
            for( int k = j; k < n; k++ )
            {
                if( p[j].point == p[k].point && p[j].input > p[k].input )
                {
                    swap( p[j], p[k] );
                }
            }
        }
        for( int j = 0; j < n; j++ )
        {
            cout << p[j].s << ',' << p[j].point << '\n';
        }
    }   
    return 0; 
}

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


using namespace std;
typedef pair<string,int> P; 
bool cmp(const P &p,const P &q){
  if(p.S != q.S)return p.S > q.S;
}

int main(){
  int n;
  while(cin >> n && n){
    string s;
    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;
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
	int a,b[9],c[9],d[9],f[9];
	string n[9];
	while(1){
		cin >> a >> endl;
		for(int i = 0; i < a i++){
			cin >> b[i] >> c[i] >> d[i];
		}
		if(a == 0)break;
		for(int i = 0 ; i < a ; i++){
			cin >> n[i] >> b[i] >> c[i] >> d[i];
			f[i] = b[i]*3 + c[i]*0 + d[i]*1;
			n[i] == f[i];
		}
		}
		sort(f.begin(), f + a.end());
		for(int i = 0 ; i < a ; i++){
		cout << n[i] << "," << f[i] << endl;
		}

	return 0;
}

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

using namespace std;

int main()
{
    int n;
    int cnt = 0;

    while (cin >> n) {
        if (!n)
            break;
        if (cnt++)
            cout << endl;

        vector< pair<int, string> > tourn;

        for (int i = 0; i < n; i++) {
            int win, los, ev;
            string str;
        
            cin >> str >> win >> los >> ev;
            pair<int, string> p(win * 3 + ev, str);
            tourn.push_back(p);
        }
        stable_sort(tourn.rbegin(), tourn.rend());
        
        for (int i = 0; i < tourn.size(); i++)
            cout << tourn[i].second << ',' << tourn[i].first << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;
int main()
{
    pair<int,pair<int,string>> team[10];
	int n;
	bool first=true;
	while(cin>>n&&n){
		if(!first)cout<<endl;
		for(int i=0;i<n;i++){
			int k,m,h;
			cin>>team[i].second.second>>k>>m>>h;
			team[i].first=k*3+h;
			team[i].second.first=-i;
		}
		sort(team,team+n,greater<pair<int,pair<int,string>>>());
		for(int i=0;i<n;i++){
			cout<<team[i].second.second<<","<<team[i].first<<endl;
		}
		first=false;
	}
    return 0;
}