cho.sh
Notes
Loading...

I Am the Class President

Time limit

1s

Memory limit

128 MB

Problem

An elementary school class with N students is holding an election for class president. Three students are running as candidates, numbered candidate 1, candidate 2, and candidate 3.

Each student must give 3 points to the candidate they prefer the most, 2 points to their second choice, and 1 point to the candidate they prefer the least. For every student, the three scores for the candidates are all different, and the scores 1, 2, and 3 each appear exactly once.

A candidate's final score is the sum of all preference scores received from the students. The candidate with the largest final score becomes president. If several candidates share the largest score, the candidate who received more 3-point scores becomes president. If those counts are also equal, the candidate who received more 2-point scores becomes president. If the counts of both 3-point and 2-point scores are equal, the president cannot be decided.

Given the preference votes, compute the scores for the three candidates. If a unique president can be decided, output that candidate's number and the highest score. Otherwise, output 0 and the highest score.

Input

The first line contains the number of students N (3 <= N <= 1,000).

Each of the next N lines contains the preference scores for the three candidates submitted by one student. The first score is for candidate 1, the second for candidate 2, and the third for candidate 3. In each line, the three scores are different, and 1, 2, and 3 each appear exactly once.

Output

If the vote results determine a unique president, output the elected candidate's number and the highest score. If a unique president cannot be determined, output 0 and the highest score.