Final Standings

Time limit: 0.05s
Memory limit: 64MB
Input:
Output:

Task

After you helped kids form teams for IKPC (International Kindergarten Programming Contest), you now want to know which team won the competition!

Your teacher provided you information regarding the number of teams, NN, the number of problems, PP, as well as the number of actions taken by the teams, QQ.

For the ithi^{th} action, you know the number of the team, tit_i, the problem number they submitted on, pip_i, as well as the verdict of the solution, 11 if the solution was accepted or 00 if the solution was rejected. If team tit_i did not submit a correct solution before the ithi^{th} action to that problem pip_i, the penalty of the team corresponding to problem pip_i is increased by ii. If a team submits multiple solutions to a problem, the total penalty is increased by the sum of the penalties accumulated by the time the first correct solution was submitted, including the first correct solution. However, if a team never submits any correct solution to a problem pp, the penalties accumulated for pp are NOT added towards the final penalty.

For example, if a team submits the following solutions on problem 11, they will get the total penalty increased by 2424, as only the submissions sent at times 55, 99 and 1010 are considered. Take note that the wrong solution at time 1515 is not added to the total penalty.

  • a wrong solution at time 55
  • a wrong solution at time 99
  • a correct solution at time 1010
  • a wrong solution at time 1515

In order to simplify the competition, each action takes place at a different moment of time, thus the ithi^{th} action will take place in the ithi^{th} minute. The moments of time are indexed from 11.

The final standings of the competition are decided as follows:

  • First, the teams are ordered in non-ascending order of the number of problems they solved. Warning, if the team submits more than a correct solution for the same problem, only the first correct solution is counted.
  • If two or more teams are tied, they will be ordered in non-descending order of their penalties. Warning, in order to compute the penalty, we will consider the penalty accumulate only among the problems which weresolved, without considering the solutions sent after the problem was solved, irrespective of the status of the solution.
  • If they are still tied, they will be ordered in the non-ascending order of the number of first solves they obtained. A first solve consists of a team being the first one to solve a certain problem.
  • If they are still tied, they will be ordered in increasing order of their team numbers (if two teams have the exact same stats, the team with a smaller label goes first).

For example, if a team solved 1010 problems and has a penalty of 190190, it will be ahead of any team who solved 99 problems or less, as well as ahead any team who solved 1010 problems but with a penalty greater than 190190 or if they have the same penalty too, they will be ahead if they have more first solves than the other team or the same number of first solves too but a smaller label.

Input data

The first line of the input will contain the numbers NN, PP and QQ, as stated above.

The next QQ lines will each contain three values, tit_i, pip_i and viv_i, where tit_i (1tiN1 \leq t_i \leq N) is the number of the team which had this action, pip_i (1piP1 \leq p_i \leq P) is the problem number they submitted on, viv_i is the verdict they got (00 for rejected and 11 for accepted).

Output data

The output will contain a single line, with the order of the teams, from the first placed team to the last placed team, according to the restrictions specified in the statement.

Constraints and clarifications

  • 1N,P1001 \leq N , P \leq 100
  • 1Q1041 \leq Q \leq 10^{4}
# Points Restrictions
1 30 1M,P501 \leq M,P \leq 50
2 70 No additional constraints.

Example

stdin

7 11 17
5 3 0
4 11 1
2 5 1
3 9 1
2 11 1
7 7 0
6 1 1
4 2 1
6 11 1
4 9 1
5 5 0
1 4 1
2 2 1
2 6 0
6 10 1
3 8 1
3 5 1

stdout

4 2 6 3 1 5 7

Explanation

In the table below you can see the list of solved problems, penalty and first solves for each team.

Team Solved problems Penalty First solve count
4 3 20 2
2 3 21 1
6 3 31 2
3 3 37 2
1 1 12 1
5 0 0 0
7 0 0 0

Log in or sign up to be able to send submissions!