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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_T = 70;
const int MAX_P = 20;
int M, T, P, R;
int tID, pID, ti, mes;
int wa[MAX_T][MAX_P];

struct data{int a, p, id; };

inline bool operator < (const data& x, const data& y)
{
  return x.a!=y.a ? x.a<y.a : x.p!=y.p ? x.p>y.p : x.id < y.id;
  //  return x.a!=y.a ? x.a<y.a : x.p>y.p;
}

inline bool operator > (const data& x, const data& y)
{
  return !(x < y);
}

inline bool operator == (const data& x, const data& y)
{
  return x.a==y.a && x.p==y.p;
}

ostream& operator <<(ostream& r, const vector<data> t){vrep(v,t)r<<v->id<<(v+1==t.end()?"":*v==*(v+1)?"=":",");return r;}

int main()
{
  while(cin >> M >> T >> P >> R, T){
    vector<data> g(T, (data){0, 0, 0});
    rep(i, MAX_T) rep(j, MAX_P) wa[i][j] = 0;
    rep(i, T) g[i].id = i + 1;

    rep(i, R){
      cin >> ti >> tID >> pID >> mes;
      tID -= 1;  pID -= 1;
      if(mes == 0){
        g[tID].a += 1;
        g[tID].p += wa[tID][pID] * 20 + ti;
      }
      else wa[tID][pID] += 1;
    }
    sort(ALL(g), greater<data>());
    cout << g << endl;
  }

  return 0;
}

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&& 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;
}