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 <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 1000000
 
using namespace std;
typedef long long ll;
 
bool checkmtpj(int m,int t,int p,int j){
	if(m==0 && t==0 && p==0 && j==0) return true;
	else return false;
}

int main(){
	int M,T,P,R;
	int mk[2000],tk[2000],pk[2000],jk[2000];


	struct Teishutsu{
		int team;
		int ansN;
		int time;
		int problem[11];
		bool flag;
	};
	

	while(1){
		cin>>M>>T>>P>>R;
		Teishutsu juni[51],tmp;


		for(int i=0;i<2000;i++){
			mk[i]=0;
			tk[i]=0;
			pk[i]=0;
			jk[i]=0;
		}

		for(int i=1;i<=R;i++){
			cin>>mk[i]>>tk[i]>>pk[i]>>jk[i];
		}
		

		/*-------------------構造体初期化処理-----------------*/
		for(int i=1;i<=T;i++){
			juni[i].team=i;
			juni[i].ansN=0;
			juni[i].time=0;
			for(int j=1;j<=11;j++){
				juni[i].problem[j]=0;
			}
			juni[i].flag=false;
		}
		/*-------------------------------------------------------*/

		/*---------------------構造体への入力---------------------*/
		for(int i=1;i<=R;i++){
			if(jk[i]==0){
				juni[tk[i]].ansN++;
				juni[tk[i]].time+=mk[i];
				if(juni[tk[i]].problem[pk[i]] != 0){
					juni[tk[i]].time+=juni[tk[i]].problem[pk[i]]*20;
				}
			}else {
				juni[tk[i]].problem[pk[i]]++;
			}
//cout<<tk[i]<<" "<<juni[tk[i]].ansN<<" "<<juni[tk[i]].time<<endl;
		}
		
		/*----------------------------------------------------------*/
		
		for(int i=1;i<=T;i++){
			for(int j=1;j<=T-i;j++){
				if(juni[j].ansN<juni[j+1].ansN){
					tmp.team=juni[j+1].team;
					tmp.ansN=juni[j+1].ansN;
					tmp.time=juni[j+1].time;
					tmp.flag=juni[j+1].flag;
					
					juni[j+1].team=juni[j].team;
					juni[j+1].ansN=juni[j].ansN;
					juni[j+1].time=juni[j].time;
					juni[j+1].flag=juni[j].flag;
					
					juni[j].team=tmp.team;
					juni[j].ansN=tmp.ansN;
					juni[j].time=tmp.time;
					juni[j].flag=tmp.flag;
				}
			}
		}

		for(int i=1;i<=T;i++){
			for(int j=1;j<=T-i;j++){
				if(juni[j].time>juni[j+1].time && juni[j].ansN==juni[j+1].ansN){
					tmp.team=juni[j+1].team;
					tmp.ansN=juni[j+1].ansN;
					tmp.time=juni[j+1].time;
					tmp.flag=juni[j+1].flag;
					
					juni[j+1].team=juni[j].team;
					juni[j+1].ansN=juni[j].ansN;
					juni[j+1].time=juni[j].time;
					juni[j+1].flag=juni[j].flag;

					juni[j].team=tmp.team;
					juni[j].ansN=tmp.ansN;
					juni[j].time=tmp.time;
					juni[j].flag=tmp.flag;
				}else if(juni[j].time==juni[j+1].time && juni[j].ansN==juni[j+1].ansN){
					juni[j].flag=true;
					
					if(juni[j].team<juni[j+1].team){
						tmp.team=juni[j+1].team;
						tmp.ansN=juni[j+1].ansN;
						tmp.time=juni[j+1].time;
						tmp.flag=juni[j+1].flag;
					
						juni[j+1].team=juni[j].team;
						juni[j+1].ansN=juni[j].ansN;
						juni[j+1].time=juni[j].time;
						juni[j+1].flag=juni[j].flag;

						juni[j].team=tmp.team;
						juni[j].ansN=tmp.ansN;
						juni[j].time=tmp.time;
						juni[j].flag=tmp.flag;
					}
				}
			}
		}


		for(int i=1;i<=T;i++){
			if(i==1){}
			else{
				if(juni[i].flag) cout<<"=";
				else cout<<",";
			}
			cout<<juni[i].team;
			
		}
		cout<<endl;
		if(checkmtpj(mk[R],tk[R],pk[R],jk[R])) break;
	}
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(void){
    int m,t,p,r;
    int mk,tk,pk,jk;
    int a[2][50][10];
    vector<pair<int,int> > vp;
    int i,j,k,x,y,z;
    while(true){
        cin >> m >> t >> p >> r;
        if(m == 0) break;
        memset(a,0,sizeof(a));
        for(i = 0;i < r;i++){
            cin >> mk >> tk >> pk >> jk;
            tk--;pk--;
            if(jk){
                a[0][tk][pk] += 20;
            }
            else{
                a[1][tk][pk] = mk + a[0][tk][pk];
            }
        }
        vp.clear();
        for(i = 0;i < t;i++){
            x = 0;
            y = 0;
            for(j = 0;j < p;j++){
                if(a[1][i][j]){
                    x++;
                    y+=a[1][i][j];
                }
            }
            vp.push_back(make_pair(x*900000-y,i));
        }
        sort(vp.begin(),vp.end());
        i = vp.size();
        x = vp[--i].first;
        cout << vp[i].second+1;
        for(;i > 0;){
            if(x == vp[--i].first){
                cout << "=";
            }
            else cout << ",";
            x = vp[i].first;
            cout << vp[i].second+1;
        }
        cout << endl;
    }
}