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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2005;
const ll INF=1LL<<59;
struct team{
    int ti;
    vector<int> cnt;
    int ok;
    int id;
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int M,T,P,R;cin>>M>>T>>P>>R;
        
        if(M+T+P+R==0) break;
        
        vector<team> S(T);
        for(int i=0;i<T;i++){
            S[i].cnt.resize(15);
            S[i].id=i;
        }
        
        for(int i=0;i<R;i++){
            int a,b,c,d;cin>>a>>b>>c>>d;
            b--;c--;
            if(d){
                S[b].cnt[c]++;
            }else{
                S[b].ti+=S[b].cnt[c]*20+a;
                S[b].ok++;
            }
        }
        
        sort(all(S),[](team a,team b){
            if(a.ok==b.ok){
                if(a.ti==b.ti){
                    return a.id>b.id;
                }
                return a.ti<b.ti;
            }
            return a.ok>b.ok;
        });
        
        for(int i=0;i<T;i++){
            if(i){
                if(S[i].ok==S[i-1].ok&&S[i].ti==S[i-1].ti){
                    cout<<'='<<S[i].id+1;
                }else{
                    cout<<','<<S[i].id+1;
                }
            }else{
                cout<<S[i].id+1;
            }
        }
        cout<<endl;
    }
    
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000
#define rep(i,n) for(i=0;i<n;i++)

typedef pair<int,int> pii;


int main() {
    while(1){
        int m,t,p,r;
        cin>>m>>t>>p>>r;
        if(m==0 && t==0 && p==0 && r==0)break;
        int i;
        pair<pii,int> team[50]; //solved_num, time, team_num
        int v[50][10]={};//team_num, problem_num, wrong_num
        int time,tnum,pnum,j;
        rep(i,t)
            team[i].second=i+1;
        rep(i,r){
            cin>>time>>tnum>>pnum>>j;
            tnum--;
            pnum--;
            if(j){//WA
                v[tnum][pnum]++;
            }else{//AC
                team[tnum].first.first++;
                team[tnum].first.second-=time+v[tnum][pnum]*20;
            }
        }
        rep(i,t)
            if(team[i].first.second==0)team[i].first.second=-1000000;
        
        sort(team,team+t);
        for(i=t-1;i>0;i--){
            cout<<team[i].second;
            if(team[i].first.first==team[i-1].first.first &&
               team[i].first.second==team[i-1].first.second)
                cout<<"=";
            else
                cout<<",";
            
        }
        cout<<team[0].second<<endl;
    
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

struct score {
	int teamNum;
	int accepted;
	int time;
	int penaltyTime;
	vector<int> miss;
	bool operator==(score s) const {
		return this->accepted == s.accepted && this->getTi() == s.getTi();
	};
	bool operator<(score s) const {
		return this->accepted != s.accepted ? this->accepted > s.accepted : (this->getTi() != s.getTi() ? this->getTi() < s.getTi() : this->teamNum > s.teamNum);
	};
	int getTi() const {
		return this->time + this->penaltyTime;
	};
};

int main() {
	while(1){
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		
		if(!M && !T && !P && !R) break;
		
		score *sc = new score[1+T];
		for(int i = 1; i <= T; i++){
			sc[i].teamNum = i;
		}
		for(int i = 0; i < R; i++){
			int m, t, p, r;
			cin >> m >> t >> p >> r;
			
			if(r){
				sc[t].miss.push_back(p);
			}else{
				sc[t].accepted++;
				sc[t].time += m;
				if(find(sc[t].miss.begin(), sc[t].miss.end(), p) != sc[t].miss.end()) sc[t].penaltyTime += 20;
			}
		}
		
		sort(&sc[1], &sc[1+T]);
		for(int i = 1; i <= T; i++){
			cout << sc[i].teamNum << (i==T ? '\n' : (sc[i]==sc[i+1] ? '=' : ','));
		}
	}
	return 0;
}