Under construction

Still being built. Things may change

Mining Rights Division

Time limit1sMemory limit2048 MB

Summary
Given chords that split a disk and two interior points, decide whether both points can lie in regions of the same two-coloring class.
Level

Medium6 of 10

Topics
Geometry, Math, Graph
Solved
No attempts yet

Problem

A circular plot of land contains two very valuable resources at two different locations. Because of their enormous value, many companies competed for the mining rights, but a strict screening process selected only two companies. Your company is one of the two companies that finally received the mining rights. To avoid accusations of favoritism, the government devised a fair way to divide the land between the two companies, as follows:

  • Rule 1 (Division by company A): Company A may divide the circular land into smaller regions using fewer than 10 00010\,000 line segments. Each segment starts at one point on the circumference and ends at another point on the circumference.
  • Rule 2 (No shared borders): Regions that share a straight border must be developed by different companies.
  • Rule 3 (Acceptance and choice by company B): Company B may accept or reject the division proposed by company A. If company B accepts, company B may choose one of the resulting regions. The remaining regions are assigned to the two companies automatically according to Rule 2.

You already know the two resource locations p1p_1 and p2p_2. On behalf of company B, you must decide whether to accept or reject company A's division so that both locations lie in regions assigned to company B.

Given the division proposal as a set of line segments and the two resource locations, write a program that decides whether company B should accept the proposal.

Input

Input is read from standard input. The first line contains an integer nn, the number of segments that divide the circle, where nn is less than 10 00010\,000. The next nn lines describe the segments. Each line contains two integer indices that give the two endpoints of one segment. The circumference is divided into 3 6003\,600 units. The point on the circumference that lies exactly due east of the center has index 00, and the index increases counterclockwise up to 3 5993\,599. No segment is duplicated. After the nn lines, two more lines give the resource locations p1p_1 and p2p_2, which are different from each other. Each location is given by two integers. The first integer is the index where the ray from the center through the location meets the circumference. The second integer is the distance from the center to the resource. The radius is divided into 1 0001\,000 units, so the center has distance 00 and points on the circumference have distance 1 0001\,000. Each resource lies inside the circle and never lies on a segment.

Output

Output is written to standard output as exactly one line. Print "YES" if company B can obtain both resource locations p1p_1 and p2p_2. Otherwise, print "NO".

Examples2

  1. Example 1

    Input
    3
    450 1800
    900 0
    450 2700
    900 850
    450 500
    
    Expected output
    NO
    
  2. Example 2

    Input
    4
    450 1800
    0 1350
    1350 2700
    2700 0
    450 500
    3150 950
    
    Expected output
    YES