Under construction

Still being built. Things may change

Land

Time limit2sMemory limit1024 MB

Summary
Lines with coefficients in {-1,0,1} are added online, and for each query the task is to tell whether two points lie in the same region of the plane cut by all lines so far.
Level

Hard8 of 10

Topics
Divide and conquer, Union-find, Geometry
Solved
No attempts yet

Problem

Farmer Lasagna bought his dream land, where his cows will live and where he will grow his corn. Cows love to eat corn and will destroy any crop they can reach. So Lasagna plans to build long walls that are high and strong enough that his cows cannot cross them. Lasagna is busy with a performance in Sweden, so he asks you to help him organize his land.

The land is a coordinate plane, and each wall is a line on that plane. Lasagna will send Q queries, and each query is one of two types:

  1. Build a wall given by the equation ax+by=cax + by = c, which is the line of all points (x,y)(x, y) that satisfy it. Lasagna guarantees that aa and bb are integers from -1 to 1.

  2. Given the walls built so far, a cow stands at point (x1,y1)(x_1, y_1) and a corn crop is planted at point (x2,y2)(x_2, y_2). Can the cow reach (x2,y2)(x_2, y_2) and destroy the crop?

Can you help him answer all of his queries?

Input

The first line contains an integer QQ (1≤Q≤3000001 \le Q \le 300000), the number of queries.

Each of the next QQ lines is in one of two formats.

  1. "1 a b c", where aa, bb, and cc are integers with −1≤a,b≤1-1 \le a, b \le 1, a≠0a \ne 0 or b≠0b \ne 0, and −3⋅108≤c≤3⋅108-3 \cdot 10^8 \le c \le 3 \cdot 10^8. The test data guarantees that when the wall is built, no existing wall coincides with the new wall at every point.

  2. "2 x1 y1 x2 y2", where x1x_1, y1y_1, x2x_2, and y2y_2 are integers with −108≤x1,y1,x2,y2≤108-10^8 \le x_1, y_1, x_2, y_2 \le 10^8. (x1,y1)(x_1, y_1) is the cow's position and (x2,y2)(x_2, y_2) is the corn's position. The test data guarantees that at that moment neither point lies on any wall, and the two points are different.

Output

For each query of the second type, print "DA" on its own line if the cow can reach the crop, or "NE" otherwise.

Hint

In the first sample, the first line is the x-axis, and it separates points with positive y-coordinates from points with negative y-coordinates. The second line is the y-axis, and together they split the points by quadrant.

The sketch in the third sample shows the lines for all walls and all points that were queried.

Examples3

  1. Example 1

    Input
    4
    1 0 1 0
    2 -1 2 2 1
    1 -1 0 0
    2 -1 2 2 1
    
    Expected output
    DA
    NE
    
  2. Example 2

    Input
    5
    1 -1 -1 2
    1 1 -1 3
    2 0 0 -4 5
    2 5 -3 3 1
    2 1 -5 -10 2
    
    Expected output
    DA
    NE
    NE
    
  3. Example 3

    Input
    8
    2 -2 3 1 2
    1 1 -1 -3
    2 1 2 -2 3
    2 3 3 1 2
    1 0 1 1
    2 3 3 5 6
    1 1 0 4
    2 1 2 5 6
    
    Expected output
    DA
    NE
    DA
    DA
    NE