Under construction

Still being built. Things may change

Soccer Tournament

Interview

Time limit1sMemory limit1024 MB

Summary
Select 11 players, exactly one goalkeeper and at least one each of striker, midfielder, and defender, to maximize the sum of their assigned preference scores.
Level

Medium5 of 10

Topics
Dynamic programming, Greedy
Solved
No attempts yet

Problem

Seollal is here, and Dohun's army unit is holding a soccer tournament. As the team's coach, Dohun must select 1111 players to join the team.

Each selected player must be registered at one of four positions: striker, midfielder, defender, or goalkeeper. Each position must have at least one player. However, exactly one goalkeeper must be selected.

Each applicant submitted preference scores aia_i, bib_i, cic_i, and did_i for the striker, midfielder, defender, and goalkeeper positions. The team's satisfaction is the sum of the preference scores for the positions each player is assigned to. Using this information, Dohun wants to select players that satisfy the team rules and maximize the team's satisfaction. Find the maximum team satisfaction when exactly 1111 players are selected.

Input

The first line contains the number of soldiers NN.

The next NN lines are given such that line i+1i+1 contains the striker, midfielder, defender, and goalkeeper preference scores aia_i, bib_i, cic_i, and did_i of soldier ii, separated by spaces.

Output

Print the maximum team satisfaction when players are selected according to the team rules.

Constraints

  • 11≤N≤200 00011 \le N \le 200\,000
  • 1≤ai≤1081 \le a_i \le 10^8
  • 1≤bi≤1081 \le b_i \le 10^8
  • 1≤ci≤1081 \le c_i \le 10^8
  • 1≤di≤1081 \le d_i \le 10^8
  • All input values are integers.

Examples1

  1. Example 1

    Input
    11
    1 1 1 1
    2 2 2 2
    5 5 5 5
    3 3 3 3
    5 5 5 5
    2 2 2 2
    8 8 8 8
    7 7 7 7
    5 5 5 5
    4 4 4 4
    1 1 1 1
    
    Expected output
    43