Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		M, T, P, R := io.NextInt(), io.NextInt(), io.NextInt(), io.NextInt()
		if M == 0 {
			break
		}
		score := make([]struct{ num, time, index int }, T)
		submit := make([][]int, T)
		for i := 0; i < T; i++ {
			score[i].index = i + 1
			submit[i] = make([]int, P)
		}

		for i := 0; i < R; i++ {
			m, t, p, j := io.NextInt(), io.NextInt()-1, io.NextInt()-1, io.NextInt()
			if j == 0 {
				score[t].num++
				score[t].time += submit[t][p]*20 + m
			} else {
				submit[t][p]++
			}
		}
		sort.SliceStable(score, func(i, j int) bool {
			return score[i].num < score[j].num || score[i].num == score[j].num && score[i].time > score[j].time
		})

		for i := T - 1; i > 0; i-- {
			io.Printf("%d", score[i].index)
			if score[i].num == score[i-1].num && score[i].time == score[i-1].time {
				io.Printf("=")
			} else {
				io.Printf(",")
			}
		}
		io.Println(score[0].index)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
struct team{
    int tID;
    int pID;        //問題ID
    vector<int> p;  //誤答数
    int ansnum;     //正答数
    int time;       //時間
	int place;
 
    bool operator<( const team& right ) const {
        return ( ansnum == right.ansnum ? 
            (time == right.time ? tID < right.tID : time > right.time) 
			: ansnum < right.ansnum );
    }
	bool operator==( const team& right ) const {
        return ( ansnum == right.ansnum ? 
            time == right.time : false );
    }
};
 
int main(void){
  //  FILE* fp_in = freopen("data.txt", "r", stdin);
 
    while(1) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;
        if( M == 0 && T == 0 && P == 0 && R == 0 ) break; 
 
        //■■■■チームテーブル作成■■■■
        vector<team> teams;
        team newteam;
        for(int i = 0; i <= P; i++)
            newteam.p.push_back(0);
 
        for(int i = 0; i < T; i++) {
            newteam.tID = i + 1;
            newteam.ansnum = 0;
			newteam.time = 0;
            teams.push_back( newteam );
        }
 
        //■■■■レコード取得■■■■
        for(int i = 0; i < R; i++) {
            int tID, pID, time_i, j;
            cin >> time_i >> tID >> pID >> j;
           
			if( j == 0 ) {
				teams.at(tID - 1).ansnum ++;
				teams.at(tID - 1).time += time_i + 20 * teams.at(tID - 1).p.at(pID);
			} else {
				teams.at( tID - 1 ).p.at( pID ) ++;
			}

        }

        sort( teams.begin(), teams.end() );
		
		cout << teams.at(teams.size() - 1).tID;
		for(int i = teams.size() - 2; i >= 0 ; i--) {
			if( teams.at(i) == teams.at(i + 1) ) {
				cout << "=" << teams.at(i).tID;
			} else {
				cout << "," << teams.at(i).tID;
			}
		}
		cout << endl;
 
    }
 
   // while(1){}
 
    return 0;
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

list<int> Prime(int num) {
	list<int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (j*j > i) {
				break;
			}
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if (j*j > i + 2) {
				break;
			}
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> M >> N >> L >> R;
	while (M) {
		vector<pair<pair<int, int>, int>>score(N + 1);
		for (int i = 1; i <= N; i++) {
			score[i].second = i;
		}
		vector<vector<int>>WA(N + 1, vector<int>(M + 1));
		for (int i = 0; i < R; i++) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			if (d) {
				WA[b][c]++;
			}
			else {
				score[b].first.first++;
				score[b].first.second -= a;
				score[b].first.second -= WA[b][c] * 20;
			}
		}
		sort(score.begin(), score.end());
		reverse(score.begin(), score.end());
		pair<int,int> box = { -1,0 };
		for (auto i : score) {
			if (i.second==0) {
				continue;
			}
			if (box.first == -1) {
				cout << i.second;
				box = { i.first.first,i.first.second };
			}
			else {
				if (box == make_pair(i.first.first, i.first.second)) {
					cout << "=" << i.second;
				}
				else {
					cout << "," << i.second;
					box = { i.first.first,i.first.second };
				}
			}
		}
		cout << endl;
		cin >> M >> N >> L >> R;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef pair<int,pair<int,int> > triple;
#define mkt(i,j,k) make_pair((i),make_pair((j),(k)))
#define solved first
#define time second.first
#define teamid second.second 

const int MAX_T=50;
const int MAX_P=10;
int wa[MAX_T][MAX_P];
triple team[MAX_T];

int main(){ _;
  int M,T,P,R,m,t,p,j;
  while(cin>>M>>T>>P>>R,(M|T|P|R)!=0){
    REP(i,MAX_T)REP(j,MAX_P)wa[i][j]=0;
    REP(i,MAX_T)team[i]=mkt(0,0,i);
    REP(i,R){
      cin>>m>>t>>p>>j;
      t--;p--;
      if(j==0){
	team[t].solved++;
	team[t].time-=m+wa[t][p]*20;
      }
      else{
	wa[t][p]++;
      }
    }
    sort(team,team+T,greater<pair<int,pair<int,int> > >());
    int cursolved=team[0].solved;
    int curtime=team[0].time;
    cout<<team[0].teamid+1;
    for(int i=1;i<T;i++){
      cout<<((cursolved==team[i].solved&&curtime==team[i].time)?"=":",")<<team[i].teamid+1;
      cursolved=team[i].solved;
      curtime=team[i].time;
    }
    cout<<endl;
  }
}