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 <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

class team
{
public:
	int num;	// number of team
	int cnt;	// solved problems
	int tim;	// total consumed time

	team(void) {};
	team(int _num, int _cnt, int _tim) :
		num(_num), cnt(_cnt), tim(_tim) {};

	friend bool operator == (const team &a, const team &b)
	{
		return a.cnt == b.cnt && a.tim == b.tim;
	}

	friend bool operator < (const team &a, const team &b)
	{
		if (a.cnt != b.cnt)
			return a.cnt > b.cnt;
		else if (a.tim != b.tim)
			return a.tim < b.tim;
		else
			return a.num < b.num;
	}
};

class record
{
public:
	int tim;	// elapsed time
	int num;	// number of team
	int pro;	// problem number
	int jud;	// judgement of submission	

	record(void) {};
	record(int _tim, int _num, int _pro, int _jud) :
		tim(_tim), num(_num), pro(_pro), jud(_jud) {};
};

team tm[55];
record rc[2005];
bitset<15> sl[55];	// if team i solved problem j

signed main(void)
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int m, t, p, r;

	while (cin >> m >> t >> p >> r, m || t || p || r)
	{
		for (int i = 1; i <= t; ++i)
			sl[i].reset();
		
		for (int i = 1; i <= r; ++i)
		{
			int ti, ni, pi, ji;
			cin >> ti >> ni >> pi >> ji;
			rc[i] = record(ti, ni, pi, ji);

			if (ji == 0)sl[ni].set(pi);	// team ni solved pi
		}

		for (int i = 1; i <= t; ++i)
			tm[i] = team(i, sl[i].count(), 0);

		for (int i = 1; i <= r; ++i)
		{
			int ti = rc[i].tim;
			int ni = rc[i].num;
			int pi = rc[i].pro;
			int ji = rc[i].jud;

			if (ji == 0)
				tm[ni].tim += ti;
			else if (sl[ni][pi])
				tm[ni].tim += 20;
		}

		sort(tm + 1, tm + 1 + t);

		int stk[55], tot = 0;

		for (int i = 1, j = 1; i <= t; i = j)
		{
			while (j <= t && tm[i] == tm[j])
				stk[++tot] = j++;
			
			cout << tm[stk[tot--]].num;

			while (tot)
				cout << "=" << tm[stk[tot--]].num;

			if (j <= t)
				cout << ",";
			else 
				cout << endl;
		}
	}

//	system("pause");
}

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

int M, T, P, R;
int wa[55][15]; // team, pena
int solved[55];
int pena[55];

bool cmp(int i, int j) {
    return make_pair(make_pair(-solved[i], pena[i]), -i) < make_pair(make_pair(-solved[j], pena[j]), -j);
}

bool equal(int i, int j) {
    return make_pair(-solved[i], pena[i]) == make_pair(-solved[j], pena[j]);
}

int main() {
    while (cin >> M >> T >> P >> R) {
        if (T == 0) break;
        memset(wa, 0, sizeof(wa));
        memset(solved, 0, sizeof(solved));
        memset(pena, 0, sizeof(pena));
        for (int i = 0; i < R; ++i) {
            int m, t, p, j; cin >> m >> t >> p >> j; --t;
            if (j == 0) {
                ++solved[t];
                pena[t] += m + wa[t][p];
            }
            else {
                wa[t][p] += 20;
            }
        }
        
        vector<int> vec(T);
        for (int i = 0; i < T; ++i) vec[i] = i;
        sort(vec.begin(), vec.end(), cmp);
        for (int i = 0; i < T; ++i) {
            if (i > 0) {
                if (equal(vec[i-1], vec[i])) cout << "=";
                else cout << ",";
            }
            cout << vec[i] + 1;
        }
        cout << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

pair<P,int> t[55];
int wrong[55][15];

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c,d;
    while(cin>>a>>b>>c>>d,a)
    {
	REP(i,b) t[i]=make_pair(P(0,0),-i-1);
	REP(i,b) REP(j,c) wrong[i][j]=0;

	REP(i,d){
	    int e,f,g,h;
	    cin>>e>>f>>g>>h;
	    f--,g--;
	    if(h==0){
		t[f].first.first--;
		t[f].first.second+=e+20*wrong[f][g];
	    }else{
		wrong[f][g]++;
	    }
	}
	sort(t,t+b);
	cout<<-t[0].second;
	for(int i=1;i<b;i++){
	    if(t[i-1].first.first==t[i].first.first &&
	       t[i-1].first.second==t[i].first.second){
		cout<<"=";
	    } else cout<<",";
	    cout<<-t[i].second;
	}
	cout<<endl;
    }
}