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++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
	while(1){
		ll m,t,p,r;
		cin>>m>>t>>p>>r;
		if(m==0)return 0;
		map<P,V<int>,greater<P>> mp;
		V<P> dat(t,P(0,0));
		V<V<ll>> mis(t,V<ll>(p,0));
		V<V<bool>> ac(t,V<bool>(p,false));
		for(int i=0;i<r;i++){
			ll a,b,c,d;
			cin>>a>>b>>c>>d;
			a--;b--;c--;
			if(d==0){
				if(ac[b][c])continue;
				ac[b][c]=true;
				dat[b].fi++;
				dat[b].se-=mis[b][c]*20+a;
			}else{
				mis[b][c]++;
			}
		}
		for(int i=0;i<t;i++){
			mp[dat[i]].emplace_back(i+1);
		}
		int cnt=0;
		for(auto p:mp){
			cnt++;
			sort(all(p.se),greater<int>());
			for(int i=0;i<p.se.size();i++){
					cout<<p.se[i];
					if(i!=(int)p.se.size()-1)cout<<'=';
			}
			if(cnt!=(int)mp.size())cout<<',';
		}
		cout<<"\n";
	}
}

C++: #include<stdio.h>
#include<string.h>
typedef struct {
	int id;
	int ac ;
	int time;
	int pt[300];
	int ok[20];

} Player;

int M, T, P,R;



void makeScore(int n, Player * A)
{
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= P; j++)
		{
			if (A[i].ok[j] == 0)
			{
				if (A[i].pt[j])
					A[i].time += (20 * A[i].pt[j]);
			}

		}
	
		
	}
}

void makeRank(int n, Player*A)
{
	int i, j;
	Player temp;
	for (int i = 0; i < n; i++)
		for (int j = n; j > i + 1; j--)
		{
			if (A[j].ac>A[j - 1].ac)
			{
				temp = A[j]; A[j] = A[j - 1]; A[j - 1] = temp;
			}
			else if (A[j].ac == A[j - 1].ac)
			{
				if (A[j].time < A[j - 1].time)
				{
					temp = A[j]; A[j] = A[j - 1]; A[j - 1] = temp;
				}
				else if (A[j].time == A[j - 1].time)
				{
					if (A[j].id > A[j - 1].id)
					{
						temp = A[j]; A[j] = A[j - 1]; A[j - 1] = temp;
					}
				}
			}
		}
}

void Print(int n, Player *A)
{
	int i;
	for (i = 1; i <= n; i++)
	{
		
		printf("%d", A[i].id);
		if (A[i].ac == A[i + 1].ac&&A[i].time==A[i+1].time && i != n)
			printf("=");
		else if (i != n)
			printf(",");
	}
	printf("\n");
}
int main()
{

	int i;
	int time, team, num, ok;
	Player plr[100];
	
	while (scanf("%d%d%d%d", &M, &T, &P, &R) && M || T || R || P)
	{
		for (int i = T; i>=1;i--)
		{
			memset(plr[i].pt, 0, sizeof(plr[i].pt));
			memset(plr[i].ok, -1, sizeof(plr[i].ok));
			plr[i].ac = plr[i].time = 0;
			plr[i].id = i;
		}
	
		for (i = 0; i < R; i++)
		{
			scanf("%d%d%d%d", &time, &team, &num, &ok);
			if (ok == 0)
			{
				plr[team].ac++;
				plr[team].time += time;
				plr[team].ok[num] = 0;
			}
			else
			{
				
				plr[team].pt[num]++;
			}
		}

		makeScore(T, plr);
		makeRank(T, plr);
		Print(T, plr);



	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> Team;
int AC[50][10],WA[50][10];
int main() {
    int  M,T,P,R;
    while(cin>>M>>T>>P>>R,M) {
        memset(AC,-1,sizeof(AC));
        memset(WA,0,sizeof(WA));
        for(int i=0;i<R;i++) {
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            t--;p--;
            if(j==0) {
                AC[t][p]=m;
            }else {
                WA[t][p]++;
            }
        }
        vector<Team> v;
        for(int i=0;i<T;i++) {
            int solved=0,penalty=0;
            for(int j=0;j<P;j++) {
                if(AC[i][j]!=-1) solved++,penalty+=AC[i][j]+WA[i][j]*20;
            }
            v.push_back(make_tuple(-solved,penalty,-(i+1)));
        }
        sort(v.begin(),v.end());
        printf("%d",-get<2>(v[0]));
        for(int i=1;i<v.size();i++) {
            if(get<0>(v[i-1])<get<0>(v[i])||get<1>(v[i-1])<get<1>(v[i])) putchar(',');
            else putchar('=');
            printf("%d",-get<2>(v[i]));
        }
        putchar('\n');
    }
}