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 <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
main(){
	int M,T,P,R,m,t,p,j,ac,time;
	for(;scanf("%d%d%d%d",&M,&T,&P,&R),M;puts("")){
		map<int,pair< //team number
			map<int,int>, //problem, accepted_time
			map<int,int>  //problem, wrong_answer
		> >contest;
		for(;R--;){
			scanf("%d%d%d%d",&m,&t,&p,&j);
			if(j){ //wrong_answer
				contest[t].second[p]+=20;
			}else{
				contest[t].first[p]=m;
			}
		}
		vector<pair<pair<int,int>,int> >contestants;
		for(t=1;t<=T;t++){
			ac=time=0;
			map<int,int>::iterator it=contest[t].first.begin();
			for(;it!=contest[t].first.end();it++){
				ac++;
				time+=it->second+contest[t].second[it->first];
			}
			contestants.push_back(make_pair(make_pair(-ac,time),-t));
		}
		sort(contestants.begin(),contestants.end());
		printf("%d",-contestants[0].second);
		for(t=1;t<T;t++){
			printf(
				contestants[t].first.first==contestants[t-1].first.first &&
				contestants[t].first.second==contestants[t-1].first.second ? "=%d" : ",%d",
				-contestants[t].second
			);
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

        vector<vector<int>> solved(t, vector<int>(3));
        for (int i = 0; i < t; i++)solved[i] = {0, 1145141919, i};
        vector<vector<int>> penalty(t, vector<int>(p));
        for (int i = 0; i < r; i++) {
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            b--;
            c--;
            if (d == 0) {
                solved[b][0]++;
                solved[b][1] -= a + penalty[b][c] * 20;
            } else {
                penalty[b][c]++;
            }
        }

        sort(solved.begin(), solved.end(), greater<>());

        for (int i = 0; i < t - 1; i++) {
            cout << solved[i][2] + 1;
            if (solved[i][0] != solved[i + 1][0] || solved[i][1] != solved[i + 1][1])cout << ",";
            else cout << "=";
        }
        cout << solved[t - 1][2] + 1 << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  while(true) {
    int m, t, p, r;
    cin >> m >> t >> p >> r;
    if(!m && !t && !p && !r) break;
    VVI rec;
    REP(i, r) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      rec.PB({a, b, c, d});
    }
    int wa[55][15] = {0};
    VVI ac;
    REP(i, t) ac.PB({0, 0, (int)i+1});
    REP(i, r) {
      //??£?§£
      if(!rec[i][3]) {
        ac[rec[i][1]-1][0]++;
        ac[rec[i][1]-1][1] += wa[rec[i][1]-1][rec[i][2]] * 20 + rec[i][0];
      } else {
        wa[rec[i][1]-1][rec[i][2]]++;
      }
    }
    REP(i, t) {
      ac[i][0] *= -1;
      ac[i][2] *= -1;
    }
    sort(ALL(ac));/*
    cout << endl;
    REP(i, t) {
      REP(j, 3) {
        cout << ac[i][j] << " ";
      }
      cout << endl;
    }*/
    cout << -1*ac[0][2];
    FOR(i, 1, t) {
      if(ac[i][0] == ac[i-1][0] && ac[i][1] == ac[i-1][1]) {
        cout << "=";
      } else {
        cout << ",";
      }
      cout << -1*ac[i][2];
    }
    cout << endl;
  }

  return 0;
}