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 <algorithm>
#include <iostream>
#define MAX_R 2001
#define MAX_T 51
#define MAX_P 11
using namespace std;

void mysort(int ac[MAX_T], int sum[MAX_T], int rank[MAX_T], int n) {
  for (int i = 1; i <= n; i++) {
    for (int j = i; j > 1; j--) {
      if (ac[j - 1] < ac[j] || ac[j - 1] == ac[j] && sum[j - 1] > sum[j]
	  || ac[j - 1] == ac[j] && sum[j - 1] == sum[j] && rank[j - 1] < rank[j]) {
	swap(ac[j - 1], ac[j]);
	swap(sum[j - 1], sum[j]);
	swap(rank[j - 1], rank[j]);
      }
    }
  }
}

int main() {
  while (true) {
    int m[MAX_R], t[MAX_R], p[MAX_R], j[MAX_R];
    int ac[MAX_T], sum[MAX_T], wa[MAX_T][MAX_P], rank[MAX_T];
    int M, T, P, R;
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0) return 0;

    for (int i = 0; i < MAX_R; i++) {
      m[i] = t[i] = p[i] = j[i] = 0;
    }
    for (int i = 0; i < MAX_T; i++) {
      ac[i] = sum[i] = 0;
      for (int j = 0; j < MAX_P; j++) {
	wa[i][j] = 0;
      }
    }
    for (int i = 0; i < MAX_T; i++) {
      rank[i] = i;
    }
    
    for (int i = 0; i < R; i++) {
      cin >> m[i] >> t[i] >> p[i] >> j[i];
    }

    for (int i = 0; i < R; i++) {
      int team = t[i];
      int minute = m[i];
      int problem = p[i];
      if (j[i] == 0) {
	ac[team]++;
	sum[team] += minute + wa[team][problem] * 20;
      } else {
	wa[team][problem]++;
      }
    }

    mysort(ac, sum, rank, T);

    for (int i = 1; i <= T; i++) {
      if (i == T) {
	cout << rank[i] << endl;
      } else if (ac[i] == ac[i + 1] && sum[i] == sum[i + 1]) {
	cout << rank[i] << '=';
      } else {
	cout << rank[i] << ',';
      }
    }
  }
}

C++: #include<iostream>
using namespace std;

int main(){
 while(true){
  int M, T, P, R;
  cin >> M >> T >> P >> R;

  if(M==0 && T==0 && P==0 && R==0) break;

  int CP[T],  TT[T],  PT[T][P]; //正解数、時間計、ペナルティ
  for(int i=0; i<T; i++){
   CP[i] = TT[i] = 0;
   for(int j=0; j<P; j++){
    PT[i][j] = 0;
   }
  }

  for(int i=0; i<R; i++){ //各チームの正解数、時間計を求める
   int m, t, p, j;
   cin >> m >> t >> p >> j;
   
   if(j==0){ //正解
    CP[t-1]++;
    TT[t-1] += (m+PT[t-1][p-1]);
   }else{ //不正解
    PT[t-1][p-1] += 20;
   }
  }

   int t_now, t_pre = -1; //今のチーム、1つ前のチーム
   bool flag[50]; //処理済みフラグ
   for(int i=0; i<T; i++){
    flag[i] = false;
   }
   
   for(int i=0; i<T; i++){
    t_now = -1;
    for(int j=0; j<T; j++){ //今のチームを求める
     if(flag[j]) continue;
     if(t_now==-1){
      t_now = j;
     }else{
      if(CP[j]>CP[t_now] || (CP[j]==CP[t_now] && TT[j]<=TT[t_now])){
       t_now = j;
      }
     }
    }

    if(t_pre!=-1){
     if(CP[t_now]==CP[t_pre] && TT[t_now]==TT[t_pre]){
      cout << '=';
     }else{
      cout << ',';
     }
    }
    cout<<t_now+1;

    flag[t_now] = true;
    t_pre = t_now;
   }
   cout << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

struct Team
{
	int solved, penalty, no;
	bool operator < (const Team &a) const
	{
		if(solved != a.solved) return solved > a.solved;
		if(penalty != a.penalty) return penalty < a.penalty;
		return no > a.no;
	}
	int compareTo(Team a)
	{
		if(solved != a.solved) 
		{
			if(solved > a.solved) return 1;
			else return -1;
		}
		if(penalty != a.penalty) 
		{
			if(penalty < a.penalty) return 1;
			else return -1;
		}
		return 0;
	}
} team[50];

int wrongCnt[50][10];

int main(void)
{
	int m, t, p, r;
	while(scanf("%d %d %d %d", &m, &t, &p, &r), m)
	{
		memset(wrongCnt, 0, sizeof(wrongCnt));
		for(int i=0;i<t;i++) 
		{
			team[i].solved = team[i].penalty = 0;
			team[i].no = i;
		}

		for(int i=0;i<r;i++)
		{
			int mk, tk, pk, jk;
			scanf("%d %d %d %d", &mk, &tk, &pk, &jk);
			tk--, pk--;
			if(jk == 0) 
			{
				team[tk].penalty += mk + wrongCnt[tk][pk] * 20;
				team[tk].solved++;
			}
			else wrongCnt[tk][pk]++;
		}

		sort(team, team + t);
		for(int i=0;i<t;i++)
		{
			int e = i;
			while(e < t && team[i].compareTo(team[e]) == 0) e++;
			if(i) printf(",");
			for(int j=i;j<e;j++)
			{
				if(j != i) printf("=");
				printf("%d", team[j].no + 1);
			}
			i = e - 1;
		}
		printf("\n");
	}

	return 0;
}

C++: 
	int M, T, P, R;
	cin >> M >> T >> P >> R;

	vector<Team> teams(T, Team(P));

	for (int i = 0; i < T; ++i) {
		teams[i].num = i + 1;
	}

	for (int i = 0; i < R; ++i) {
		int m, t, p, j;
		cin >> m >> t >> p >> j;

		// judge is incorrect.
		if (j != 0) {
			teams[t - 1].incorrects[p - 1]++;
			continue;
		}

		// judge is correct.
		teams[t - 1].corrects[p - 1] = 1;

		int time = m + teams[t - 1].incorrects[p - 1] * 20;
		teams[t - 1].time = time;
	}

	sort(teams.begin(), teams.end());

	int time = 0;
	for (int i = 0; i < teams.size(); ++i) {
		auto&& t = teams[i];
		
		int c = count(t.corrects.begin(), t.corrects.end(), 1);
		

		if (i == teams.size() - 1) {
			cout << t.num << endl;
			break;
		}

		auto&& nt = teams[i + 1];

		int nc = count(nt.corrects.begin(), nt.corrects.end(), 1);

		if (c == nc && nt.time == t.time) {
			cout << t.num << '=';
		}
		else {
			cout << t.num << ',';
		}
	}