Deleting

아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

You are given an array \[1,2,,n]\[1, 2, \ldots, n], where the number of elements nn is even. 

In one operation, you can delete two adjacent elements of the array. If these elements are ii and jj, the cost of this operation is cost(i,j)\mathit{cost}(i, j).

In n2\frac{n}{2} operations, all elements will be deleted. The cost of deleting the whole array is defined as the largest cost among all the n2\frac{n}{2} operations.

What is the smallest possible cost of deleting the whole array?

입력

The first line of the input contains a single integer nn (2n40002 \le n \le 4000, nn is even).

We are kind today. So we won't provide unnecessary input. It can be shown that it's impossible for two numbers of the same parity to be adjacent at any point, so we won't provide costs for those pairs.

The ii-th of the next n1n - 1 lines contains ni+12\lfloor \frac{n-i+1}{2} \rfloor integers. If ii is even, these integers are cost(i,i+1),cost(i,i+3),,cost(i,n1)\mathit{cost}(i, i+1), \mathit{cost}(i, i+3), \ldots, \mathit{cost}(i, n-1). Otherwise, they are cost(i,i+1),cost(i,i+3),,cost(i,n)\mathit{cost}(i, i+1), \mathit{cost}(i, i+3), \ldots, \mathit{cost}(i, n).

It is guaranteed that the costs form a permutation of numbers from 11 to (n2)2(\frac{n}{2} )^2.

출력

Output a single integer: the smallest possible cost of deleting the whole array.

힌트

In the first example, the array is \[1,2]\[1, 2], and cost(1,2)=1\mathit{cost}(1, 2) = 1. So, the only way to delete the array has the total cost of 11.

In the second example, one of the ways to delete the array is:

  • \[1,2,3,4,5,6]\[1,2,5,6]\[1, 2, 3, 4, 5, 6] \to \[1, 2, 5, 6], deleting pair (3,4)(3, 4) with cost 66.
  • \[1,2,5,6]\[1,6]\[1, 2, 5, 6] \to \[1, 6], deleting pair (2,5)(2, 5) with cost 55.
  • And then deleting pair (1,6)(1, 6) with cost 33.

The total cost is therefore max(6,5,3)=6\max (6, 5, 3) = 6.