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++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

struct Team{
public:
  int solved;
  int elapsed_time;
  int penalty;
  int id;
  Team() : solved(0),elapsed_time(0),penalty(0),id(0){}
  bool operator<(const Team& t) const{
    if(__builtin_popcount(solved) == __builtin_popcount(t.solved)){
      if((elapsed_time + penalty) == (t.elapsed_time + t.penalty)){
	return id > t.id;
      }
      else{
	return ((elapsed_time + penalty) < (t.elapsed_time + t.penalty)); 
      }
    }
    else{
      return (__builtin_popcount(solved) > __builtin_popcount(t.solved));
    }
  }
  bool operator==(const Team& t) const{
    if(__builtin_popcount(solved) == __builtin_popcount(t.solved)
       && (elapsed_time + penalty) == (t.elapsed_time + t.penalty)){
      return true;
    }
    return false;
  }
};

int main(){
  int duration;
  int total_teams;
  int total_problems;
  int total_submission_records;
  while(~scanf("%d %d %d %d",
	       &duration,
	       &total_teams,
	       &total_problems,
	       &total_submission_records)){

    if(duration == 0
       && total_teams == 0
       && total_problems == 0
       && total_submission_records == 0) break;

    Team teams[51];
    int freq[51][11];
    
    memset(freq,0,sizeof(freq));
    for(int team_idx=0;team_idx < total_teams; team_idx++){
      teams[team_idx].id = team_idx+1;
    }
    for(int submit_idx=0;submit_idx< total_submission_records; submit_idx++){
      int elapsed_time;
      int team_number;
      int problem_number;
      int judgement;
      scanf("%d %d %d %d",
	    &elapsed_time,
	    &team_number,
	    &problem_number,
	    &judgement);
      if(judgement == 0){
	teams[team_number-1].elapsed_time
	  += elapsed_time;
	teams[team_number-1].penalty
	  += freq[team_number-1][problem_number-1] * 20;
	freq[team_number-1][problem_number-1] = 0;
	teams[team_number-1].solved |= (1<<(problem_number-1));
      }
      else{
	if(!(teams[team_number-1].solved & (1<<(problem_number-1)))){
	  freq[team_number-1][problem_number-1]++;
	}
      }
    }

    sort(teams,teams+total_teams);
    for(int team_idx=0;team_idx+1 < total_teams; team_idx++){
      if(teams[team_idx] == teams[team_idx+1]){
	printf("%d=",teams[team_idx].id);
      }
      else{
	printf("%d,",teams[team_idx].id);
      }
    }
    printf("%d\n",teams[total_teams-1].id);
  }
}

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

class Team{
public:
  int num;
  int solve;
  int time;
  vector<int> plist;
  Team():num(0),solve(0),time(0),plist(vector<int>(11,0)){}
};

bool compare_solve(const Team& left, const Team& right){
  return left.solve > right.solve;
}
bool compare_time(const Team& left, const Team& right){
  return left.time <= right.time;
}

int main(){
  int M, T, P, R;
  int m, t, p, j;
  vector<Team> team;
  for(;;){
    scanf("%d %d %d %d", &M, &T, &P, &R);
    if( M == 0 && T == 0 && P == 0 && R == 0)
      return 0;
    for(int i = 0; i < T; i++){  
      Team temp;
      temp.num = i+1;
      team.push_back(temp);
    }
    for(int i = 0; i < R; i++){
      scanf("%d %d %d %d", &m, &t, &p, &j);
      if(j != 0)
	team.at(t-1).plist.at(p) += 1;
      else{
	team.at(t-1).solve += 1; 
	team.at(t-1).time += m;
	team.at(t-1).time += team.at(t-1).plist.at(p) * 20;
      }
    }
    sort(team.begin(),team.end(),compare_time);
    stable_sort(team.begin(),team.end(),compare_solve);
    cout << team.at(0).num;
    for(int i = 1; i < T; i++){
      if(team.at(i-1).solve == team.at(i).solve && team.at(i-1).time == team.at(i).time)
	cout << "=";
      else
	cout << ",";
      cout << team.at(i).num;
    }
    cout << endl;
    team.clear();
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

pair<pint,int> cnt[51];//{cnt,-pena,id}
int pn[51][12];
int main(){
    int m,t,p,r;
    while(cin>>m>>t>>p>>r,m|t|p|r){
        rep(i,t) cnt[i]={{0,0},i+1};
        memset(pn,0,sizeof(pn));
        int mi,ti,pi,ji;
        rep(i,r){
            cin>>mi>>ti>>pi>>ji;
            --ti;
            if(ji==0){
                ++cnt[ti].first.first;
                cnt[ti].first.second-=mi+pn[ti][pi];
            }
            else{
                pn[ti][pi]+=20;
            }
        }
        sort(cnt,cnt+t);
        reverse(cnt,cnt+t);
        rep(i,t){
            cout<<cnt[i].second;
            if(i<t-1){
                if(cnt[i].first==cnt[i+1].first) cout<<"=";
                else cout<<",";
            }
        }
        cout<<endl;
    }
    return 0;
}