Four Dice

Interview

Time limit1sMemory limit128 MB

Summary
Given N sets of four dice rolls, compute each participant's prize by rules based on matching-face patterns and output the maximum prize.
Level

Easy3 of 10

Topics
Implementation, Hash map, Simulation
Solved
No attempts yet

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.

Examples1

  1. Example 1

    Input
    4
    3 3 3 3
    3 3 6 3
    2 2 6 6
    6 2 1 5
    
    Expected output
    65000