On the planet Midav, the end of the world is very near. As is known, this flat planet can be represented as an infinite plane with Cartesian coordinates. On this planet, there are Q settlements.
On day zero, an infection occurred on Midav. It is represented by a convex polygon with
N vertices. Each day, the area of the infection changes in an unknown manner, but for each day with number
i > 0, the following holds:
-
If any point is infected on the i-th day at a distance d from the original polygon, then all other points at a distance no greater than d from the original polygon are also infected;
-
Let Sk be the area of the infection on the k-th day. Then it holds that Si = 2 · Si−1.
If any settlement is located inside or on the boundary of the infection, all living organisms in it will immediately die. For each settlement on the planet Midav, there is very little time left, so answer which day (including day zero) will be the last for the settlement.
Input
The first line contains an integer N — the number of points in the infection polygon on day zero (3 ≤ N ≤ 105).
The next N lines contain two integers cxi and cyi — the coordinates of the vertices of the infection.
The following line contains an integer Q — the number of settlements on Midav (1 ≤ Q ≤ 105).
The next Q lines contain two integers txi and tyi — the coordinates of each settlement.
All coordinates in absolute value do not exceed 109. It is guaranteed that the given polygon is convex and that the vertices are given in counter-clockwise order. It is also guaranteed that the settlements are at least 10−6 away from the boundary of the infection on any day except day zero.
Output
Output Q integers — the last days for the settlements in the order of input.
Sample
input | output |
---|
4
1 3
1 1
3 1
3 3
4
2 2
1 2
4 1
6 2
| 0
0
2
4
|
Notes
In the example, the second settlement will be infected on day zero, as it lies on the boundary of the infection.
Problem Author: Vadim Barinov
Problem Source: Ural Regional Contest Qualifier 2023