cho.sh
Notes
Loading...

Number Game

Time limit

2s

Memory limit

128 MB

Problem

N people play a number game. Each person receives 5 cards, and every card contains an integer from 1 to 10.

Each person chooses exactly 3 of their own cards, adds the numbers, and uses the units digit of that sum as their score. Each person chooses the 3 cards that make this score as large as possible.

The person with the highest score wins. If two or more people have the highest score, the person with the largest number among them wins. Given the cards for all N people, print the winner's number.

Input

The first line contains an integer N, the number of people. N is between 2 and 1,000, inclusive.

Each of the next N lines gives the 5 cards held by one person, from person 1 through person N. Each card is an integer from 1 to 10, and the integers on a line are separated by single spaces.

Output

Print the number of the person who wins the game on the first line. If there are multiple winners, print the largest number among them.