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 <algorithm>
#include <vector>
using namespace std;

struct team{
    int t;
    int ac;
    int id;
    team():t(0),ac(0),id(0){}
    bool operator <(const team& a){
        if(ac != a.ac) return ac > a.ac;
        if(t != a.t) return t < a.t;
        return id > a.id;
    }
};

int main(){
    while(1){
        int m,t,p,r;
        cin >>m>>t>>p>>r;
        if(m==0) break;

        vector<vector<int> > wa(t, vector<int>(p,0));
        vector<team> info(t);
        for(int i=0; i<t; i++) info[i].id=i+1;
        for(int i=0; i<r; i++){
            int mi,ti,pi,ji;
            cin >>mi>>ti>>pi>>ji;
            ti--; pi--;
            if(ji==0){
                info[ti].ac++;
                info[ti].t += mi + wa[ti][pi]*20;
            }else{
                wa[ti][pi]++;
            }
        }
        sort(info.begin(), info.end());
        cout << info[0].id;
        for(int i=1; i<t; i++){
            if(info[i].ac==info[i-1].ac && info[i].t==info[i-1].t){
                cout << "=";
            }else{
                cout << ",";
            }
            cout << info[i].id;
        }
        cout << endl;
    }   
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int x[99][2],y[99][20],n,a,b,c,d,e,f,g,h,p,i,j,k;
int main() {
while(true) {
memset(x,0,sizeof(x));memset(y,0,sizeof(y));
cin>>n>>a>>b>>c;
if(n==0){break;}
for(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(i=b;i>=0;i--){
for(j=0;j<=49999;j++){h=0;
for(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<iostream>
#include<algorithm>
using namespace std;
typedef struct mtpj{
  int No,time,ACcnt,WAcnt[11];
  bool AC[11];
  static bool comp(const mtpj& hm,const mtpj& hmhm){
    if(hm.ACcnt!=hmhm.ACcnt) return hm.ACcnt>hmhm.ACcnt;
    if(hm.time!=hmhm.time) return hm.time<hmhm.time;
    return hm.No>hmhm.No;
  }
}P;
P p[50];
int main(){
  int M,T,P,R;
  int m,t,q,J;
  int TEcnt;
  while(cin >> M >> T >> P >> R && M|T|P|R){
    TEcnt = 0;
    for(int i=1;i<=T;i++){
      p[i].time=p[i].ACcnt=0,p[i].No=i;
      for(int j=1;j<=10;j++) p[i].WAcnt[j]=0,p[i].AC[j]=false;
    }

    for(int i=0;i<R;i++){
      cin >> m >> t >> q >> J;
      if(p[t].AC[q])continue;
      if(J==0){ //AC
	p[t].AC[q] = true;
	p[t].ACcnt++;
	p[t].time += p[t].WAcnt[q]*20 + m;
      }else p[t].WAcnt[q]++; //WA
    }
    sort(p+1,p+T+1,mtpj::comp);
    for(int i=1;i<=T;i++){
      if(p[i-1].time==p[i].time && p[i-1].ACcnt==p[i].ACcnt&&i!=1){
	cout << "=";
      }else if(i!=1){
	cout << ",";
      }
      cout << p[i].No;
    }
    cout << endl;
  }
}

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

class team{
    public:
        vector<int> tt;
        int ac = 0;
        vector<int> miss;
};

int main(void){
    int M,T,P,R;
    
    while(cin >> M >> T >> P >> R, M){
    
        vector<team> teams(T);
        for (int i=0; i<T; i++) {
            teams[i].tt = vector<int>(P,-1);
            teams[i].miss = vector<int>(P,0);
        }

        int m,t,p,j;
        for (int i=0; i<R; i++) {
            cin >> m >> t >> p >> j;
            if (j == 0) {
                teams[t-1].tt[p-1] = max(teams[t-1].tt[p-1], m);
                teams[t-1].ac++;
            }
            else {
                teams[t-1].miss[p-1]++;
            }
        }
        

        
        vector<pair<int, pair<int, int>>> score(T);
        
        for (int i=0; i<T; i++){
            int t = 0;
            for (int j=0; j<P; j++) {
                if (teams[i].tt[j] != -1)
                    t += teams[i].tt[j] + teams[i].miss[j]*20;
            }
            score[i] = make_pair(teams[i].ac, make_pair(-t, i+1));
        }
        
        // for (int i=0; i<T; i++){
        //     cout << "team " << i+1 <<" :" << endl;
        //     cout << teams[i].ac << endl;
        //     for (int j=0;j<P;j++) {
        //         cout << teams[i].tt[j] << " ";
        //     }
        //     cout << endl;
        //     for (int j=0;j<P;j++) {
        //         cout << teams[i].miss[j] << " ";
        //     }
        //     cout << endl;
        //     cout << -score[i].second.first << endl;
        // }
        
        
    
        sort(score.begin(), score.end(), greater<pair<int,pair<int,int>>>());
        
        
        for (int i=0; i<T-1; i++) {
            cout << score[i].second.second;
            if (score[i].first == score[i+1].first && score[i].second.first == score[i+1].second.first) cout << "=";
            else cout << ",";
        }
        cout << score[T-1].second.second << endl;
    }
}