atcoder#ZONE2021C. MAD TEAM

MAD TEAM

Score : 400400 points

Problem Statement

You want to choose three persons from NN candidates to form a team. Each candidate has five parameters: power, speed, technique, knowledge, and inventiveness. The power, speed, technique, knowledge, and the inventiveness of the ii-th candidate are AiA_i, BiB_i, CiC_i, DiD_i, and EiE_i, respectively. Let us define your team's power as the maximum of the members' powers. The team's speed, technique, knowledge, and inventiveness are defined similarly. Then, let us define your team's total strength as the minimum of the team's power, speed, technique, knowledge, and inventiveness. Find the maximum possible value of your team's total strength.

Constraints

  • All values in input are integers.
  • 3N30003 \leq N \leq 3000
  • 1Ai,Bi,Ci,Di,Ei1091 \leq A_i, B_i, C_i, D_i, E_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1 C1C_1 D1D_1 E1E_1

A2A_2 B2B_2 C2C_2 D2D_2 E2E_2

\vdots

ANA_N BNB_N CNC_N DND_N ENE_N

Output

Print the answer.

3
3 9 6 4 6
6 9 3 1 1
8 8 9 3 7
4

We have no choice but to choose all three of them. Then, the team's parameters will be as follows:

  • power: max(3,6,8)=8\max(3, 6, 8) = 8;
  • speed: max(9,9,8)=9\max(9, 9, 8) = 9;
  • technique: max(6,3,9)=9\max(6, 3, 9) = 9;
  • knowledge: max(4,1,3)=4\max(4, 1, 3) = 4;
  • inventiveness: max(6,1,7)=7\max(6, 1, 7) = 7.

Thus, the team's total strength will be min(8,9,9,4,7)=4\min(8, 9, 9, 4, 7) = 4.

5
6 13 6 19 11
4 4 12 11 18
20 7 19 2 5
15 5 12 20 7
8 7 6 18 5
13

If we choose the 11-st, 22-nd, and 33-rd candidates, the team's total strength will be min(20,13,19,19,18)=13\min(20, 13, 19, 19, 18) = 13.

10
6 7 5 18 2
3 8 1 6 3
7 2 8 7 7
6 3 3 4 7
12 8 9 15 9
9 8 6 1 10
12 9 7 8 2
10 3 17 4 10
3 1 3 19 3
3 14 7 13 1
10