#K68912. Voting System

    ID: 32970 Type: Default 1000ms 256MiB

Voting System

Voting System

You are given a voting system where each vote is identified by a voter ID and a candidate ID. Each voter may vote multiple times; however, only the last vote for each voter is counted. Your task is to compute the total votes for each candidate and then declare the winner. In the output, first print the total votes for each candidate in the order in which the candidate first appeared in the entire input (even if a candidate lost some votes due to vote updates). Then, on a new line, print the candidate with the highest vote count along with their vote count. In case of ties, the candidate who appeared earliest in the input should be declared the winner.

Note: If no votes are cast (i.e. the number of votes is 0), simply output "No votes".

Mathematical Formulation:
Let \(n\) be the number of vote submissions. For each vote submission \(i\) (\(0 \le i < n\)) with voter id \(v_i\) and candidate id \(c_i\), maintain the mapping \(V(v_i) = c_i\) (overwriting previous votes). Then let the total votes for a candidate \(x\) be given by:
\[ T(x) = \sum_{v \;:\; V(v)=x} 1 \] The winner is defined as the candidate \(w\) such that
\[ w = \arg\max_{x} T(x) \]
If multiple candidates tie for \(\max T(x)\), choose the one that appeared first in the input.

inputFormat

The first line contains a single integer \(n\) indicating the number of vote submissions. Each of the next \(n\) lines contains a voter ID (an integer) and a candidate ID (a string), separated by a space.

Example:
6
1 A
2 B
1 C
3 A
4 A
2 A

outputFormat

If \(n = 0\), output "No votes".

Otherwise, the output consists of two lines:

  • The first line displays the total votes for each candidate (who received at least one valid vote) in the order of their first appearance in the input. Each candidate and its vote count are printed separated by a space.
  • The second line contains the winning candidate and its vote count, separated by a space. In case of a tie, the candidate who appeared earliest in the input is considered the winner.

Example Output:
A 3 C 1
A 3

## sample
6
1 A
2 B
1 C
3 A
4 A
2 A
A 3 C 1

A 3

</p>