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;

struct Team {
  int time,correct,team_num;
};

int main(){
  Team data[51];
  int i,j,M,T,P,R,m,t,p,wrong[51][11];
  while(1){
     for( i = 0; i < 51; i++ ){
    for( j = 0; j < 51; j++ ){
    	wrong[i][j] = 0;
     }
      }
    cin >> M >> T >> P >> R;
    if ( M == 0 && T == 0 && P == 0 && R == 0 ) break;

    for( i = 1; i <= T; i++ ){
      data[i].time = 0;
      data[i].correct = 0;
      data[i].team_num = i;
    }
  
    for( i = 1; i <= R; i++ ){
      cin >> m >> t >> p >> j;
      if( j == 0 ){
	data[t].correct++;
	data[t].time += m + wrong[t][p] * 20;
      }else wrong[t][p]++; 
    }

    for( i = 1; i <= T; i++ ){
      for( j = 1; j < T; j++ ){
	if( data[j].team_num < data[j+1].team_num ) 
	  swap( data[j],data[j+1] );
      }
    }

    for( i = 1; i <= T; i++ ){
      for( j = 1; j < T; j++ ){
	if( data[j].time > data[j+1].time ) swap( data[j],data[j+1] );
      }
    }

    for( i = 1; i <= T; i++ ){
      for( j = 1; j < T; j++ ){
	if( data[j].correct < data[j+1].correct )
	  swap( data[j],data[j+1] );
      }
    }
   
    for( i = 1; i <= T-1; i++ ){
      cout << data[i].team_num;
      if( data[i].correct > data[i+1].correct )	cout << ",";
      else if( data[i].time < data[i+1].time ) cout <<  ",";
      else cout << "=";
      }
    cout << data[T].team_num << endl;

  }

  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int m,t,p,r;
    cin >> m >> t >> p >> r;
    if(m==0) return 0;
    vector<vector<int>> w(t,vector<int>(p,0));
    vector<int> ac(t,0);
    vector<int> pn(t,0);
    int keika,team,prob,judge;
    rep(i,r){
      cin >> keika >> team >> prob >> judge;
      team--,prob--;
      if(judge==0){
        ac[team]++;
        pn[team]+=keika+w[team][prob]*20;
      }else{
        w[team][prob]++;
      }
    }
    vector<int> id(t);
    iota(all(id),0);
    sort(all(id),[&](const int &l, const int &r){
      return ac[l]==ac[r]?(pn[l]==pn[r]?l>r:pn[l]<pn[r]):ac[l]>ac[r];
    });
    rep(i,t){
      if(i>0){
        if(ac[id[i-1]]==ac[id[i]]&&pn[id[i-1]]==pn[id[i]]) cout << '=';
        else cout << ',';
      }
      cout << id[i]+1;
    }
    cout << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int x[99][2],y[99][20],n,a,b,c,d,e,f,g,h,p;
int main() {
	while(true) {
		memset(x,0,sizeof(x));
		memset(y,0,sizeof(y));
		cin>>n>>a>>b>>c;
		if(n==0){
			break;
		}
		for(int i=0;i<c;i++){
			cin>>d>>e>>f>>g;
			if(g!=0){
				y[e][f]+=20;
			}
			else{
				x[e][1]+=d+y[e][f];
				x[e][0]++;
			}
		}
		p=0;
		for(int i=b;i>=0;i--){
			for(int j=0;j<=99999;j++){
				h=0;
				for(int k=a;k>0;k--){
					if(x[k][0]==i&&x[k][1]==j){
						if(h>=1){
							cout<<'=';
						}
						else if(p>=1){
							cout<<',';
						}
						cout<<k;
						p++;
						h++;
					}
				}
			}
		}
		cout<<endl;
	}
}

C++: #include "bits/stdc++.h"
#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define P(s) cout<<(s)<< endl
#define P2(a, b) cout<<(a) << " " << (b) << endl
using namespace std;
typedef long long ll;

struct teams{
	int ac=0;
	int time=0;
	int team_name=0;
};

bool cmp(const teams &A, const teams &B){
	return A.ac > B.ac ||
		(A.ac == B.ac && A.time < B.time) ||
		(A.ac == B.ac && A.time == B.time && A.team_name > B.team_name);
}

int main() {
	int M,T,P,R;
	while(cin >> M >> T >> P >> R && M){
		int m,t,p,j;
		vector<vector<int>> ac(T,vector<int>(P,0));
		vector<vector<int>> time(T,vector<int>(P,0));
		vector<vector<int>> pena(T,vector<int>(P,0));

		REP(i,0,R){
			cin >> m >> t >> p >> j;
			t--;p--;
			if(j==0){
				ac[t][p]++;
				time[t][p]+=m+pena[t][p]*20;
			}else{
				pena[t][p]++;
			}
		}
		vector<teams> ranp;
		REP(i,0,T){
			teams team;
			REP(j,0,P){
				team.ac+=ac[i][j];
				team.time+=time[i][j];
			}
			team.team_name=i+1;
			ranp.push_back(team);
		}

		sort(ranp.begin(),ranp.end(),cmp);
		/**
		for(auto r : ranp){
			P2(r.team_name,r.ac);
		}
		 **/

		cout << ranp[0].team_name;
		REP(i,1,ranp.size()){
			if(ranp[i-1].ac==ranp[i].ac && ranp[i-1].time==ranp[i].time){
				cout << '=' << ranp[i].team_name;
			}else{
				cout << ',' << ranp[i].team_name;
			}
		}
		cout << endl;
	}
	return 0;
}