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<cstring>
using namespace std;
int x[100][3], n, a, b, c, d, e, f, g, h, p;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n >> a >> b >> c;
		for (int i = 0; i < c; i++) {
			cin >> d >> e >> f >> g;
			if (g) {
				x[e][2] += 20;
			}
			else {
				x[e][1] = d + x[e][2];
				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;
	}
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;

struct st{
    int ac;
    int wa;
};


int main(){
    for(;;){
        int M,T,P,R;
        cin >> M >>T>>P>>R;
        if (M==0 and R ==0) break;
        st data[T+1][P+2];
        int ans=0;
        for (int i=1; i<=T; i++) {
            for (int j=1; j<=P+1; j++) {
                data[i][j]={0,0};
            }
        }
        for (int i=0; i < R; i++) {
            int m,t,p,j;
            cin >>m >> t >> p >> j;
            if (j==0) {//ac
                data[t][p].ac = 1;
                data[t][P+1].wa += m;
                data[t][P+1].ac++;
            }else{
                data[t][p].wa++;
            }
        }
        /*for (int i=1; i<=T; i++) {
            for (int j=1; j<=P+1;j++ ) {
                cout << "("<<data[i][j].ac <<","<<data[i][j].wa<<")"<<"|";
            }
            cout << endl;
        }*/
        vector<pair<int,int> > AC(T);
        for (int i=1; i<=T; i++) {
            AC[i-1] = {P+1-data[i][P+1].ac,i};
        }
        sort(AC.begin(), AC.end());
        /*for (int i=0; i<T; i++) {
            cout << AC[i].second << "|";
        }
        cout << endl;
         */
        for (int i=0; i<T; i++) {
            int p=i;
            while (AC[p].first==AC[p+1].first and p+1<T) {
                p++;
            }
            vector<pair<int, int> > time(p-i+1);
            for (int j=i; j<=p; j++) {
                int dis=data[AC[j].second][P+1].wa;
                for (int k = 1; k<P+1; k++) {
                    if (data[AC[j].second][k].ac == 1) {
                        dis += data[AC[j].second][k].wa*20;
                    }
                }
                time[j-i] = {dis, AC[j].second};
            }
            sort(time.begin(), time.end());
            for (int l =0 ;l < p-i+1;l++ ) {
                int s = l;
                if (s+1 >= p-i+1) {
                    cout << time[s].second;
                    ans++;
                    if (ans != T) {
                        cout << ",";
                    }
                }else{
                    while (time[s].first==time[s+1].first and s+1 < p-i+1) {
                        s++;
                    }
                    if (s-l>=1) {
                        for (int u =0; u<=s-l; u++) {
                            cout << time[s-u].second;
                            ans++;
                            if (u==s-l and ans != T) {
                                cout << ",";
                            }else{
                                if (ans != T) {
                                    cout << "=";
                                }
                            }
                        }
                    }else{
                        cout << time[s].second;
                        ans++;
                        if (ans != T) {
                            cout << ",";
                        }
                    }
                }
                l = s;
            }
            i=p;
        }
        cout << endl;
    }
}

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

int main(){
  while(true){
    int M, T, P, R;
    cin >> M >> T >> P >> R;

    if(M==0 && T==0 && P==0 && R==0)
      break;

    int CP[50], TT[50], PT[50][10];
    for(int i=0; i<T; i++){
      CP[i] = TT[i] = 0;
      for(int j=0; j<P; j++)
	PT[i][j] = 0;
    }

    for(int i=0; i<R; i++){
      int m, t, p, j;
      cin >> m >> t >> p >> j;

      if(j==0){
	CP[t-1]++;
	TT[t-1] += (m+PT[t-1][p-1]);
      }
      else{
	PT[t-1][p-1] += 20;
      }
    }

    int tnow, tpre = -1;
    bool flg[50];
    for(int i=0; i<T; i++)
      flg[i] = false;

    for(int i=0; i<T; i++){
      tnow = -1;
      for(int j=0; j<T; j++){
	if(flg[j])
	  continue;

	if(tnow==-1){
	  tnow = j;
	}
	else{
	  if(CP[j]>CP[tnow] || (CP[j]==CP[tnow] && TT[j]<=TT[tnow])){
	    tnow = j;
	  }
	}
      }

      if(tpre!=-1){
	if(CP[tnow]==CP[tpre] && TT[tnow]==TT[tpre])
	  cout << '=';
	else
	  cout << ',';
      }
      cout << tnow+1;

      flg[tnow] = true;
      tpre = tnow;
    }
    cout << endl;
  }
  return 0;
}