cho.sh
Notes
Loading...

Four Dice

Time limit

1s

Memory limit

128 MB

Problem

Each participant rolls four dice whose faces are numbered from 1 through 6. The prize for one participant is determined by the combination of the four rolled faces.

  1. If all four faces are the same, the prize is 50000 + face * 5000.
  2. If exactly three faces are the same, the prize is 10000 + face * 1000.
  3. If there are two different pairs, the prize is 2000 + (sum of the paired faces) * 500.
  4. If there is exactly one pair, the prize is 1000 + paired face * 100.
  5. If all four faces are different, the prize is largest face * 100.

Given the results for N participants, print the largest prize.

Input

The first line contains the number of participants N. (1 <= N <= 1000)

Each of the next N lines contains four integers separated by spaces, representing the faces rolled by one participant. Each face is an integer from 1 to 6.

Output

Print the largest prize among all participants.