COCI '19 Contest 2 #5 Zvijezda

View as PDF

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

Mirko and Slavko are spending their free time playing with polygons and watching a new season of The Biggest Loser. Mirko recently drew a convex polygon with an even number of vertices . Slavko then considered each pair of oposite sides (two sides are opposite if there are sides between them), drew straight lines that lie on those sides and colored them along with the part of the plane that lies between them and contains the polygon. Finally, Mirko found a set of points and decided to challenge Slavko to answer for each point whether it lies in the colored or uncolored part of the plane.

The new episode of The Biggest Loser is about to start and Slavko doesn’t have the time to answer Mirko’s queries. Can you help him?

Input

The first line contains an integer which is used as a parameter for generating Mirko’s queries. This number can be either or .

The second line contains an even integer from the task description.

Each of the next lines contains two integers which represent one of the polygon’s vertices. You can assume that the vertices are given in the counter clockwise order and that no three successive vertices are collinear.

The next line contains an integer from the task description.

Each of the next lines contains two integers which are used as parameters for generating the point in the -th of Mirko’s queries.

Let be equal to the number of points in the first (inclusive) of Mirko’s queries that lie in the colored part of the plane. Naturally, . The point of Mirko’s -th query should then be generated as:

where ⊕ represents the bitwise xor operation.

Output

The -th line of output should contain the word DA (YES in Croatian) if the point from -th of Mirko’s queries lies in the colored part of the plane. Otherwise, the -th line should contain the word NE (NO in Croatian).

Sample Input 1

0
4
1 1
5 1
4 3
2 2
4
3 2
2 4
6 2
4 5

Sample Output 1

DA
NE
DA
NE

Sample Input 2

0
6
-1 -1
2 -1
3 3
2 4
1 4
-2 1
6
2 2
3 0
1 -6
2 6
-5 5
5 10

Sample Output 2

DA
DA
NE
NE
NE
NE

Sample Input 3

1
6
-1 -1
2 -1
3 3
2 4
1 4
-2 1
6
2 2
3 0
1 -6
2 6
-5 5
5 10

Sample Output 3

DA
DA
DA
NE
NE
NE

Explanation for Sample Output 3

The colored parts of the plane are the same as in the second example and the points in Mirko’s queries are: and .