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>
using namespace std;

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

    int cp[50],tt[50],pt[50][10];
    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 tnow, tpre = -1;
    bool flg[50];
    for(int i=0; i<T; i++)
      flg[i] = false;

    for(int i=0; i<T; i++){
      tnow =-1;
      for(int j=0; j<T; j++){
        if(flg[j])
          continue;

        if(tnow==-1){
          tnow = j;
        }
        else{
          if(cp[j]>cp[tnow] || (cp[j]==cp[tnow] &&tt[j]<=tt[tnow])){
            tnow = j;
          }
        }
      }

      if(tpre!=-1){
        if(cp[tnow]==cp[tpre] && tt[tnow]==tt[tpre])
          cout<<'=';
        else
          cout<<',';
      }
      cout<<tnow+1;

      flg[tnow] = true;
      tpre = tnow;
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
struct A{int slv,pe,num;};
bool comp(A a,A b){
      if(a.slv!=b.slv)return a.slv>b.slv;
      if(a.pe!=b.pe)return a.pe<b.pe;
      return a.num>b.num;
}
int main(){
      int m,t,p,r,mm,tt,pp,rr;
      while(cin>>m>>t>>p>>r&&t&&p){
            int pe[t],miss[t][p],slv[t];
            memset(miss,0,sizeof(miss));
            memset(pe,0,sizeof(pe));
            memset(slv,0,sizeof(slv));
            while(r--){
                  cin>>mm>>tt>>pp>>rr;tt--;pp--;
                  if(rr==0){
                        slv[tt]++;
                        pe[tt]+=miss[tt][pp]*20+mm;
                  }else{
                        miss[tt][pp]++;
                  }
            }
            vector<A> V;
            REP(i,t)V.PB((A){slv[i],pe[i],i});
            sort(ALL(V),comp);
            REP(i,t){
                  int s=i;
                  while(V[s].slv==V[i].slv&&V[s].pe==V[i].pe&&i<t)i++;
                  for(int j=s;j<i;j++){
                        cout<<V[j].num+1;
                        if(j!=i-1)cout<<"=";
                  }
                  if(i==t)cout<<endl;
                  else cout<<",";
                  i--;
            }
      }
}

C++: #include <bits/stdc++.h>
using namespace std;

bool func() {
    int M, T, P, R;
    typedef struct{
        int m;
        int t;
        int p;
        int j;
    } Data;
    vector<Data> datas;

    typedef struct {
        int id;
        int solve;
        int time;
        vector<int> pena; 
    } Team;
    vector<Team> teams;

    cin >> M >> T >> P >> R;
    if(M==0 && T==0 && P==0 && R==0) return true;

    for(int i=0; i<T; i++) {
        vector<int> tmpvec(P, 0);
        Team t = {i+1, 0, 0, tmpvec};
        teams.push_back(t);
    }

    for(int i=0; i<R; i++) {
        int m, t, p, j;
        cin >> m >> t >> p >> j;
        Team team = teams[t-1];
        if(j==0) {
            team.solve += 1;
            team.time += team.pena[p-1] * 20 + m;
        } else {
            team.pena[p-1] += 1;
        }
        teams[t-1] = team;
    }
    sort(teams.begin(), teams.end(), [](const Team& a, const Team& b){
        if(a.solve == b.solve && a.time == b.time) return a.id > b.id;
        else if(a.solve == b.solve) return a.time < b.time;
        else return a.solve > b.solve;
    }); 

    vector<int> tmpvec;
    Team pre = {-1, -1, -1, tmpvec};
    char delimiter = ',';
    for(Team t: teams) {
        if(pre.solve!=-1) {
            if(pre.solve==t.solve && pre.time==t.time) delimiter = '=';
            else delimiter = ',';
            printf("%c", delimiter);
        }
        pre = t;
        printf("%d", t.id);
    }
    printf("\n");
    return false;
}

int main() {
    bool flag = false;
    while(!flag) {
        flag = func();
    }
    return 0;
}

C++: #include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>
using namespace std;
int T,N,M,Q,A,B,C,D;
int b[999],c[999][999],d[999][999];
int main(){
	while(true){
		for(int i=0;i<999;i++){
			for(int j=0;j<999;j++){
				b[i]=0;
				c[i][j]=-1;
				d[i][j]=0;
			}
		}
		cin>>T>>N>>M>>Q;
		if(T==0){break;}
		for(int i=0;i<Q;i++){
			cin>>A>>B>>C>>D;
			if(c[B][C]==-1){
				if(D==0){
					c[B][C]=A;
					b[B]++;
				}
				else{
					d[B][C]+=20;
				}
			}
		}
		vector<tuple<int,int,int>>vec;
		for(int i=1;i<=N;i++){
			int sum=0;
			for(int j=1;j<=M;j++){
				if(c[i][j]>=0){
					sum+=c[i][j]+d[i][j];
				}
			}
			vec.push_back(make_tuple(b[i],-sum,i));
		}
		sort(vec.begin(),vec.end());
		cout<<get<2>(vec[vec.size()-1]);
		for(int i=(int)(vec.size())-2;i>=0;i--){
			if(get<0>(vec[i])==get<0>(vec[i+1]) && get<1>(vec[i])==get<1>(vec[i+1])){
				cout<<"=";
			}
			else{cout<<',';}
			cout<<get<2>(vec[i]);
		}
		cout<<endl;
	}
}