Under construction

Still being built. Things may change

Prison for Zedd

Time limit2sMemory limit1024 MB

Summary
Pick six of the given rectangles to form the three face pairs of a box and report the largest possible volume, or -1 if no box can be built.
Level

Medium7 of 10

Topics
Graph, Sorting, Hash map
Solved
No attempts yet

Statement

The Black Ranger found nn rectangular metal sheets of different sizes in the crater of an abandoned volcano. Sheet ii measures aia_i meters by bib_i meters.

Zordon asked the Black Ranger to build a prison for the evil general Zedd, and these sheets are a lucky find. The prison must be a rectangular box where each face is one whole sheet. The Ranger will take 6 of the sheets, assemble the box, and show it to Zordon. Sheets cannot be bent or cut, and no sheet used in the prison may stick out past the edges of the box.

A bigger prison is a safer prison, so the box must have the largest possible volume. Find the maximum volume of a box that can be assembled from these sheets.

Sheets may be rotated. For example, a 4 by 7 sheet and a 7 by 4 sheet are considered the same.

Input

The first line contains one integer nn, the number of metal sheets (6≤n≤2000006 \le n \le 200000).

Each of the next nn lines contains two integers aia_i and bib_i, the dimensions of the ii-th sheet (1≤ai,bi≤1061 \le a_i, b_i \le 10^6).

Output

Print one integer, the maximum volume of a rectangular box that can be assembled from these sheets.

If no box can be assembled, print −1-1.

Examples3

  1. Example 1

    Input
    6
    3 6
    6 9
    9 3
    6 3
    3 9
    9 6
    
    Expected output
    162
    
  2. Example 2

    Input
    6
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    
    Expected output
    1
    
  3. Example 3

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