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<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 1005

typedef struct data{

    int team_number;
    int number;//順位
    int penalty[2][15];//penalty[WA回数][解けたかどうか]
    int ac_sum;//AC数
    int passed_time;//経過時間

}DATA;


bool comp(const DATA& a,const DATA& b){
    //昇順ソート
    if(a.ac_sum == b.ac_sum){
        //AC数が同じ
        if(a.passed_time == b.passed_time){
            //AC数も時間も同じ場合は順位は同じだが、並べる順番がチーム番号の大きい順のため
            return a.team_number > b.team_number;
        }else{
            return a.passed_time < b.passed_time;
        }
    }else{
        //AC数が同じ場合はAC数の大きい方が順位が先
        return a.ac_sum > b.ac_sum;
    }



}


int main(){

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

        vector<DATA> a(T);
        
        REP(i,T){
            //チーム番号の格納、WAテーブルの初期化
            a[i].team_number = i+1;
            REP(j,2){
                REP(k,15){
                    a[i].penalty[j][k] = 0;
                }
            }
        }

        int m,t,p,j;
        REP(i,R){
            //各チームのデータの整理
            cin >> m >> t >> p >> j;
            if(j){
                //WAの場合
                a[t-1].penalty[0][p-1]++;
            }else{
                a[t-1].penalty[1][p-1] = 1;//解けた
                a[t-1].passed_time += m;//解くまでの時間はこの時点で足しておく
                a[t-1].ac_sum++;//AC数を1つ増やす
            }
        }

        //ペナルティ加算後の経過時間の計算
        REP(i,T){
            REP(j,P){
                if(a[i].penalty[1][j] == 1){
                    //解けているのでWA数×20を足す
                    a[i].passed_time += a[i].penalty[0][j]*20;
                }
            }
        }

        sort(a.begin(),a.end(),comp);
        
        //順位付けをつける処理
        a[0].number = 1;
        for(int i = 1;i < T;i++){

            if(a[i-1].ac_sum == a[i].ac_sum){
                //AC数が同じ
                if(a[i-1].passed_time == a[i].passed_time){
                    //AC数も経過時間も同じ
                    a[i].number = a[i-1].number;
                }else{
                    //経過時間が長い
                    a[i].number = a[i-1].number + 1;
                }
            }else{
                //AC数が少ない
                a[i].number = a[i-1].number + 1;
            }
        }
        //順位の表示処理
        REP(i,T){
            if(i == 0){
                cout << a[i].team_number;
            }else{
                if(a[i-1].number < a[i].number){
                    cout << "," << a[i].team_number;
                }else{
                    cout << "=" << a[i].team_number;
                }
            }
        }
        cout << endl;
        a.shrink_to_fit();//メモリ開放
    }




    return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long
#define INF (int)1e7
using namespace std;

struct S{
    int p,t,i;
};

bool cmp(const S &left, const S &right){
    return left.p == right.p ? left.t == right.t ? left.i > right.i : left.t < right.t : left.p > right.p;
}
bool eq(const S &l, const S &r){
    return l.p == r.p && l.t == r.t;
}


signed main(){
    while(true){
        int M,T,P,R; cin >> M >> T >> P >> R;
        if(M == 0)break;
        vector<S> s(T);
        vector<vector<int> > c(T,vector<int>(P,0));
        for(int i = 0; i < T; i++){
            S temp = {0, 0, i+1};
            s[i] = temp;
        }

        for(int i = 0; i < R; i++){
            int m,t,p,j;
            t--;
            cin >> m >> t >> p >> j;
            if(j == 0){
                if(c[t-1][p-1] != 1){
                    s[t-1].p++;
                    s[t-1].t += m+c[t-1][p-1];
                    c[t-1][p-1] = 1;
                }
            }
            else{
                c[t-1][p-1] += 20;
            }
        }
        sort(ALL(s),cmp);
        cout << s[0].i;// << ":" << s[0].p << ":" << s[0].t;
        for(int i = 1; i < T; i++){
            if(eq(s[i-1],s[i])){
                cout << "=";
            }
            else{
                cout << ",";
            }
            cout << s[i].i;// << ":" << s[i].p << ":" << s[i].t;
        }
        cout << endl;
    }
                


    return 0;
}