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 <vector>
#include <algorithm>
using namespace std;
struct nx { 
string name;
int cost;
};
class Comp {
	public:
		bool operator() (const nx& a, const nx& b) {
			return a.cost > b.cost;
		}
};
int main() {
	int n;
	while (cin>>n) {
		if (n) cout<<endl;
		else 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;
		}
		sort(m.begin(), m.end(), Comp());
		for (int i=0; i<n; i++) {
			cout<<m[i].name<<","<<m[i].cost<<endl;
		}
	}
}

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

using namespace std;

typedef pair<int, string> T;

int main()
{
    int n;
    bool fst = true;
    while(cin >> n && n) {
        if(fst) {
            fst = false;
        } else {
            cout << endl;
        }
        vector<T> vt;
        string name;
        int a,b,c;
        while(n--) {
            cin >> name >> a >> b >> c;
            vt.push_back(T(a * 3 + c, name));
        }
        
        stable_sort(vt.begin(), vt.end(), greater<T>());
        for(int i = 0; i < vt.size(); i++) {
            cout << vt[i].second << "," << vt[i].first << endl;
        }
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,score[1000];
    while(1){
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }
    int max=-10000,count=0,j=0,s;bool bo=false;
    while(1){
        if(count==n){
            break;
        }
        for(int i=0;i<n;i++){
            if(score[i]>max){
                max=score[i];
                s=i;
            }
        }
        cout<<name[s]<<","<<score[s]<<endl;
        count++;
        score[s]=-10;
        max=-10000;
    }
        cout<<endl;
    }
    return 0;
}

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

int main() {
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		map<double, string>s;
		auto c = 0.01;
		for (int b = 0; b < a; b++) {
			string d; double e, f, g;
			cin >> d >> e >> f >> g;
			s.insert(pair<double, string>((e * 3 + f * 0 + g * 1 + (1 - c)), d));
			c+=0.01;
		}
		for (auto i = s.end();; i--) {
			if (i == s.end())i--;
			cout << i->second << "," <<(int)(i->first) << endl;
			if (i == s.begin())break;
		}
		cout << endl;
	}
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
string s[11];
int w[11], l[11], d[11], p[11];
bool used[11];


bool f;
int main() {
	while (cin >> n&&n) {
		if (f)cout << endl;;
		f = true;
		REP(i, n) {
			used[i] = false;
			cin >> s[i] >> w[i] >> l[i] >> d[i];
			p[i] = 3 * w[i] + d[i];
		}
		REP(i, n) {
			int maxp = -2;
			string maxc;
			int maxj = 0;
			REP(j, n) {
				if (maxp < p[j]&&!used[j]) {
					maxp = p[j];
					maxc = s[j];
					maxj = j;
				}
			}
			cout << maxc << "," << maxp << endl;
			used[maxj] = true;
		}
	}
}

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

typedef pair<int,int> P;
typedef pair<P,string> PP;

int main(void)
{

	int n;
	bool k = false;

	while(cin >> n,n){
		if(k)
			cout << endl;
	int win,lost,draw;
	PP team[10] = {};
	for(int i = 0; i < n; i++){
		cin >> team[i].second;
		cin >> win >> lost >> draw;
		team[i].first.first = win*3+draw;
		team[i].first.second= 10-i;
	}
	sort( team, team+10 );

	for(int i = 9; 10-i <= n; i--)
		cout << team[i].second << ',' << team[i].first.first << endl;


		k = 1;
	}


	return 0;
}

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

struct C {
  int s;
  int i;
  
  static bool greater(const C &l, const C &r) {
    return l.s > r.s;
  }
};

int main() {
  char country[10][21];
  C obj[10];
  int n, a, b, c;
  bool flg = false;
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      scanf("%s %d %d %d\n", country[i], &a, &b, &c);
      obj[i].s = 3*a+c;
      obj[i].i = i;
    }
    stable_sort(obj, obj+n, C::greater);
    if (!flg) {
      flg = true;
    } else {
      printf("\n");
    }
    for (int i=0; i<n; i++) {
      printf("%s,%d\n", country[obj[i].i], obj[i].s);
    }
  }
  return 0;
}

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

using namespace std;

struct Team {
	string name;
	int score;
};

int main() {

	int n;

	while (cin >> n && n != 0) {

		Team *team = new Team[n];
		int w, l, d;

		for (int i = 0; i < n; i++) {

			cin >> team[i].name >> w >> l >> d;
			team[i].score = w * 3 + d * 1;


		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (team[i].score > team[j].score)
					swap(team[i], team[j]);
			}
		}

		for (int i = 0; i < n; i++)
			cout << team[i].name << "," << team[i].score << "\n";

		cout << "\n";

	}


	return 0;

}

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

struct Country{string name; int wp;};
vector<Country> Allteam;

bool comp(const Country& c1, const Country& c2){
  return (c1.wp > c2.wp);
}

int main(void){
  int n;
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      string tname;
      int w, l, d;
      cin >> tname >> w >> l >> d;
      Country c = {tname, w * 3 + d};
      Allteam.push_back(c);
    }
    sort(Allteam.begin(), Allteam.end(), comp);
    for(int i = 0; i < Allteam.size(); i++){
      cout << Allteam[i].name << "," << Allteam[i].wp << endl;
    }
    cout << endl;
    Allteam.clear();
  }
  return 0;
}