Under construction

Still being built. Things may change

ICPC Ranking

Time limit1sMemory limit128 MB

Summary
Simulate the ICPC log to score each team by solved problems and penalty time, then print the ordered ranking with ties marked.
Level

Easy3 of 10

Topics
Simulation, Sorting, Implementation
Solved
No attempts yet

Problem

Read the submission log of an ICPC (International Collegiate Programming Contest) and determine the team rankings.

The log is a list of submission records in the order they were submitted. Each record has four fields: elapsed time, team number, problem number, and judgment. The elapsed time is the time from the start of the contest to that submission. The judgment tells whether the submitted program was correct or incorrect, and when it was incorrect, which kind of error was found.

The rankings follow the rules below. This rule set is the one used in the real ICPC World Finals and Regionals, with a few detail rules dropped for simplicity.

  1. A team that solved more problems ranks higher.
  2. Among teams that solved the same number of problems, the one with the smaller total consumed time ranks higher.
  3. If two or more teams solved the same number of problems and their total consumed times are equal, they get the same rank.

The total consumed time is the sum of the consumed time of every solved problem. The consumed time of a solved problem is the elapsed time of the accepted submission plus 20 penalty minutes for each earlier rejected submission on that problem.

The consumed time of an unsolved problem is zero, so any number of incorrect submissions on it costs nothing.

You can assume that a team never submits a program for a problem after a correct submission for the same problem.

Input

The input is a sequence of datasets, each in the format below. A line with four zeros follows the last dataset.

M T P R
m1 t1 p1 j1
m2 t2 p2 j2
.....
mR tR pR jR

The first line of a dataset contains four integers MM, TT, PP, and RR. MM is the duration of the contest, TT is the number of teams, PP is the number of problems, and RR is the number of submission records. These values satisfy 120≤M≤300120 \le M \le 300, 1≤T≤501 \le T \le 50, 1≤P≤101 \le P \le 10, and 0≤R≤20000 \le R \le 2000. Team numbers run from 1 to TT, and problem numbers run from 1 to PP.

Each of the next RR lines holds one submission record as four integers mkm_k, tkt_k, pkp_k, and jkj_k (1≤k≤R1 \le k \le R). mkm_k is the elapsed time, tkt_k is the team number, pkp_k is the problem number, and jkj_k is the judgment, where 0 means correct and any other value means incorrect. These values satisfy 0≤mk≤M−10 \le m_k \le M-1, 1≤tk≤T1 \le t_k \le T, 1≤pk≤P1 \le p_k \le P, and 0≤jk≤100 \le j_k \le 10.

Elapsed times are rounded to the nearest minute.

Submission records come in submission order, so if i<ji < j then the ii-th submission happened before the jj-th one and mi≤mjm_i \le m_j. In some cases that fact would separate two teams whose times differ by less than a minute, but the ranking never uses it. Teams are ranked on time in minutes only.

Output

For each dataset, print the team numbers (1 to TT) on one line, highest ranked team first. The separator between two team numbers is a comma. The separator between two teams that share a rank is an equal sign. Teams that share a rank are listed in decreasing order of team number.

Examples1

  1. Example 1

    Input
    300 10 8 5
    50 5 2 1
    70 5 2 0
    75 1 1 0
    100 3 1 0
    150 3 2 0
    240 5 5 7
    50 1 1 0
    60 2 2 0
    70 2 3 0
    90 1 3 0
    120 3 5 0
    140 4 1 0
    150 2 4 1
    180 3 5 4
    15 2 2 1
    20 2 2 1
    25 2 2 0
    60 1 1 0
    120 5 5 4
    15 5 4 1
    20 5 4 0
    40 1 1 0
    40 2 2 0
    120 2 3 4
    30 1 1 0
    40 2 1 0
    50 2 2 0
    60 1 2 0
    120 3 3 2
    0 1 1 0
    1 2 2 0
    300 5 8 0
    0 0 0 0
    
    Expected output
    3,1,5,10=9=8=7=6=4=2
    2,1,3,4,5
    1,2,3
    5=2=1,4=3
    2=1
    1,2,3
    5=4=3=2=1