Under construction

Still being built. Things may change

N-Queen (Area)

Time limit1sMemory limit1024 MB

Summary
Place N non-attacking queens on an N by N grid warped inside a convex quadrilateral to maximize the total area of the occupied cells.
Level

Hard8 of 10

Topics
Backtracking, Geometry, Bit manipulation
Solved
No attempts yet

Problem

The N-Queen problem asks you to place NN queens on an N×NN \times N chess board so that no two queens attack each other. A queen can attack other pieces on the same row, column, or diagonal.

In this problem, the chess board is distorted. The board is a convex quadrilateral ABCD, as shown in the figure. Each of the four sides is divided into NN equal parts. Division points on segments AB and CD, and on AD and BC, are connected to the points that face them. This forms N2N^2 square cells.

Among all placements of NN queens where no two queens attack each other, find the placement that maximizes the total area of the cells occupied by queens. Output that maximum total area.

Input

The first line contains NN.

The second line contains the coordinates of the four vertices xA,yA,xB,yB,xC,yC,xD,yDx_A, y_A, x_B, y_B, x_C, y_C, x_D, y_D, separated by spaces. The vertices are given in clockwise or counterclockwise order.

Output

Print the maximum total area of the cells occupied by queens. Answers with an absolute or relative error of up to 10−910^{-9} are accepted.

Constraints

  • 4≤N≤1004 \le N \le 100. It is guaranteed that a placement of NN queens exists in this range.
  • −1000≤xA,yA,xB,yB,xC,yC,xD,yD≤1000-1000 \le x_A, y_A, x_B, y_B, x_C, y_C, x_D, y_D \le 1000
  • All input values are integers.

Examples1

  1. Example 1

    Input
    4
    6 2 8 2 7 0 6 0
    
    Expected output
    0.75