This page is still under construction.

Parts of this page are still being built. What you see may change.

A Highway and the Seven Dwarfs

Time limit1sMemory limit128 MB

Summary
Given N points and many query lines, report for each line whether all points fall strictly on one side or the line splits them into two groups.
Level

Medium7 of 10

Topics
Geometry, Divide and conquer, Sorting, Binary search
Solved
No attempts yet

Problem

Long ago there was a land called Dwarfland, home to several families of dwarfs. Each family lived in one house, and the dwarfs loved visiting their friends in the other houses.

The humans in the surrounding countries decided to build several straight highways. Some of the planned highways would pass through Dwarfland. The dwarfs are tiny and slow, so they cannot cross a highway safely. If a highway separates the houses into two non-empty groups, some dwarfs can no longer reach their friends. A highway is therefore harmless only if it does not split the houses into two groups.

You are given NN points (houses) in the plane and several straight lines (highways). For each line, decide whether all NN houses lie on the same side of the line, or whether the line divides them into two groups. No highway passes through any house.

Input

The first line contains an integer NN (0≤N≤100 0000 \le N \le 100\,000), the number of houses.

Each of the next NN lines contains two real numbers xix_i and yiy_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9), separated by a space — the coordinates of the ii-th house.

Each remaining line contains four real numbers X1X_1, Y1Y_1, X2X_2, Y2Y_2 (−109≤X1,Y1,X2,Y2≤109-10^9 \le X_1, Y_1, X_2, Y_2 \le 10^9), separated by spaces. They are the coordinates of two distinct points (X1,Y1)(X_1, Y_1) and (X2,Y2)(X_2, Y_2) lying on one highway. There are at most 100 000100\,000 highways, and the input ends at end-of-file.

Output

For each highway, print a single line: GOOD if all houses lie on the same side of the line, or BAD if the line splits the houses into two non-empty groups.

Because the coordinates are real numbers, rounding errors may occur; when checking whether two computed real values are equal, allow a small tolerance (for example 10−410^{-4}).

Examples1

  1. Example 1

    Input
    4
    0.0 0
    6.00 -0.001
    3.125 4.747
    4.747 0.47
    5 3 7 0
    4 -4.7 7 4.7
    4 47 4 94
    
    Expected output
    GOOD
    BAD
    BAD