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 <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct team_t {
  array<uint32_t, 11> times;
  array<bool, 11> corrects;
  uint32_t id;
  team_t() : times({}), corrects({}), id(0) {}

  uint32_t get_corrects() {
    uint32_t count = 0;
    for (uint32_t i = 0; i < corrects.size(); i++) {
      if (corrects[i]) {
        count++;
      }
    }
    return count++;
  }

  uint32_t get_penalty() {
    uint32_t penalty = 0;
    for (uint32_t i = 0; i < corrects.size(); i++) {
      if (corrects[i]) {
        penalty += times[i];
      }
    }
    return penalty;
  }

  bool operator==(team_t &team) {
    if (this->get_corrects() == team.get_corrects()) {
      return this->get_penalty() == team.get_penalty();
    }
    return false;
  }

  bool operator<(team_t &team) {
    if (this->get_corrects() == team.get_corrects()) {
      if (this->get_penalty() == team.get_penalty()) {
        return id > team.id;
      } else {
        return this->get_penalty() < team.get_penalty();
      }
    } else {
      return team.get_corrects() < this->get_corrects();
    }
  }

  void correct(uint32_t pid, uint32_t time) {
    corrects[pid] = true;
    times[pid] += time;
  }

  void println() {
    cout << id << " " << get_corrects() << " " << get_penalty() << endl;
  }

  void wrong(uint32_t pid) { times[pid] += 20; }
};

int32_t main() {
  while (true) {
    uint32_t M, T, P, R;
    cin >> M >> T >> P >> R;
    if (M == 0) break;

    vector<team_t> teams(T + 1);
    for (uint32_t i = 0; i < teams.size(); i++) {
      teams[i].id = i;
    }

    for (uint32_t i = 0; i < R; i++) {
      uint32_t m, t, p, j;
      cin >> m >> t >> p >> j;
      if (j == 0) {
        teams[t].correct(p, m);
      } else {
        teams[t].wrong(p);
      }
    }

    sort(teams.begin() + 1, teams.begin() + T + 1);

    for (uint32_t i = 1; i < T; i++) {
      cout << teams[i].id;
      if (teams[i] == teams[i + 1]) {
        cout << "=";
      } else {
        cout << ",";
      }
    }
    cout << teams[T].id;
    cout << endl;
  }

  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int time, team, pro, rec;
	while (cin >> time >> team >> pro >> rec, time) {
		vvi pena(team, vi(pro, 0));
		vector<pair<pii, int>> ac(team, pair<pii, int>({0,0},0));
		REP(i, team)
			ac[i].second = (i + 1);
		REP(i,rec) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			b--;
			c--;
			if (d == 0) {
				ac[b].first.first = ac[b].first.first + 1;
				ac[b].first.second= ac[b].first.second - a - pena[b][c];
			}
			else {
				pena[b][c] += 20;
			}
		}
		RSORT(ac);
		REP(i, team) {
			if (i != 0)
				if (ac[i - 1].first.first == ac[i].first.first&&
					ac[i - 1].first.second == ac[i].first.second)
					cout << "=";
				else
					cout << ",";
			cout << ac[i].second;
		}
		cout << endl;
	}
}

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

typedef pair<int,int>P;
typedef pair<P,int>PP;

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R,M){
		int d[55][15][2]={0};//チーム///問題///フラグ/時間
		vector<PP>V(T);
		for(int i=0;i<V.size();i++){
			V[i].first.first=0;
			V[i].first.second=0;
			V[i].second=i+1;
		}
		for(;R--;){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			if(j==0 && d[t][p][0]==0){
				d[t][p][1]+=m;
				d[t][p][0]=1;
				V[t-1].first.first++;//解いた数
				V[t-1].first.second-=d[t][p][1];//合計時間
			}
			if(j!=0 && d[t][p][0]==0){
				d[t][p][1]+=20;
			}
		}
		sort(V.begin(),V.end());
		for(int i=V.size()-1;i>=0;i--){
			cout<<V[i].second;
			if(i==0)cout<<endl;
			else if(V[i].first==V[i-1].first)cout<<"=";
			else cout<<",";
		}
	}
	
	
	return 0;
}