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"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
struct team {
	int solve;
	int time;
	int id;

};

int main() {
	while (1) {
		int N, T, P, R; cin >> N >> T >> P >> R;
		vector<vector<int>>wrongs(T, vector < int>(P));
		vector<vector<int>>scores(T, vector <int>(P,0));
		if (!N)break;
		for (int i = 0; i < R; ++i) {
			int m, t, p, j; cin >> m >> t >> p >> j;
			t--; p--;
			if (j) {
				wrongs[t][p]++;
			}
			else {
				if (!scores[t][p]) {
					scores[t][p] += 1+wrongs[t][p] * 20 + m;
				}
			}
		}
		vector<team>ts;
		for (int i = 0; i < T; ++i) {
			team t = team{ 0,0,i+1 };
			for (int j = 0; j < P; ++j) {
				if (scores[i][j]) {
					t.solve++;
					t.time += scores[i][j];

				}
			}
			ts.emplace_back(t);
		}
		sort(ts.begin(), ts.end(), [](const team&l, const team&r) {
			return l.solve == r.solve ? l.time == r.time ? l.id>r.id:l.time<r.time : l.solve>r.solve;
			; });
		cout << ts[0].id;
		for (int i = 1; i < ts.size(); ++i) {
			if (ts[i].solve == ts[i - 1].solve&&ts[i].time == ts[i - 1].time)cout << '=';
			else cout << ",";
			cout << ts[i].id;
		}
		cout << endl;
	}
	return 0;
}

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

struct node{
	int cnt, totaltime, id;
	int ass[51];
};

bool cmp(node a, node b){
	if (a.cnt > b.cnt)return true;
	else if (a.cnt < b.cnt)return false;
	else if (a.totaltime < b.totaltime)return true;
	else if (a.totaltime > b.totaltime)return false;
	else return a.id > b.id;
}

int main()
{
	int m, t, p, r, mk, tk, pk, jk;
	while (cin >> m >> t >> p >> r){
		if (!m && !t && !p && !r)return 0;
		vector<node> vec(t);
		for (int i = 0; i < t; ++i){
			vec[i].id = i + 1;
			vec[i].cnt = 0;
			vec[i].totaltime = 0;
		}
		for (int i = 0; i < r; ++i)
		{
			cin >> mk >> tk >> pk >> jk;
			if (!jk){
				++vec[tk - 1].cnt;
				vec[tk - 1].totaltime += mk + vec[tk-1].ass[pk];
			}else{
				vec[tk-1].ass[pk] += 20;
			}
		}
		sort(vec.begin(), vec.end(), cmp);
		cout << vec[0].id;
		for (int i = 1; i < vec.size(); ++i){
			if (vec[i - 1].cnt == 0 || (vec[i].cnt == vec[i - 1].cnt && vec[i].totaltime == vec[i - 1].totaltime)){
				putchar('=');
			}
			else putchar(',');
			cout << vec[i].id;
		}
		putchar('\n');
	}
}

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

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

        int ap[55] = {};
        int at[55] = {};
        int pen[55][11] = {};
        for(int i=0;i<55;i++){
            ap[i] = 0;
            at[i] = 0;
            for(int j=0;j<11;j++){
                pen[i][j] = 0;
            }
        }

        for(int i=0;i<R;i++){
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            if(j==0){
                ap[t]++;
                at[t]+=m+20*pen[t][p];
            }else{
                pen[t][p]++;
            }
        }

        bool c_flag = false;
        for(int i=10;i>=0;i--){
            for(int j=0;j<50000;j++){
                bool e_flag = false;
                for(int k=T;k>=1;k--){
                    if(ap[k]==i && at[k]==j){
                        if(e_flag){
                            cout << '=';
                        }else if(c_flag){
                            cout << ',';
                        }
                        c_flag = true;
                        e_flag = true;
                        cout << k;
                    }
                }
            }
        }
        cout << endl;
    }
}

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

struct d{
  int time, prob, team;
};
bool operator<(const d &a, const d &b){
  if(a.prob == b.prob){
    if(a.time == b.time){
      return a.team > b.team;
    }else{
      return a.time < b.time;
    }
  }else{
    return a.prob > b.prob;
  }
}
int main(){

  int M, T, P, R;
  int m, t, p, j, i;

  while(cin >> M >> T >> P >> R, M+T+P+R){
    d res[T+1];
    for(i = 1; i <= T; i++){
      res[i].time = res[i].prob = 0;
      res[i].team = i;
    }
    int rank[T+1][P+1];
    for(i = 1; i <= T; i++){
      for(j = 1; j <= P; j++){
        rank[i][j] = 0;
      }
    }
    for(i = 0; i < R; i++){
      cin >> m >> t >> p >> j;
      if(m > M) break;
      if(j){
        rank[t][p]++;
      }else{
        res[t].time += m + rank[t][p]*20;
        res[t].prob++;
      }
    }
    /* cerr << "debug" << endl;
    for(i=1; i<=T; i++)
    {
      cerr << res[i].team << "," << res[i].prob << "," << res[i].time << endl;
    }
    cerr << "debug" << endl;
*/
    sort(res+1, res+T+1);
    cout << res[1].team;
    for(i=2; i<=T; i++)
    {
      cout << ((res[i].prob==res[i-1].prob && res[i].time==res[i-1].time) ? "=" : ",") << res[i].team;
    }
    cout << endl;
    //cerr << endl;
  }
  return 0;
}