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++: //
//  1187.cpp
//  
//
//  Created by Minote Tomoki on 2015/06/04.
//
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct {
    int m;
    int t;
    int p;
    int j;
} data;

typedef struct {
    int team;
    int time;
    int collect;
} status;

status judge(vector<data> team,int num) {
    int que_time[10]={0};
    
     status result = {num};
    
    for(auto k:team) {
//        que_time[k.p-1]+=k.m;
        if(k.j==0) {
            result.collect++;
            result.time+=k.m + que_time[k.p-1];
        }
        else {
            que_time[k.p-1]+=20;
        }
        
    }
//    cout << result.time << endl;
//    cout << result.collect << endl;
    
//    cout << result.time << endl;
    
    return result;
}

bool cmp(const status& left, const status& right) {
    if ( left.collect == right.collect) {
        if(left.time == right.time) {
            return left.team > right.team;
        }
        else {
            return left.time < right.time;
        }
    }
    return left.collect > right.collect;
}

bool eq(const status& left, const status& right) {
    if(left.collect == right.collect && left.time == right.time) return true;
    else return false;
}

int main(void) {
    int M,T,P,R;
    int m,t,p,j;
    
    while(cin >> M >> T >> P >> R, M|T|P|R) {
    
        vector<data> dat(R);
        vector<vector<data>> team(T);
        vector<status> result;
    
        for(int i=0;i<R;i++) {
            cin >> m >> t >> p >> j;
            data d={m,t,p,j};
            team[t-1].push_back(d);
        }
    
        int k=1;
        for(auto i:team){
            status tmp = judge(i,k++);
            result.push_back(tmp);
            //cout << tmp.time << "," << tmp.collect << endl;
        }
        
        
        //for(int i=0;i<T;i++) { cout << result[i].collect << endl; }
        sort(result.begin(),result.end(),cmp);
        for(int i=0;i<team.size();i++){
            cout << result[i].team;
            if(i<team.size()-1) {
                if(eq(result[i],result[i+1])) cout << "=";
                else cout << ",";
            }
        }
        cout << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

#define rep(i, j) for(int i= 0; i < j;i++)
#define all(i) i.begin(), i.end()

struct team { int num, ac, time; };

// t0<t1
bool compare(team &t0, team &t1)
{
	if (t0.ac == t1.ac) 
	{
		if (t0.time == t1.time){ return t0.num < t1.num; }
		return t0.time > t1.time; 
	}
	return t0.ac < t1.ac;
}
int main()
{
	int M, T, P, R;
	while (cin >> M >> T >> P >> R && (M != 0 && T != 0))
	{
		vector<int> m(R, 0), t(R, 0), p(R, 0), j(R, 0);
		vector<team> dat(T + 10);
		vector<vector<int>> wa(T + 10, vector<int>(P + 10, 0));
		rep(i, R)
		{
			int tmp[4] = { 0 };
			cin >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3];
			if (tmp[3] > 0) { wa[tmp[1]][tmp[2]] += 20; }
			else if(tmp[3] == 0)
			{
				dat[tmp[1]].time += tmp[0] + wa[tmp[1]][tmp[2]];
				dat[tmp[1]].ac += 1;
				dat[tmp[1]].num = tmp[1];
			}
		}
		rep(i, T + 1) { dat[i].num = i; }
		sort(dat.rbegin(), dat.rend(), compare);
		rep(i, T)
		{
			if (i == T - 1){ printf("%d\n", dat[i].num); }
			else if(dat[i].time == dat[i+1].time && i != T - 1){ printf("%d=", dat[i].num); }
			else{ printf("%d,", dat[i].num); }
		}
	}
}

C++: #include<stdio.h>

int main(){

int M,T,P,R;

while(1){
scanf("%d%d%d%d",&M,&T,&P,&R);
if(M==0&&T==0&&P==0&&R==0)break;

int n[51][11]={};int n2[51][11]={};

int m,t,p,j;
for(int i=0;i<R;i++)
{
scanf("%d%d%d%d",&m,&t,&p,&j);
if(j==0){n[t][p]+=m;n2[t][p]=1;}
else{n[t][p]+=20;}
}
for(int i=1;i<=T;i++)
for(int k=1;k<=P;k++)
	if(n2[i][k]==0){n[i][k]=0;}


int N[51][3]={};
for(int i=1;i<=T;i++)
for(int k=1;k<=P;k++)
{
N[i][0]+=n[i][k];
N[i][1]+=n2[i][k];
N[i][2]=i;
}

for(int i=1;i<=T;i++)
for(int k=T;k>i;k--)
if(N[k][1]>N[k-1][1]){
int t=N[k][1];N[k][1]=N[k-1][1];N[k-1][1]=t;
int t2=N[k][0];N[k][0]=N[k-1][0];N[k-1][0]=t2;
int t3=N[k][2];N[k][2]=N[k-1][2];N[k-1][2]=t3;
}
for(int i=1;i<=T;i++)
for(int k=T;k>i;k--)
	if(N[k][1]==N[k-1][1]&&N[k][0]<N[k-1][0]){
		int t=N[k][1];N[k][1]=N[k-1][1];N[k-1][1]=t;
int t2=N[k][0];N[k][0]=N[k-1][0];N[k-1][0]=t2;
int t3=N[k][2];N[k][2]=N[k-1][2];N[k-1][2]=t3;
	}


for(int i=1;i<=T;i++)
for(int k=T;k>i;k--)
	if(N[k][1]==N[k-1][1]&&N[k][0]==N[k-1][0]&&N[k][2]>N[k-1][2]){
		int t3=N[k][2];N[k][2]=N[k-1][2];N[k-1][2]=t3;
	}


for(int i=1;i<=T;i++)
{if(i>1){if(N[i][1]==N[i-1][1]&&N[i][0]==N[i-1][0])printf("=");
else printf(",");}

printf("%d",N[i][2]);
}
printf("\n");
}
return 0;
}