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 <bits/stdc++.h>
using namespace std;

int main(){
    int M, T, P, R;
    cin >> M >> T >> P >> R;
    while(M > 0){
        vector<pair<pair<int, int>, int>> ans(T);
        for(int i=0; i<T; i++){
            ans[i].first = make_pair(P, 0);
            ans[i].second = -i;
        }
        vector<vector<int>> pen(T, vector<int>(P, 0));
        for(int i=0; i<R; i++){
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--; p--;
            if(j == 0){
                ans[t].first.first--;
                ans[t].first.second += m + pen[t][p];
            }else{
                pen[t][p] += 20;
            }
        }
        sort(ans.begin(), ans.end());
        for(int i=0; i<T; i++){
            cout << -ans[i].second+1;
            if(i<T-1) cout << (ans[i].first == ans[i+1].first ? "=":",");
        }
        cout << endl;

        cin >> M >> T >> P >> R;
    }
}

C++: #include <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

class team
{
public:
	int num;	// number of team
	int cnt;	// solved problems
	int tim;	// total consumed time

	team(void) {};
	team(int _num, int _cnt, int _tim) :
		num(_num), cnt(_cnt), tim(_tim) {};

	friend bool operator == (const team &a, const team &b)
	{
		return a.cnt == b.cnt && a.tim == b.tim;
	}

	friend bool operator < (const team &a, const team &b)
	{
		if (a.cnt != b.cnt)
			return a.cnt > b.cnt;
		else if (a.tim != b.tim)
			return a.tim < b.tim;
		else
			return a.num < b.num;
	}
};

class record
{
public:
	int tim;	// elapsed time
	int num;	// number of team
	int pro;	// problem number
	int jud;	// judgement of submission	

	record(void) {};
	record(int _tim, int _num, int _pro, int _jud) :
		tim(_tim), num(_num), pro(_pro), jud(_jud) {};
};

team tm[55];
record rc[2005];
bitset<15> sl[55];	// if team i solved problem j

signed main(void)
{
	int m, t, p, r;

	while (cin >> m >> t >> p >> r, m || t || p || r)
	{
		for (int i = 1; i <= p; ++i)
			sl[i].reset();
		
		for (int i = 1; i <= r; ++i)
		{
			int ti, ni, pi, ji;
			cin >> ti >> ni >> pi >> ji;
			rc[i] = record(ti, ni, pi, ji);

			if (ji == 0)sl[ni].set(pi);	// team ni solved pi
		}

		for (int i = 1; i <= t; ++i)
			tm[i] = team(i, sl[i].count(), 0);

		for (int i = 1; i <= r; ++i)
		{
			int ti = rc[i].tim;
			int ni = rc[i].num;
			int pi = rc[i].pro;
			int ji = rc[i].jud;

			if (ji == 0)
				tm[ni].tim += ti;
			else if (sl[ni][pi])
				tm[ni].tim += 20;
		}

		sort(tm + 1, tm + 1 + t);

		int stk[55], tot = 0;

		for (int i = 1, j = 1; i <= t; i = j)
		{
			while (j <= t && tm[i] == tm[j])
				stk[++tot] = j++;
			
			cout << tm[stk[tot--]].num;

			while (tot)
				cout << "=" << tm[stk[tot--]].num;

			if (j <= t)
				cout << ",";
			else 
				cout << endl;
		}
	}

//	system("pause");
}

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

typedef struct ICPC{
	int AC;
	int TIME;
	int No;
	int WA[20];
}S;

int M, T, P, R;

int huga(S a, S b){
	if(a.AC > b.AC) return 1;
	else if(a.AC == b.AC){
		if(a.TIME > b.TIME) return 2;
		else if(a.TIME == b.TIME){
			if(a.No > b.No) return 3;
		}
	}
	return false;
}

void Sort(S a[]){
	int v, j;
	S temp;
	for(int i = 2; i <= T; i++){
		j = i-1;
		temp = a[i];
		while(j >= 1 && huga(temp,a[j])){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = temp;
	}
}

int main(){

	while(1){
		S a[100] = {};
		cin>>M>>T>>P>>R;
		if(!M&&!T&&!P&&!P)break;
		for(int i = 1; i <= T; i++)a[i].No = i;
		for(int i = 1,m,t,p,j; i <= R; i++){
			cin>>m>>t>>p>>j;
			if(!j){a[t].AC++;a[t].TIME -= m + a[t].WA[p]*20;}
			else a[t].WA[p]++;
		}
		Sort(a);
		for(int i = 1; i <= T; i++){
			if(i==1)cout<<a[i].No;
			else{
				if(huga(a[i-1],a[i]) == 3) cout<<'='<<a[i].No;
				else cout<<','<<a[i].No;
			}
		}cout<<endl;
	}
	
	return 0;
}