Rectangles

Given a set of rectangles in the plane, determine if it is possible to choose one diagonal from each rect- angle such that none of the selected diagonals inter- sect. Two diagonals intersect if they share at least one point. Note that the rectangles themselves are free to intersect. Input Input consists of several test cases. Each test case begins with an integer n (1 ≤ n ≤ 1000), represent- ing the number of rectangles. This is followed by n lines each describing a rectangle using 8 integer num- bers x1,y1,x2,y2,x3,y3,x4,y4, where each (xi,yi) is a vertex. All coordinate values are between −109 and 109. The input is terminated by a line containing ‘0’ which should not be processed. Output For each test case, output a line containing either ‘YES’ if the selection is possible or ‘NO’ if not. Sample Input 4 01111000 11212010 23535020 23333222 7 0 10 10 10 10 0 0 0 10 10 20 10 20 0 10 0 20 30 50 30 50 0 20 0 20 30 30 30 30 20 20 20 30 10 40 10 40 0 30 0 50 30 0 30 -10 5 -10 0 0 5 0 5 -10 0 -10 0 Sample Output YES NO