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<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){
    typedef struct TEAM{
        int AC;
        int WA[12];
        int PE;
        int num;
    } team;

    while(1){
        int m, t, p, r; cin >> m >> t >> p >> r;
        if(t == 0) break;
        team Team[55];
        
        //?????????
        for(int i = 1; i <= t; i++){
            Team[i].num = i;
            Team[i].AC = 0;
            Team[i].PE = 0;
            for(int j = 1; j <= p; j++) Team[i].WA[j] = 0;
        }

        
        //?????°????????????
        for(int i = 0; i < r; i++){
            int tID, pID, ti; cin  >> ti >> tID >> pID;
            int j; cin >> j;

            if(j != 0){
                Team[tID].WA[pID]++;
            }else{
                Team[tID].AC++;
                Team[tID].PE += Team[tID].WA[pID] * 20 + ti;
            }
        }

        int flag = 1;

        while(flag == 1){
            flag = 0;
            for(int i = 1; i < t; i++){
                if(Team[i].num < Team[i + 1].num){
                    team temp;
                    temp = Team[i];
                    Team[i] = Team[i + 1];
                    Team[i + 1] = temp;
                    flag = 1;
                    //if(Team[i].PE == Team[j].PE) cout << "nuko" << endl;
                }
            }
        }

        flag = 1;

        while(flag == 1){
            flag = 0;
            for(int i = 1; i < t; i++){
                if(Team[i].PE > Team[i + 1].PE){
                    team temp;
                    temp = Team[i];
                    Team[i] = Team[i + 1];
                    Team[i + 1] = temp;
                    flag = 1;
                    //if(Team[i].PE == Team[j].PE) cout << "nuko" << endl;
                }
            }
        }

        flag = 1;
        while(flag == 1){
            flag = 0;
            for(int i = 1; i < t; i++){
                if(Team[i].AC < Team[i + 1].AC){
                    team temp;
                    temp = Team[i];
                    Team[i] = Team[i + 1];
                    Team[i + 1] = temp;
                    flag = 1;
                    //if(Team[i].PE == Team[j].PE) cout << "nuko" << endl;
                }
            }
        }

        for(int i = 1; i <= t; i++){
            if(i == t) cout << Team[i].num;
            else if(Team[i].AC == Team[i + 1].AC && Team[i].PE == Team[i + 1].PE) cout << Team[i].num << "=";
            else cout << Team[i].num << ",";
        }
        cout << endl;
    }

    
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

using Tup = tuple<int64, int64, int64>;

int main(void){
	int64 M, T, P, R;
	while(cin >> M >> T >> P >> R && M+T+P+R){
		vector<vector<int64>> solved(T, vector<int64>(P, 0));
		vector<Tup> res(T);
		REP(i, T) res[i] = Tup(0, 0, i);
		REP(i, R){
			int32 m, t, p, j;
			cin >> m >> t >> p >> j; t--; p--;
			if(solved[t][p] <= 0){
				if(j == 0){
					int64 a, b, c;
					tie(a, b, c) = res[t];
					a++;
					b += solved[t][p]-m;
					res[t] = Tup(a, b, c);
					solved[t][p] = 1;
				}else{
					solved[t][p] -= 20;
				}
			}
		}
		sort(all(res), greater<Tup>());
		REP(i, T-1){
			cout << get<2>(res[i])+1;
			if(get<0>(res[i]) == get<0>(res[i+1]) && get<1>(res[i]) == get<1>(res[i+1]))
				cout << '=';
			else
				cout << ',';
		}
		cout << get<2>(res[T-1])+1 << endl;
	}
}

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 = 01;
    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;
}