Shopping center#7255

Shopping center

0.2 seconds
256 megabytes
Easy

In the country of Olympia, a decision has been made to construct a large shopping center. For this project, a square plot measuring N \times N meters has been designated. There are specific height restrictions for the building. If the plot is divided into vertical and horizontal strips, each 1 meter wide, then each strip has its own height limit. The architects plan to design the shopping center as a rectangular parallelepiped.

Task

Your task is to write a program that, given the size of the plot and the height restrictions for each strip, determines the maximum volume of the building, shaped as a rectangular parallelepiped, that can be constructed on this plot.

Input

The input consists of three lines. The first line contains a natural number (2 \leq N \leq 5 \times 10^4) — the size of the plot. The second line contains non-negative integers, each not exceeding 10^5, representing the height restrictions for the vertical strips. The third line also contains non-negative integers, each not exceeding 10^5, representing the height restrictions for the horizontal strips.

Output

The output should be a single number — the maximum volume of the shopping center building that can be constructed on the specified plot. The input data guarantees that it is possible to construct a building with a non-zero volume on the plot.

Examples

Example 1

Loading
Loading

Scoring

The test set is divided into 5 blocks, with the following conditions:

  1. 10 points: 1 \leq N \leq 10

  2. 10 points: 10 < N \leq 30

  3. 10 points: 30 < N \leq 70

  4. 30 points: 70 < N \leq 1000

  5. 40 points: 1000 < N \leq 5 \times 10^4