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)
}

Python: import sys
while(True):
    M,T,P,R=map(int,input().split())
    if (M,T,P,R)==(0,0,0,0):
        break
    points=[0 for i in range(T)]
    time=[0 for i in range(T)]
    penalty=[[0 for i in range(T)] for i in range(P)]
    for i in range(R):
        m,t,p,j=map(int,input().split())
        #正解したものをもう一度出すかどうかは考慮しない
        if j!=0:
            penalty[p-1][t-1]+=1
            continue
        points[t-1]+=1
        time[t-1]+=m+penalty[p-1][t-1]*20
    teams=[(points[i],time[i],i+1) for i in range(T)]
    teams.sort(key=lambda x:(-x[0],x[1],-x[2]))
    st=str(teams[0][2])
    for i in range(1,T):
        if (teams[i-1][0],teams[i-1][1])==(teams[i][0],teams[i][1]):
            st=st+"="
        else:
            st=st+","
        st=st+str(teams[i][2])
    print(st)

Python: import sys

def main():
    while True:
        M,T,P,R = map(int,input().split())
        if not M and not T and not P and not R:
            return
        prob = [[0]*(P+1) for _ in range(T+1)]
        result = dict([(t,[0,sys.maxsize]) for t in range(1,T+1)]) # (t,m,p)
        for _ in range(R):
            m,t,p,j = map(int,input().split())
            if j == 0:
                result[t][0] += prob[t][p] + m
                result[t][1] += 1
            else:
                prob[t][p] += 20
        result = list(result.items())
        result = sorted(result, key=lambda x: (-1*x[1][1], x[1][0], -1*x[0]))

        print(result[0][0], end="")
        for i in range(1,T):
            if result[i][1][0] == result[i-1][1][0] and result[i][1][1] == result[i-1][1][1]:
                print("={}".format(result[i][0]), end="")
            else:
                print(",{}".format(result[i][0]), end="")
        print()

if __name__ == '__main__':
    main()

Python: from functools import cmp_to_key

def f(a, b):
    if a[0] == b[0]:
        ap = a[1] + a[2] * 20
        bp = b[1] + b[2] * 20
        if ap == bp:
            return a[3] > b[3]
        return ap < bp
    return a[0] > b[0]


while True:
    M, T, P, R = map(int, input().split())
    if not M:
        break
    fail = [[0 for i in range(P)] for j in range(T)]
    # [-solved, time, -team]
    res = [[0, 0, -i] for i in range(T)]
    
    for r in range(R):
        m, t, p, j = map(int, input().split())
        t -= 1
        p -= 1
        if j:
            fail[t][p] += 1
        else:
            res[t][0] -= 1
            res[t][1] += fail[t][p] * 20 + m
    res = sorted(res)
    for i, r in enumerate(res[:-1]):
        if r[0] == res[i + 1][0] and r[1] == res[i + 1][1]:
            print(-r[2] + 1, end='=')
        else:
            print(-r[2] + 1, end=',')
    print(-res[-1][2] + 1)

Python: "ICPCの順位づけ"
while True:
    M, T, P, R = map(int, input().split())
    if M == 0:
        break
    submits = []  # ログを管理する配列
    for i in range(R):
        submits.append(list(map(int, input().split())))

    team_scores = {}
    for i in range(1, T+1):
        team_scores[i] = [0, 0]  # 正解数, 時間の合計

    for i in range(R):
        if submits[i][3] == 0:
            add_time = 0
            for j in range(0, i):
                if submits[j][1] == submits[i][1] and submits[j][2] == submits[i][2]:
                    add_time += 20
            team_scores[submits[i][1]][0] += 1
            team_scores[submits[i][1]][1] += (submits[i][0] + add_time)

    team_scores = sorted(team_scores.items(), key=lambda x: (x[1][0], -x[1][1], x[0]), reverse=True)

    ans = ''
    for i in range(len(team_scores)):
        if i == 0:
            ans += str(team_scores[i][0])
        else:
            if team_scores[i][1] == team_scores[i-1][1]:
                ans += '='+str(team_scores[i][0])
            else:
                ans += ','+str(team_scores[i][0])

    print(ans)

Python: from collections import defaultdict

while True:
  time = [ [0 for _ in range(16)] for __ in range(64) ]
  accepted = [ [0 for _ in range(16)] for __ in range(64) ]

  M,T,P,R = map(int, input().split())
  if M==0 and T==0: break

  for i in range(R):
    m,t,p,j = map(int, input().split())
    if j==0:
      accepted[t][p] = 1
      time[t][p] = time[t][p] + m
    else:
      time[t][p] += 20

  score = defaultdict(int)
  for t in range(1,T+1):
    for p in range(1,P+1):
      score[t] +=  accepted[t][p] * 1<<16
      if accepted[t][p]:
        score[t] -= time[t][p]

  mp = defaultdict(list)
  prev = -1
  for k,v in score.items():
    mp[v].append(k)

  output = ""
  for sc,ts in sorted(mp.items(), key=lambda x: x[0], reverse=True):
    output += '='.join(map(str, sorted(ts, reverse=True)))
    output += ','
  else:
    print(output[:-1])