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 <string>

using namespace std;

class team_obj{
	public:
	int ansNum;
	int penalty;
	int wrongNum[10];
	int teamNum;
	int time;
};

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){

	team_obj team[50];
	int ansLine[20];

	for(int i=0;i<50;i++){
		team[i].ansNum=0;
		team[i].penalty=0;
		for(int j=0;j<10;j++){
			team[i].wrongNum[j]=0;
		}
		team[i].teamNum=i;
	}

	int m,t,p,r;
	while(cin>>m>>t>>p>>r){
		if(m==0 && t==0 && p==0 && r==0)break;
			
		int tid,pid,tim;
		string str;
		for(int i=0;i<50;i++){
			team[i].ansNum=0;
			team[i].penalty=0;
			for(int j=0;j<10;j++){
				team[i].wrongNum[j]=0;
			}
			team[i].teamNum=i;
			team[i].time=0;
		}
		for(int i=0;i<20;i++)ansLine[i]=0;

		for(int i=0;i<r;i++){
			int jk;
			cin>>tim>>tid>>pid>>jk;
			tid--;
			pid--;

			if(team[tid].wrongNum[pid]==-1)continue;

			if(jk!=0){
				team[tid].wrongNum[pid]++;
			}
			else{
				team[tid].penalty+=team[tid].wrongNum[pid]*20;
				team[tid].wrongNum[pid]=-1;
				team[tid].ansNum++;
				team[tid].time+=tim;
			}
		}

		for(int i=0;i<t;i++){
			team[i].penalty+=team[i].time;
		}
/*
		for(int i=0;i<t;i++){
			cout<<"i="<<i<<endl;
			cout<<team[i].ansNum<<" "<<team[i].penalty<<endl;
		}
		*/
		//答え数のソートを行う。
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].ansNum>=team[j-1].ansNum){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}
		//答え数の数を数える。
		for(int i=0;i<t;i++){
			ansLine[team[i].ansNum]++;
		}

		//次はペナルティにてソートを行う。
		//ペナルティにてソートを行う際、回答数が同じ場合のみ交換を行う。
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].penalty<=team[j-1].penalty && team[j].ansNum == team[j-1].ansNum){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}
		//最後にチーム番号にてソートを行う。
		//回答数とペナルティ数が同じ場合のみソートを実行
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].teamNum>=team[j-1].teamNum && team[j].ansNum == team[j-1].ansNum && team[j].penalty == team[j-1].penalty){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}

		//解答出力
		for(int i=0;i<t;i++){
			team[i].teamNum++;
			if(i!=t-1){
				cout<<team[i].teamNum;
				if(team[i].ansNum==team[i+1].ansNum && team[i].penalty == team[i+1].penalty){
					cout<<'=';
				}
				else{
					cout<<',';
				}
			}
			else{
				cout<<team[i].teamNum<<endl;
			}
		}
	}

	return 0;
}

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);



	}
}