Under construction

Still being built. Things may change

Ribbon Road

Time limit1sMemory limit1024 MB

Summary
Given a simple polygon, Christie's position on its boundary, and a point her ray passes through, decide whether she is inside, outside, or cannot tell.
Level

Medium6 of 10

Topics
Geometry, Implementation
Solved
No attempts yet

Problem

Christie is an ant that likes to crawl on a closed ribbon (a polygon whose start and end points are attached to each other). Her owner, Cindy, places a sugar cube on the ribbon for her to enjoy. Cindy always puts the sugar cube on the exterior side of the ribbon, so Christie wants to crawl on the exterior side to find a sugar cube somewhere down the ribbon road. However, Christie is so tiny that she often cannot tell whether she is crawling on the inside or the outside. If she is on the inside, she has to carefully crawl to the outside.

Christie's antenna emits a signal, which is a ray. A ray travels from her location to some other point (x,y)(x,y), and it may pass through the ribbon. The rays she emits span [0∘,180∘][0^\circ, 180^\circ] relative to the line segment she stands on. The direction parallel to that segment and pointing forward is 0∘0^\circ, and the direction parallel to it and pointing away from her is 180∘180^\circ. The span of the ray goes above her.

The ribbon does not twist (it does not rotate about itself), so it is not a Möbius band. Therefore, whether Christie is on the inside or the outside stays the same as she walks along the ribbon.

If the ray is parallel to the segment she stands on, she cannot tell whether she is inside or outside. If she stands on a vertex, she might not be able to tell either. At a vertex, she can be parallel to either edge adjacent to that vertex. Help Christie find out whether she is on the inside of the ribbon road.

An illustration of Christie's antenna range. If the antenna points at 0∘0^\circ or 180∘180^\circ, Christie cannot tell whether she is inside or outside.

Input

The first line contains a single integer NN (3≤N≤1053 \leq N \leq 10^5), the number of vertices of the polygon. The next NN lines each contain a pair of integers (xi,yi)(x_i, y_i), the iith vertex of the polygon in order (1≤i≤N1 \leq i \leq N). The ribbon road is a closed simple polygon, so the last vertex connects back to the first vertex. No three consecutive vertices are collinear.

The final line contains four integers: (xc,yc)(x_c, y_c), Christie's location, and (x,y)(x, y), a point that Christie's signal passes through. Christie always stays on the ribbon in a direction parallel to the ribbon, but (x,y)(x, y) has no restrictions. If Christie stands on a vertex, she can be parallel to either edge adjacent to that vertex. It is guaranteed that (xc,yc)≠(x,y)(x_c, y_c) \neq (x, y).

All coordinates satisfy −106≤xi,yi,xc,yc,x,y≤106-10^6 \leq x_i, y_i, x_c, y_c, x, y \leq 10^6.

Output

Output a single line: inside if Christie is inside the ribbon road, outside if she is outside it, or ? if it cannot be determined.

Examples5

  1. Example 1

    Input
    4
    0 0
    2 0
    2 2
    0 2
    1 0 1 1
    
    Expected output
    inside
    
  2. Example 2

    Input
    4
    0 0
    0 2
    2 2
    2 0
    1 0 -1 0
    
    Expected output
    ?
    
  3. Example 3

    Input
    4
    0 0
    5 0
    5 5
    0 5
    4 0 1 0
    
    Expected output
    ?
    
  4. Example 4

    Input
    4
    0 0
    2 0
    2 2
    0 2
    0 0 1 1
    
    Expected output
    inside
    
  5. Example 5

    Input
    4
    0 0
    2 0
    2 2
    0 2
    0 0 -1 -1
    
    Expected output
    outside