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 <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

struct Team {
    Team(int team_number) {
        tn_ = team_number;
        n_ = 0;
        t_ = 0;
        pc_ = 0;
    }
    int tn_;
    int n_;
    int t_;
    int pc_;
    vector<int> p_list_;
};

int main (int argc, char *argv[]) {
    int M, T, P, R;
    int m, t, p, j;
    vector<Team> tv;

    while (cin>>M>>T>>P>>R) {
        for (int i = 0; i < T; ++i) {
            tv.push_back(Team(i+1));
        }
        for (int i = 0; i < R; ++i) {
            cin>>m>>t>>p>>j;
            if (j != 0) {
                tv[t-1].p_list_.push_back(p);
            }
            else {
                for (auto e : tv[t-1].p_list_) {
                    if (e == p) {
                        tv[t-1].pc_++;
                    }
                }
                tv[t-1].n_++;
                tv[t-1].t_ += m;
            }
        }
        for (auto& e : tv) {
            e.t_ += e.pc_ * 20;
        }

        // for (auto e : tv) {
        //     cout<<"-----------"<<endl;
        //     cout<<e.tn_<<endl;
        //     cout<<e.n_<<endl;
        //     cout<<e.t_<<endl;
        //     cout<<e.pc_<<endl;
        //     for (auto c : e.p_list_) {
        //         cout<<c<<" ";
        //     }
        //     cout<<endl;
        //     cout<<"-----------"<<endl;
        // }

        sort(tv.begin(), tv.end(), [](const auto& lhs, const auto& rhs) -> bool{
            if (lhs.n_ != rhs.n_ ) {
                return lhs.n_ > rhs.n_;
            }
            else if (lhs.n_ == rhs.n_ && lhs.t_ != rhs.t_) {
                return lhs.t_ < rhs.t_;
            }
            else return lhs.tn_ > rhs.tn_;
        });

        const int size = static_cast<int>(tv.size());
        for (int i = 0; i < size; ++i) {
            cout<<tv[i].tn_;
            if(i != size -1) {
                if (tv[i].n_ != tv[i+1].n_ || tv[i].t_ != tv[i+1].t_ ) {
                    cout<<",";
                }
                else cout<<"=";
            }
        }
        if cout<<endl;
        tv.clear();
    }

    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int a[50][2];
int b[50][10];

int main()
{
  while (1) {
    int m, t, p, r, i, j;
    vector <pair<int, pair<int, int> > > v;

    scanf("%d %d %d %d", &m, &t, &p, &r);

    if (m == 0 && t == 0 && p == 0 && r == 0) break;

    for (i = 0; i < t; i++) a[i][0] = a[i][1] = 0;
    for (i = 0; i < t; i++) {
      for (j = 0; j < p; j++) {
        b[i][j] = 0;
      }
    }

    for (i = 0; i < r; i++) {
      int m, t, p, j;

      scanf("%d %d %d %d", &m, &t, &p, &j);

      t--;
      p--;

      if (j == 0) {
        a[t][0]++;
        a[t][1] += b[t][p];
        a[t][1] += m;
      } else {
        b[t][p] += 20;
      }
    }

    for (i = 0; i < t; i++) v.push_back(make_pair(a[i][0], make_pair(-a[i][1], i + 1)));

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    printf("%d", v[0].second.second);

    for (i = 1; i < v.size(); i++) {
      if (v[i].first == v[i - 1].first && v[i].second.first == v[i - 1].second.first) {
        putchar('=');
      } else {
        putchar(',');
      }

      printf("%d", v[i].second.second);
    }

    puts("");
  }

  return 0;
}

C++: #include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<numeric>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);

struct Team {
	Team(int id_, int P) {
		id = id_;
		times.resize(P, INF);
		penalties.resize(P, 0);
	}

	int id;
	vector<int> times;
	vector<int> penalties;

	pair<int, int> score() const{
		int solveNum = 0;
		int penalty = 0;

		for (int time : times) {
			if (time != INF) {
				solveNum++;
				penalty += time;
			}
		}
		REP(i, times.size()) {
			if (times[i] != INF) {
				penalty += 20 * penalties[i];
			}
		}

		return { -solveNum,penalty };
	}

	const bool operator < (const Team r)const {
		if (score() == r.score()) {
			return id > r.id;
		}
		else {
			return score() < r.score();
		}
	}
};

//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	while (true) {
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		if (M == 0)break;

		vector<Team> teams;
		REP(i, T) {
			teams.push_back(Team(i + 1, P));
		}
		REP(i, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			p--;
			if (j == 0) {
				teams[t].times[p] = m;
			}
			else {
				teams[t].penalties[p]++;
			}
		}
		sort(teams.begin(), teams.end());

		//output
		REP(i, T) {
			cout << teams[i].id;
			if (i != T - 1) {
				if (teams[i].score() == teams[i + 1].score()) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		cout << endl;
	}
	//debug();
	
	return 0;
}