<?xml version="1.0" encoding="Windows-1251"?>
<CATS version="1.0">
<Problem title="ACM Rank Table" lang="en" author="A. Klenin" tlimit="2" mlimit="16"
    inputFile="input.txt" outputFile="output.txt" stdChecker="nums">

<ProblemStatement>
<p>ACM contests, like the one you are participating in, are hosted by the special software.
That software, among other functions, preforms a job of accepting and evaluating teams' solutions (runs),
and displaying results in a rank table.
The scoring rules are as follows:
<ol>
<li>Each run is either accepted or rejected.</li>
<li>The problem is considered solved by the team, if one of the runs submitted for it is accepted.</li>
<li>The time consumed for a solved problem is the time elapsed
  from the beginning of the contest to the submission of the first accepted run for this problem (in minutes)
  plus 20 minutes for every other run for this problem before the accepted one.
  For an unsolved problem consumed time is not computed.</li>
<li>The total time is the sum of the time consumed for each problem solved.</li>
<li>Teams are ranked according to the number of solved problems.
  Teams that solve the same number of problems are ranked by the least total time.</li>
<li>While the time shown is in minutes, the actual time is measured to the precision of 1 second, and
  the the seconds are taken into account when ranking teams.</li>
<li>Teams with equal rank according to the above rules must be sorted by increasing team number.</li>
</ol>
</p>
<p>Your task is, given the list of <i>N</i> runs with submission time and result of each run,
compute the rank table for <i>C</i> teams.
</p>
</ProblemStatement>

<InputFormat>
Input contains integer numbers <i>C</i> <i>N</i>, followed by <i>N</i> quartets of integes 
<i>c<sub>i</sub></i> <i>p<sub>i</sub></i> <i>t<sub>i</sub></i> <i>r<sub>i</sub></i>, where
 <i>c<sub>i</sub></i> -- team number,
 <i>p<sub>i</sub></i> -- problem number,
 <i>t<sub>i</sub></i> -- submission time <i>in seconds</i>, 
 <i>r<sub>i</sub></i> -- 1, if the run was accepted, 0 otherwise.
</InputFormat>

<OutputFormat>
Output file must contain <i>C</i> integers -- team numbers sorted by rank.
</OutputFormat>

<ProblemConstraints>
1 &amp;le; <i>C, N</i> &amp;le; 1000,
1 &amp;le; <i>c<sub>i</sub></i> &amp;le; <i>C</i>,
1 &amp;le; <i>p<sub>i</sub></i> &amp;le; 20,
1 &amp;le; <i>t<sub>i</sub></i> &amp;le; 36000.
</ProblemConstraints>

<Sample rank="1">
  <SampleIn>2 3
1 1 5000 0
1 1 500 1
2 1 10000 1
</SampleIn>
  <SampleOut>1 2</SampleOut>
</Sample>

<Sample rank="2">
  <SampleIn>3 3
1 2 3000 0
1 2 3100 1
2 1 4200 1
</SampleIn>
  <SampleOut>2 1 3</SampleOut>
</Sample>

<Solution name="sol" src="rank.dpr"/>
<Solution name="sol_newr" src="a.dpr"/>
<TestRange from="1" to="11"><In src="t%0n"/><Out use="sol"/></TestRange>
<Generator name="g" src="g1.dpr"/>
<Test rank="12"><In use="g" param="a 30 100"/><Out use="sol"/></Test>
<Test rank="13"><In use="g" param="b 1000 1000"/><Out use="sol"/></Test>
<Test rank="14"><In use="g" param="c 1000 1000"/><Out use="sol"/></Test>
<Test rank="15"><In use="g" param="d 1000 1000"/><Out use="sol"/></Test>

</Problem>
</CATS>