Under construction

Still being built. Things may change

Lapin Noir

Time limit1sMemory limit512 MB

Summary
For each starting cell on a hex grid, decide whether a cat can always reach (0, 0) while a rabbit blocks cells, except inside the cat's hexagonal territory.
Level

Hard9 of 10

Topics
Game theory, Geometry, Implementation
Solved
No attempts yet

Problem

This city has a ground paved with regular hexagonal cells. Each cell is represented by two integers, as shown in the figure below.

A cat wants to reach the cell (0,0)(0, 0). A mischievous black rabbit learns of this and plans to interfere with the cat.

The black rabbit jumps to the cell where the cat is standing and can block one of the six surrounding cells or two adjacent ones. The cat picks one of the six surrounding cells that is not blocked and moves there. After each move by the cat, the black rabbit chases the cat and can block again. When the rabbit moves, its previous blocks are removed. The figure below shows a blocked position.

The city has several cells that form the cat's territory. A territory is the union of nn sets, where each set is the collection of cells along the perimeter of a regular hexagon. The black rabbit can enter the cat's territory but cannot block cells there. In other words, the cat can move freely inside its territory.

There are kk candidate starting cells, and the ii-th one is (xi,yi)(x_i, y_i) (1≤i≤k1 \le i \le k). For each candidate, determine whether the cat can always reach the destination (0,0)(0, 0), or whether the black rabbit can interfere well enough to prevent the cat from reaching it.

Input

The first line contains nn (1≤n≤40 0001 \le n \le 40\,000). Lines 2 through n+1n+1 each give the six vertices of a regular hexagon that forms part of the cat's territory, listed counterclockwise.

The next line contains kk (1≤k≤40 0001 \le k \le 40\,000). The following kk lines each contain the starting cell xi,yix_i, y_i.

  • −1 000 000 000≤-1\,000\,000\,000 \le (each coordinate) ≤1 000 000 000\le 1\,000\,000\,000

Output

For each candidate starting cell, print one line per candidate. Print "YES" if the cat can always reach (0,0)(0, 0). Print "NO" if the black rabbit can block the cat so that it cannot reach (0,0)(0, 0).

Hint

Examples1

  1. Example 1

    Input
    2
    1 -1 3 -1 3 1 1 3 -1 3 -1 1
    3 0 4 0 4 1 3 2 2 2 2 1
    3
    1 1
    -1 -1
    2 4
    
    Expected output
    YES
    NO
    YES