Under construction

Still being built. Things may change

Cutting with Lasers

Interview

Time limit1sMemory limit1024 MB

Summary
Given a closed path of axis-parallel laser cuts on a sheet, find the area of the largest enclosed piece that does not touch the sheet edge.
Level

Medium5 of 10

Topics
BFS, Matrix, Implementation
Solved
No attempts yet

Problem

A laser cutting machine for wood sheets has a laser head that can move in only two directions, horizontal and vertical. You have been hired to be part of the testing team for the machine.

One of the tests consists of programming the machine to perform a non-empty sequence of consecutive cuts that starts and ends at the same point. Each cut in the sequence, except the first, starts at the point where the previous cut ended. No cut touches the edge of the sheet. Figures (a) and (b) below show two examples of cutting sequences, with 8 and 14 cuts, respectively.

Your boss asked you to find the area of the largest piece produced by the sequence of cuts, leaving out the piece attached to the edges of the sheet. Only pieces contained in the polygon formed by the cut lines are counted. Figures (c) and (d) show the largest pieces produced by the cuts in figures (a) and (b).

For illustration, figures (e) and (f) show the discarded piece, which contains the edges of the wood sheet, for the cut sequences in figures (a) and (b).

Input

The first line contains an integer NN, the number of cuts (4≤N≤1044 \le N \le 10^4). The second line contains two integers X0X_0 and Y0Y_0, the initial position of the laser head (1≤X0≤1031 \le X_0 \le 10^3, 1≤Y0≤1031 \le Y_0 \le 10^3). Each of the next NN lines contains two integers XiX_i and YiY_i, the final position of cut ii (1≤Xi≤1031 \le X_i \le 10^3, 1≤Yi≤1031 \le Y_i \le 10^3, 1≤i≤N1 \le i \le N). It is given that (XN,YN)=(X0,Y0)(X_N, Y_N) = (X_0, Y_0). All positions in the input are distinct, except the first and the last positions.

Output

Print a single line containing one integer, the area of the largest piece produced by the sequence of cuts.

Examples2

  1. Example 1

    Input
    8
    2 1
    7 1
    7 4
    3 4
    3 2
    5 2
    5 6
    2 6
    2 1
    
    Expected output
    17
    
  2. Example 2

    Input
    14
    1 1
    8 1
    8 6
    6 6
    6 2
    2 2
    2 4
    7 4
    7 5
    3 5
    3 3
    4 3
    4 6
    1 6
    1 1
    
    Expected output
    21