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>
#define rep(i,n) for(int i=0; i<n; i++)
#define F first
#define S second 
using namespace std;
typedef pair<int,int> Pi;

int main(){
    int M,T,P,R;
    while(cin >> M >> T >> P >> R,M|T|P|R){
        vector<Pi> ST(T);
        vector<vector<int> > cnt(T, vector<int>(P));
        rep(i,R){
            int m,t,p,r;
            cin >> m >> t >> p >> r;
            t--; p--;
            if(r == 0){
                ST[t].F++;
                ST[t].S -= m+20*cnt[t][p];
            }
            else cnt[t][p]++;
        }
        vector<int> num(T);
        iota(num.begin(),num.end(),0);
        reverse(num.begin(),num.end());
		stable_sort(num.begin(),num.end(),[&](int i,int j){return ST[i]>ST[j];});
		cout << num[0]+1;
        for(int i=1; i<T; i++){
            if(ST[num[i]]==ST[num[i-1]]) cout << '=';
            else cout << ',';
            cout << num[i]+1;
        }
        cout << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct{
	int sc;
	int tm;
	int nm;
}status;

int cmp(const void *a, const void *b){
	status *ta = (status *)a;
	status *tb = (status *)b;
	if(ta->sc > tb->sc){
		return -1;
	}
	else if(ta->sc < tb->sc){
		return 1;
	}
	else{
		if(ta->tm < tb->tm){
			return -1;
		}
		else if(ta->tm > tb->tm){
			return 1;
		}
		else{
			if(ta->nm > tb->nm){
				return -1;
			}
			else{
				return 1;
			}
		}
	}
}


int main(void){
	int m, t, p, r, i, j, tn, sm, pn, pena[50][10], sc[50][10];
	status s[50];
	while(1){
		scanf("%d%d%d%d",&m,&t,&p,&r);
		if(m + t + p + r == 0){
			break;
		}
		for(i = 0;i < t;i++){
			s[i].sc = 0, s[i].tm = 0, s[i].nm = i + 1;
		}
		memset(pena,0,sizeof(pena));
		memset(sc,0,sizeof(sc));
		for(i = 0;i < r;i++){
			scanf("%d%d%d%d",&sm,&tn,&pn,&j);
			if(!j){ // 正解のとき
				s[tn - 1].sc++;
				s[tn - 1].tm += sm;
				sc[tn - 1][pn - 1] = 1;
			}
			else{
				pena[tn - 1][pn - 1]++;
			}
		}
		for(i = 0;i < t;i++){
			for(j = 0;j < p;j++){
				if(sc[i][j]){
					s[i].tm += 20 * pena[i][j];
				}
			}
		}
		qsort(s,t,sizeof(s[0]),cmp);
		printf("%d",s[0].nm);
		for(i = 1;i < t;i++){
			if(s[i - 1].sc == s[i].sc && s[i - 1].tm == s[i].tm)
				printf("=");
			else
				printf(",");
			printf("%d",s[i].nm);
		}
		printf("\n");
/*		printf("-----------\n");
		for(i = 0;i < t;i++){
			printf("%d %d %d\n",s[i].sc,s[i].tm,s[i].nm);
		}
		printf("-----------\n");*/
	}
	return 0;
}

C++: #include <bits/stdc++.h>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		int M, T, P, R;
		int tmp1, tmp2;
		int dp[51][11] = {};
		int pos = 50;


		cin >> M >> T >> P >> R;
		if (M == 0) {
			break;
		}
		vector<int>m(R), t(R), p(R), j(R), time(T+1, 0), count(T+1, 0);
		vector< pair<int, int> > res(T);
		FOR(i, 0, R - 1) {
			cin >> m[i] >> t[i] >> p[i] >> j[i];
			if (j[i] == 0) {
				count[t[i]]++;
				time[t[i]] += dp[t[i]][p[i]] * 20 + m[i];
			}
			else {
				dp[t[i]][p[i]]++;
			}
		}
		FOR(i, 0, T - 1) {
			res[i].first = count[i + 1];
			res[i].second = i + 1;
		}
		sort(res.begin(), res.end());

		FOR(i, 0, T-2) {
			FOR(s, i + 1, T - 1) {
				if (res[i].first == res[s].first) {
					if (time[res[i].second] < time[res[s].second]) {
						tmp1 = res[i].second;
						res[i].second = res[s].second;
						res[s].second = tmp1;
					}
					if (time[res[i].second] == time[res[s].second]) {
						if (res[i].second > res[s].second) {
							tmp1 = res[i].second;
							res[i].second = res[s].second;
							res[s].second = tmp1;
						}
					}
				}
			}
		}
		

		bool flag = true;
		bool check = true;
		if (T == 1) {
			cout << 1 << endl;
		}
		else {
			RFOR(i, T - 1, 1) {
				if (res[i].first != res[i - 1].first) {
					if (check == false) {
						cout << "=" << res[i].second;
						check = true;
						continue;
					}
					check = true;
					if (flag == true) {
						cout << res[i].second;
						flag = false;
					}
					else {
						cout << "," << res[i].second;
					}
				}
				else if (time[res[i].second] != time[res[i - 1].second]) {
					if (check == false) {
						cout << "=" << res[i].second;
						check = true;
						continue;
					}
					check = true;
					if (flag == true) {
						cout << res[i].second;
						flag = false;
					}
					else {
						cout << "," << res[i].second;
					}
				}
				else {
					if (flag == true) {
						flag = false;
						if (check == true) {
							cout << res[i].second;
							check = false;
						}
						else {
							cout << "=" << res[i].second;
						}
						
					}
					else {
						if (check == true) {
							cout << "," << res[i].second;
							check = false;
						}
						else {
							cout << "=" << res[i].second;
						}
					}
				}
			}

			if (res[1].first != res[0].first) {
				cout << "," << res[0].second;
			}
			else if (time[res[1].second] != time[res[0].second]) {
				cout << "," << res[0].second;
			}
			else {
				cout << "=" << res[0].second;
			}

			cout << endl;
		}
		
	}
}