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 <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
vector<pair<int , pair<int, int> > > score(51);
int wrongans[51];

int main()
{
	int M, T, P, R;
	while(1){
		cin >> M >> T >> P >> R;
		if(M == 0 && T == 0 && P == 0 && R == 0) break;
		for(int i = 1; i <= T; i++){
			score[i].first = 0;
			(score[i].second).first = 0;
			(score[i].second).second = -i;
		}
		int wrongans[51][11] = {0};
		int m, t, p, j;
		for(int i = 0; i < R; i++){
			cin >> m >> t >> p >> j;
			if(j == 0){
				score[t].first--;
				(score[t].second).first += m + (20 * wrongans[t][p]);
			} else {
				wrongans[t][p]++;
			}
		}
		sort(score.begin() + 1, score.begin() + T + 1);
		for(int i = 1; i <= T; i++){
			cout << -(score[i].second).second;
			if(i == T) cout << endl;
			else if(score[i + 1].first == score[i].first && (score[i + 1].second).first == (score[i].second).first) cout << '=';
			else cout << ',';
		}
	}
	return 0;
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long 
	while (true) {
		int m, t, p, r;
		cin >> m >> t >> p >> r;
		int penalty[1000][1000] = {};
		tuple<int, int, int> team_info[1000] = {};
		if (m == 0) return 0;
		REP(i, r) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			if (d == 0) {
				//Accepted
				get<0>(team_info[b]) += 1;//AC counter up
				get<2>(team_info[b]) += penalty[c][b];
				get<1>(team_info[b]) += a + penalty[c][b] * 20;
			}
			else {
				penalty[c][b]++;
			}
		}
		vector<tuple<int, int, int>> sortings;//AC,Time,number
		for (int i = 1; i <= t; ++i) {
			sortings.push_back(make_tuple(get<0>(team_info[i]), get<1>(team_info[i]) * -1, i));
		}
		sort(sortings.begin(), sortings.end(), greater<tuple<int, int, int>>());
		queue<int> teaming;
		pair<int, int> now_back = make_pair(-1, -1);
		for (int i = 0; i < sortings.size(); ++i) {
			if (now_back == make_pair(get<0>(sortings[i]), get<1>(sortings[i]))) {
				teaming.push(get<2>(sortings[i]));
			}
			else {
				if (teaming.empty() == false) {
					int ok = 1;
					while (teaming.empty() == false) {
						if (ok == 0) {
							cout << "=";
						}
						ok = 0;
						cout << teaming.front();
						teaming.pop();
					}
					cout << ",";
				}
				teaming.push(get<2>(sortings[i]));
				now_back = make_pair(get<0>(sortings[i]), get<1>(sortings[i]));
			}
		}
		if (teaming.empty() == false) {
			int ok = 1;
			while (teaming.empty() == false) {
				if (ok == 0) {
					cout << "=";
				}
				ok = 0;
				cout << teaming.front();
				teaming.pop();
			}
		}
		cout << endl;
	}
}

C++: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int M, T, P, R;
    while(scanf("%d%d%d%d", &M, &T, &P, &R) && M){
        int time[T][P], sum[T], num[T];
        rep(i, T){
            sum[i] = num[i] = 0;
            rep(j, P) time[i][j] = 0;
        }
        rep(_, R){
            int m, t, p, j;
            scanf("%d%d%d%d", &m, &t, &p, &j);
            --t; --p;
            if(!j){
                sum[t] += time[t][p] + m;
                ++num[t];
            }
            else time[t][p] += 20;
        }
        int ans[T];
        rep(i, T) ans[i] = i;
        auto cmp = [&](const int &a, const int &b){
            if(num[a] == num[b]) return sum[a] == sum[b] ? a > b : sum[a] < sum[b];
            return num[a] > num[b];
        };
        sort(ans, ans+T, cmp);
        string s;
        int l = 0;
        while(l < T){
            int r = l;
            if(!s.empty()) s += ",";
            while(r < T && num[ans[l]]==num[ans[r]] && sum[ans[l]]==sum[ans[r]]){
                if(l != r) s += "=";
                s += to_string(ans[r]+1);
                ++r;
            }
            l = r;
        }
        cout << s << "\n";
    }
}