#C6511. Voting Process Simulation

    ID: 50280 Type: Default 1000ms 256MiB

Voting Process Simulation

Voting Process Simulation

In this problem, you are given a series of voting records representing votes cast by voters for candidates. In order to avoid ties in the elections, the country has introduced a rule: if a voter changes their vote, all previous votes from that voter for a candidate are nullified and only the latest vote is valid.

For every voting record given as input, your task is to determine the final count of valid votes for each candidate. The valid vote for a candidate is counted only from the latest vote of each voter that chose that candidate.

The final output should list each candidate along with their valid vote count, sorted by candidate ID in ascending order.

Note: All formulas in this problem adhere to LaTeX formatting. For instance, the subtraction operation is represented as aba - b.

inputFormat

Input is given via standard input (stdin). Each line of input contains two integers separated by a space, where the first integer represents a voter ID and the second integer represents a candidate ID. The input terminates at the end of file.

outputFormat

Output the result to standard output (stdout). For each candidate that received votes, print a line containing the candidate ID and the number of valid votes they received, separated by a space. The candidates must be listed in ascending order based on their candidate ID.## sample

1 2
2 3
1 4
3 3
2 3
2 0

3 2 4 1

</p>