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, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

struct S{
   int id, ac, time;
   vector<int> wa;
};
bool cmp(S p1, S p2){
   if(p1.ac == p2.ac){
       if(p1.time == p2.time){
           return p1.id > p2.id;
       }
       return p1.time < p2.time;
   }
   return p1.ac > p2.ac;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, t, p, r;
    while(1){
        cin >> m >> t >> p >> r;
        if(m + t + p + r == 0) break;
        vector<S> d(t);
        rep(i, 0, t){
            d[i].id = i; d[i].ac = 0; d[i].time = 0; d[i].wa.resize(p);
        }
        rep(i, 0, r){
            int mi, ti, pi, ji;
            cin >> mi >> ti >> pi >> ji;
            ti--; pi--;
            if(ji == 0){
                d[ti].ac++;
                d[ti].time += mi + 20 * d[ti].wa[pi];
            }else{
                d[ti].wa[pi]++;
            }
        }
        sort(all(d), cmp);
        rep(i, 0, t){
            cout << d[i].id + 1;
            if(i != t - 1){
                if(d[i].ac == d[i + 1].ac && d[i].time == d[i + 1].time) cout << "=";
                else cout << ",";
            }
        }
        cout << endl;
    }
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
//#define int long long
const int MAX_R = 2010;
const int MAX_P = 15;
const int MAX_T = 55;

class C{
  public:
    int n, penalty[MAX_P], ac, time;
    C(){
      ac = time = 0;
      memset(penalty, 0, sizeof(penalty));
    }
    bool operator<(const C &c) const{
      if(ac != c.ac) return ac < c.ac;
      else if(time != c.time) return time > c.time;
      else return n < c.n;
    }
};

int main() {
  int M, T, P, R;
  while(cin >>M >>T >>P >>R && M){
    C team[MAX_T];
    REP(i, T) team[i].n = i + 1;
    REP(i, R){
      int m, t, p, j; cin >>m >>t >>p >>j;
      --t;
      if(j == 0){
        team[t].ac += 1;
        team[t].time += team[t].penalty[p] + m;
      } else team[t].penalty[p] += 20;
    }
    sort(team, team + T);
    reverse(team, team + T);
    stringstream ss;
    REP(i, T){
      ss << team[i].n;
      if(i == T - 1) continue;
      if(team[i + 1].ac == team[i].ac && team[i + 1].time == team[i].time) ss <<"=";
      else ss <<",";
    }
    cout <<ss.str() <<endl;
  }
  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!=0) {
				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 <= 10000; 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;
	}
}