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;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> S;
int wa[51][11];
int OK[11];
vector<S> v;

//比較関数
bool comp(S lhs, S rhs){
	if(lhs.first != rhs.first){
		return lhs.first < rhs.first;
	}
	if(lhs.second.first != rhs.second.first){
		return lhs.second.first > rhs.second.first;
	}
	if(lhs.second.second != rhs.second.second){
		return lhs.second.second < rhs.second.second;
	}
}

int main(){
while(1){//start
	
	int M, T, P, R;
	cin >> M >> T >> P >> R;
	if(M == 0 and T == 0 and P == 0 and R == 0) break;

	//初期化
	v.resize(T);
	for(int i = 0; i < 51; i++){
		for(int j = 0; j < 11; j++) wa[i][j] = 0;
	}
	for(int i = 0; i < 11; i ++) OK[i] = 0;
	
	
	//データを格納
	for(int i = 0; i < R; i++){
		int m, t, p, j;
		cin >> m >> t >> p >> j;

		if(j == 0){
			v[t - 1].second.first += m + 20*wa[t][p]; 
			OK[t-1] += 1;
		}
		else{
			wa[t][p] += 1;
		}
	}
	
	//vectorにデータを入れる
	for(int i = 1; i <= T; i++){
		//v.push_back(make_pair(OK[i-1], make_pair(sum_m, i)));
		v[i-1].first = OK[i-1];
		v[i-1].second.second = i;
	}
	
	sort(v.begin(), v.end(), comp);
	reverse(v.begin(), v.end());
	
	//for(int i = 0; i < (int)v.size(); i++) cout << v[i].first << " " << v[i].second.first << " " << v[i].second.second << endl;
	
	
	//出力
	for(int i = 1; i <= (int)v.size(); i++){
		cout << v[i-1].second.second;
		if(i == (int)v.size()) continue;
		else if(v[i-1].first == v[i].first and v[i-1].second.first == v[i].second.first) cout << "=";
		else cout << ",";
	}
	cout << endl;
	v.clear();
}//end	
	return 0;
}

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

typedef struct _team{
    int tid;
    int ac;
    int time;
    _team(){tid=ac=time=0;}
} Team;

bool cmp(Team& a, Team& b){
    if(a.ac == b.ac){
        if(a.time == b.time){
            return a.tid > b.tid;
        }else{
            return a.time < b.time;
        }
    }else{
        return a.ac > b.ac;
    }
}

int main(){
    while(1){
        int m,t,p,r;
        cin >> m >> t >> p >> r;
        if(m==0) break;

        int mi, ti, pi, ji;
        vector<vector<int> > pena(t, vector<int>(p, 0));
        vector<Team> info(t);
        for(int i=0; i<t; i++){
            info[i].tid = i+1;
        }
        
        for(int i=0; i<r; i++){
            cin >> mi >> ti >> pi >> ji;
            ti--;
            pi--;
            if(ji==0){
                info[ti].time = mi;
                info[ti].ac++;
                pena[ti][pi] = -pena[ti][pi];
            }else{
                pena[ti][pi] -= 20;
            }
        }
        for(int i=0; i<t; i++){
            for(int j=0; j<p; j++){
                if(pena[i][j]>0){
                    info[i].time += pena[i][j];
                }
            }
        }

        sort(info.begin(), info.end(), cmp);
        cout << info[0].tid;
        for(int i=1; i<t; i++){
            if(info[i].ac==info[i-1].ac && info[i].time==info[i-1].time){
                cout << "=";
            }else{
                cout << ",";
            }
            cout << info[i].tid;
        }
        cout << endl;
    }
    return 0;
}

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

class Team
{
public:
	int id, penalty, acs;
	vector<int> buffer;

	Team(int id, int problem_number) : id(id), penalty(0), acs(0), buffer(problem_number) { }

	void submit(int m, int p, int j)
	{
		if(!j) {
			acs++;
			penalty += buffer[p] + m;
		} else {
			buffer[p] += 20;
		}
	}
};

bool operator == (const Team& a, const Team& b)
{
	return a.acs == b.acs && a.penalty == b.penalty;
}

bool operator < (const Team& a, const Team& b)
{
	if(a.acs != b.acs) return a.acs > b.acs;
	if(a.penalty != b.penalty) return a.penalty < b.penalty;
	return a.id > b.id;
}

int main()
{
	for(int M, T, P, R; cin >> M >> T >> P >> R && (M||T||P||R); ) {
		vector<Team> teams;

		for(int i = 0; i < T; i++) {
			teams.push_back(Team(i+1, P));
		}

		for(int i = 0; i < R; i++) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			teams[t-1].submit(m, p-1, j);
		}

		sort(teams.begin(), teams.end());

		for(int i = 0; i < T; i++) {
			cout << teams[i].id << (i+1 == T ? '\n' : (teams[i] == teams[i+1] ? '=' : ','));
		}
	}
}