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>
using namespace std;

struct team{
	  int id;
	  int ac,time;
	  vector<int> wa;
	  team(int i, int a, int t, int P){
			id = i; ac = a; time = t;
			wa = vector<int>(P+1,0);
	  }
	  bool operator < (const team& tgt) const {
			if( ac != tgt.ac )
				  return ac < tgt.ac;
			if( time != tgt.time )
				  return time > tgt.time;
			return id < tgt.id;
	  }

};

int main(){
	  while(1){
			int M,T,P,R; cin >> M >> T >> P >> R;
			if(!M) break;
			vector<team> teams;
			for(int i=0; i<T; i++)
				  teams.push_back( team(i+1,0,0,P) );
	  
			for(int i=0; i<R; i++){
				  int m,t,p,j;
				  cin >> m >> t >> p >> j;
				  if( j == 0 ){
						teams[ t-1 ].ac ++;
						teams[ t-1 ].time += m;
						teams[ t-1 ].time += teams[ t-1 ].wa[ p ]*20 ;
						
				  }
				  else{
						teams[ t-1 ].wa[ p ]++;
				  }
			}
			sort(teams.begin(),teams.end());
			reverse(teams.begin(),teams.end());
			
			team pre = team(-1,-1,-1,P);
			for(int i=0; i<T; i++){
				  team corr = teams[i];
				  if( pre.ac == corr.ac and pre.time == corr.time )
						cout << "=" << corr.id;
				  else
						if(i!=0)
							  cout << "," << corr.id;
						else
							  cout << corr.id;
				  pre = corr;
			}
			cout << endl;
	  
	  }
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
    int M, T, P, R;
    while (cin >> M >> T >> P >> R){
        int num_solved[T];
        int num_wrong[T][P];
        int total_time[T];

        memset(num_solved, 0, sizeof(num_solved));
        memset(num_wrong, 0, sizeof(num_wrong));
        memset(total_time, 0, sizeof(total_time));

        for (int i = 0; i < R; i++){
            int m, t, p, j;
            cin >> m >> t >> p >> j; t--; p--;
            if (j == 0){
                num_solved[t]++;
                total_time[t] += num_wrong[t][p] * 20 + m;
            } else {
                num_wrong[t][p]++;
            }
        }

        vector<pair<pair<int, int>, int> > vs; 

        for (int i = 0; i < T; i++){
            vs.push_back(make_pair(make_pair(-num_solved[i], total_time[i]), -i)); 
        }
        sort(vs.begin(), vs.end());

        for (int i = 0; i < T; i++){
            if (i > 0){
                if (vs[i].first == vs[i - 1].first){
                    cout << "=";
                } else {
                    cout << ",";
                }
            }
            cout << -vs[i].second + 1 ;
        }
        cout << endl; 
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); ++i)

int main(){
  int m,t,p,r;
  while(cin >> m >> t >> p >> r , m){
    vector<int> now(t);
    int p[100][20] ={};
    int ca[100] = {};
    int mm,tt,pp,jj;
    rep(i,r){
      cin >> mm >> tt >> pp >> jj;
      --tt;
      if(jj){
        p[tt][pp]++;
      }else{
        now[tt] += mm;
        now[tt] += p[tt][pp]*20;
        ca[tt]++;
      }
    }
    using tiii = tuple<int,int,int>;
    vector<tiii> ts;
    rep(i,t){
      ts.push_back(tiii{ca[i],-now[i],i+1});
    }
    sort(begin(ts),end(ts), greater<tiii>());
    rep(i,t-1){
      int a,b,c; tie(a,b,c) = ts[i];
      int aa,bb,cc; tie(aa,bb,cc) = ts[i+1];
      cout << c << ((a == aa && b == bb)?'=':',');
    }
    int a,b,c; tie(a,b,c) = ts[t-1];
    cout << c << endl;
  }
}