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: ans_list = []

while True:
    m, t, p, r = map(int, input().split())
    if m == 0 and t == 0 and r == 0 and p == 0:
        break

    team = [[[0, 1] for i in range(p)] for j in range(t)]

    for i in range(r):
        M, T, P, J = map(int, input().split())
        if J:
            team[T - 1][P - 1][0] += 20
        else:
            team[T - 1][P - 1][0] += M
        team[T - 1][P - 1][1] = J
    #    print(1, M, T, P, J)

    team_point = []
    for i in range(t):
        point = [0, 0, i]
        for j in range(p):
            if team[i][j][1] == 0:
                point[0] += 1
                point[1] += team[i][j][0]
        point[1] *= -1
        team_point.append(point)

    team_point.sort()
    team_point = team_point[::-1]
    ans = []
    same_point = [str(team_point[0][2] + 1)]
    for i in range(1, len(team_point)):
        if team_point[i][0] == team_point[i - 1][0]:
            if team_point[i][1] == team_point[i - 1][1]:
                same_point = [same_point[0] + "=" + str(team_point[i][2] + 1)]
            else:
                ans.append(same_point)
                same_point = [str(team_point[i][2] + 1)]
        else:
            ans.append(same_point)
            same_point = [str(team_point[i][2] + 1)]

    ans.append(same_point)
    ans_list.append(ans)
  #  print(team_point)
#    print(ans)
 #   print(team_point)

#print(ans_list)
for I in range(len(ans_list)):
    i = ans_list[I]
    for j in range(len(i)):
        print(i[j][0], end = "")
        if j != len(i) - 1:
            print(",", end = "")
    print()

Python: import sys
input = sys.stdin.readline

def main():
    while True:
        M, T, P, R = map(int, input().split())
        if M == 0:
            break
        results = [[i,0,0] for i in range(T)]
        if R > 0:
            logs = [list(map(int, input().split())) for i in range(R)]
            logs = sorted(logs, key=lambda x:(x[1], x[2], x[0]))
            penalty = 0
            problem = logs[0][2]
            team = logs[0][1] - 1
            penalty = 0
            i = 0
            while i < len(logs):
                m, t, p, j = logs[i]
                t -= 1
                if team == t:
                    if problem == p:
                        if j != 0:
                            penalty += 1
                        else:
                            results[team][1] += 1
                            results[team][2] += m + penalty*20
                        i += 1
                    else:
                        penalty = 0
                        problem = p
                else:
                    team = t
                    penalty = 0
                    problem = p
        results = sorted(results, key=lambda x:(-x[1], x[2], -x[0]))
        print(results[0][0]+1, end="")
        for i in range(1, T):
            if results[i][1] == results[i-1][1] and results[i][2] == results[i-1][2]:
                print("=",end="")
            else:
                print(",",end="")
            print(results[i][0]+1,end="")
        print()




if __name__ == "__main__":
    main()

Python: # coding: utf-8
while 1:
    m,t,p,r=map(int,input().split())
    if m==0:
        break
    teamdata=[[0,0,i+1,set()] for i in range(t)]
    data=[]
    for i in range(r):
        a,b,c,d=map(int,input().split())
        if d==0:
            teamdata[b-1][0]+=1
            teamdata[b-1][1]+=a
            teamdata[b-1][3].add(c)
        data.append([a,b,c,d])
    for a,b,c,d in data:
        if d!=0 and (c in teamdata[b-1][3]):
            teamdata[b-1][1]+=20
    teamdata=sorted(teamdata, key=lambda x:(-x[0],x[1],-x[2]))
    for i in range(t):
        print(teamdata[i][2],end=('\n' if i==t-1 else ',' if teamdata[i][0]>teamdata[i+1][0] or teamdata[i][1]<teamdata[i+1][1] else '='))

Python: from collections import defaultdict


class Team:
    def __init__(self, num):
        self.num = num
        self.score = 0
        self.time = 0
        self.penalty = defaultdict(int)


while True:
    _, T, _, R = map(int, input().split())
    if T == 0:break
    teams = [Team(i + 1) for i in range(T)]
    for _ in range(R):
        m, t, p, j = map(int, input().split())
        if j != 0:
            teams[t - 1].penalty[p] += 20
        if j == 0:
            teams[t - 1].score += 1
            teams[t - 1].time += m + teams[t - 1].penalty[p]

    teams.sort(key=lambda team: (-team.score, team.time, -team.num))
    ans = str(teams[0].num)
    pre_score = teams[0].score
    pre_time = teams[0].time
    for i in range(1, T):
        team = teams[i]
        ans += "=" if team.score == pre_score and team.time == pre_time else ","
        ans += str(team.num)
        pre_score = team.score
        pre_time = team.time
    print(ans)