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;

struct teaminfo {
    int team_id;
    int AC_num;
    int WA_num[11];
    int elapsed_time;

    teaminfo(int id) {
        this->team_id = id;
        this->AC_num = 0;
        for (int i = 0; i <= 10; i++) this->WA_num[i] = 0;
        this->elapsed_time = 0;
    }

    bool operator< (const teaminfo& another) const {
        if (this->AC_num == another.AC_num) {
            if (this->elapsed_time == another.elapsed_time) {
                return this->team_id > another.team_id;
            }
            return this->elapsed_time < another.elapsed_time;
        }
        return this->AC_num > another.AC_num;
    }
};

int main(void) {

    int M, T, P, R;
    while (cin >> M >> T >> P >> R, M||T||P||R) {
        vector<teaminfo> teams;
        for (int i = 1; i <= T; i++) {
            teams.emplace_back(i);
        }
        for (int i = 0; i < R; i++) {
            int m, t, p, j; cin >> m >> t >> p >> j; t--;
            if (j) {
                teams[t].WA_num[p]++;
            } else {
                teams[t].AC_num++;
                teams[t].elapsed_time += m + (teams[t].WA_num[p]*20);
            }
        }

        sort(teams.begin(), teams.end());
        cout << teams[0].team_id;
        for (auto i = 1; i < teams.size(); i++) {
            if (teams[i-1].AC_num == teams[i].AC_num && \
                teams[i-1].elapsed_time == teams[i].elapsed_time) {
                cout << '=' << teams[i].team_id;
            } else {
                cout << ',' << teams[i].team_id;
            }
        }
        cout << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
//typedef std::pair<int,int> P;
int D     = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

using namespace std;

int main() {
    int M, T, PP, R;
    while (cin >> M >> T >> PP >> R && M) {
        vector<int> tim(T, 0);                                   //各チームの所用時間
        vector<vector<bool>> solve(T, vector<bool>(PP, false));  //チームごとに各問題が解けたかどうかをboolで
        vector<vector<int>> WA(T, vector<int>(PP, 0));           //チームごとに各問題を何回間違えたか

        rep(i, 0, R) {
            int m, t, p, r;
            cin >> m >> t >> p >> r;
            t--;
            p--;
            if (r == 0) {  //正解したら、その時のmを足してとsolveをtrueに
                solve[t][p] = true;
                tim[t] += m;
            } else
                WA[t][p]++;  //間違えたらWAを増やす
        }

        vector<int> solve_count(T, 0);  //チームごとに結局何問正解できたか
        //２重forで数えます
        rep(i, 0, T) {
            rep(j, 0, PP) {
                if (solve[i][j]) {
                    solve_count[i]++;
                    tim[i] += WA[i][j] * 20;
                }
            }
        }
        vector<pair<int, pair<int, int>>> rank;  //いよいよソートします。この配列は３つの値を持ち、<問題数、時間、チーム番号>で格納。
        /*ソート自体は昇順で行いますが、問題数は降順、時間は昇順、チーム番号は降順でソートしたいので、
        降順にしたいものにはマイナスをつけることで対処します。これにより、元の値が大きいほど値が小さくなるのでうまくいきます。
        */
        rep(i, 0, T) {
            rank.pb(MP(-solve_count[i], MP(tim[i], -(i + 1))));
        }
        Sort(rank);

        /*rep(i,0,T){
            cout<<rank[i].fi<<" "<<rank[i].se.fi<<" "<<-rank[i].se.se<<endl;
        }*/

        //最後に出力です。出力するものはrank[].se.seだけですが、マイナスをつけて格納しているのでマイナスをつけて出力します。
        rep(i, 0, T) {
            if (i) cout << ",";
            cout << -rank[i].se.se;
            while (i + 1 < T && rank[i].fi == rank[i + 1].fi && rank[i].se.fi == rank[i + 1].se.fi) {
                i++;
                cout << "=";
                cout << -rank[i].se.se;
            }
        }
        cout << endl;
    }

    return 0;
}