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<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

struct team{
	long long int id,ac[15]={},tim[15]={},sumtime=0,sumac=0;
};

long long int M,T,P,R;

bool cmp(team x,team y){
	
	if(x.sumac!=y.sumac){
		return y.sumac<x.sumac;
	}
	else if(x.sumtime!=y.sumtime){
		return x.sumtime<y.sumtime;
	}else{
		return y.id<x.id;
	}
}
bool samecmp(team x,team y){
	
	if(x.sumac!=y.sumac){
		return false;
	}
	else if(x.sumtime!=y.sumtime){
		return false;
	}else{
		return true;
	}
}
int main() {
	
	cout << fixed << setprecision(18);
	cin>>M>>T>>P>>R;
	while(M!=0){
		team te[55];
		for(int i=1;i<=T;i++){te[i].id=i;}
		for(int i=0;i<R;i++){
			long long int m,t,p,j;
			cin>>m>>t>>p>>j;
			if(j==0){te[t].ac[p]=1;te[t].tim[p]+=m;}
			else{te[t].tim[p]+=20;}
		}
		
		for(int i=1;i<=T;i++){
			for(int v=1;v<=P;v++){
				te[i].sumac+=te[i].ac[v];
				te[i].sumtime+=te[i].ac[v]*te[i].tim[v];
			}
		}
		sort(te+1,te+T+1,cmp);
		cout<<te[1].id;
		for(int i=2;i<=T;i++){
			if(samecmp(te[i],te[i-1])){
				cout<<"="<<te[i].id;
			}else{
				cout<<","<<te[i].id;
			}
		}
		cout<<endl;
		cin>>M>>T>>P>>R;
	}

}

C++: #include<iostream>
#include<string>
#include<vector>
#include<tuple>
#include<set>
#include<map>
#include<algorithm>
using namespace std;

struct Record {
  int tid, pid, time;
  bool correct;
};

struct Team {
  Team() {
    penalty = 0;
  }
  set<int> solved;
  map<int, int> WA;
  int penalty;
};

// Solved Problems, Penalty, Team ID
typedef tuple<int, int, int> Score;

int main() {
  int M, T, P, R;
  while (cin >> M >> T >> P >> R && M) {
    vector<Record> records(R);
    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      records[i].pid = --p;
      records[i].tid = --t;
      records[i].time = m;
      records[i].correct = (j == 0);
    }

    vector<Team> teams(T);
    for (Record r : records) {
      if (teams[r.tid].solved.find(r.pid) != teams[r.tid].solved.end()) {
        continue;
      } else if (r.correct) {
        teams[r.tid].solved.insert(r.pid);
        teams[r.tid].penalty +=
          teams[r.tid].WA[r.pid] * 20 + r.time;
      } else {
        teams[r.tid].WA[r.pid]++;
      }
    }

    vector<Score> team_result(T);
    for (int i = 0; i < T; i++) {
      get<0>(team_result[i]) = -teams[i].solved.size();
      get<1>(team_result[i]) = teams[i].penalty;
      get<2>(team_result[i]) = -i;
    }

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

    for (int i = 0, len = team_result.size(); i < len; i++) {
      Score s = team_result[i];
      if (i > 0) {
        Score p = team_result[i - 1];
        cout << 
          (get<0>(p) == get<0>(s) && get<1>(p) == get<1>(s)?"=":",");
      }
      cout << -get<2>(s)+1;
    }
    cout << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> S;
int wa[51][11];
int OK[11];
vector<S> v;

//比較関数
bool comp(S lhs, S rhs){
	if(lhs.first != rhs.first){
		return lhs.first < rhs.first;
	}
	if(lhs.second.first != rhs.second.first){
		return lhs.second.first > rhs.second.first;
	}
	if(lhs.second.second != rhs.second.second){
		return lhs.second.second < rhs.second.second;
	}
}

int main(){
while(1){//start
	
	int M, T, P, R;
	cin >> M >> T >> P >> R;
	if(M == 0 and T == 0 and P == 0 and R == 0) break;

	//初期化
	v.resize(T);
	for(int i = 0; i < 51; i++){
		for(int j = 0; j < 11; j++) wa[i][j] = 0;
	}
	for(int i = 0; i < 11; i ++) OK[i] = 0;
	
	
	//データを格納
	for(int i = 0; i < R; i++){
		int m, t, p, j;
		cin >> m >> t >> p >> j;

		if(j == 0){
			v[t - 1].second.first += m + 20*wa[t][p]; 
			OK[t-1] += 1;
		}
		else{
			wa[t][p] += 1;
		}
	}
	
	//vectorにデータを入れる
	for(int i = 1; i <= T; i++){
		//v.push_back(make_pair(OK[i-1], make_pair(sum_m, i)));
		v[i-1].first = OK[i-1];
		v[i-1].second.second = i;
	}
	
	sort(v.begin(), v.end(), comp);
	reverse(v.begin(), v.end());
	
}//end	
	return 0;
}