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 <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};

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

		vector<vector<int>> status(t, vector<int>(p));
		vector<tuple<int, int, int>> results;
		for (int i = 0; i < t; i++)results.emplace_back(make_tuple(0, i, 0));

		for (int i = 0; i < r; i++) {
			int mi, ti, pi, ji;
			cin >> mi >> ti >> pi >> ji;
			if (ji == 0) {
				get<0>(results[ti - 1]) += mi + status[ti - 1][pi - 1] * 20;
				get<2>(results[ti - 1])++;
			}
			else {
				status[ti - 1][pi - 1]++;
			}
		}

		stable_sort(results.begin(), results.end(),
			[](auto a,auto b) {
				int delta0 = get<0>(a) - get<0>(b);
				int delta1 = get<1>(a) - get<1>(b);
				int delta2 = get<2>(a) - get<2>(b);
				if (delta2 == 0) {
					if (delta0 == 0)return delta1 > 0;
					else return delta0 < 0;
				}
				else return delta2 > 0;
			}); 
		for (int i = 0; i < t; i++) {
			if (i > 0) {
				if (get<0>(results[i]) == get<0>(results[i - 1]))cout << '=';
				else cout << ',';
			}
			cout << get<1>(results[i]) + 1;
		}
		cout << endl;
	}
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int M, T, P, R;

struct Team {
    Team () {}
    Team (int p) : bads(p), solved(0), score(0){}
    
    VI bads;
    int solved;
    int idx;

    int score;

    bool operator < (const Team &t) const { // greater
        if (solved != t.solved) return solved > t.solved;
        if (score != t.score) return score < t.score;
        return idx > t.idx;
    }

    bool same(const Team &t) {
        return score == t.score && solved == t.solved;
    }
};

vector<Team> teams;

int main(void) {
    while (cin >> M >> T >> P >> R, M) {
        teams.clear();
        teams.resize(T, Team(P));
        for (int i = 0; i < T; i++) {
            teams[i].idx = i + 1;
        }

        for (int i = 0; i < R; i++) {
            int time, ti, pi, judge;
            cin >> time >> ti >> pi >> judge;

            --ti;
            --pi;

            if (judge) { // ?????£?§£
                teams[ti].bads[pi]++;
            } else {    // ??£?§£
                teams[ti].solved++;
                teams[ti].score += time + teams[ti].bads[pi] * 20;
            }
        }

        sort(ALL(teams));

        // output
        for (int i = 0; i < T; i++) {
            cout << teams[i].idx;
            if (i == T - 1) {
                cout << endl;
            } else {
                cout << (teams[i].same(teams[i + 1]) ? "=" : ",");
            }
        }
    }

	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int x[100][2], y[100][10], n, a, b, c, d, e, f, g, h, p;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		cin >> n >> a >> b >> c;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < c; i++) {
			cin >> d >> e >> f >> g;
			if (g) {
				y[e][f] += 20;
			}
			else {
				x[e][1] += d + y[e][f];
				x[e][0]++;
			}
		}
		p = 0;
		for (int i = 10; i >= 0; i--) {
			for (int j = 0; j <= 1000; j++) {
				h = 0;
				for (int k = a; k > 0; k--) {
					if (x[k][0]==i && x[k][1]==j) {
						if (h >= 1) {
							cout << '=';
						}
						else if (p >= 1) {
							cout << ',';
						}
						cout << k;
						p++;
						h++;
					}
				}
			}
		}
		cout << endl;
	}
}