Laser Game

Given n directed rays and two points s and t, find the minimum number of rays a curve from s to t must cross.

Medium7GeometryGraphShortest pathNo attempts yetTime limit2sMemory limit512 MB

Problem

You are playing a game against several classmates. Each opponent carries a device that fires one laser beam. The beam starts at that opponent's own position, goes in the direction the opponent picks, and continues forever. Once every beam is aimed and fixed, your turn starts. You stand at a point ss and have to run to a point tt, and you want the path you run to cross as few beams as possible.

The field is a two dimensional plane. The nn opponents o1,o2,,ono_1, o_2, \dots, o_n stand at nn distinct points p1,p2,,pnp_1, p_2, \dots, p_n, and opponent oio_i fires a one way beam from pip_i. Some beams can be parallel. The points ss and tt differ from every pip_i.

Your path is any curve from ss to tt. It crosses a beam when it passes from one side of that beam to the other side. Beam ii covers pip_i and the points after it along the chosen direction, so a path that goes around pip_i on the side the beam does not cover never crosses beam ii.

Find the smallest number of beams a path from ss to tt has to cross.

Input

The input holds several test cases. The first line of a test case has nn, the number of laser beams (1n2001 \le n \le 200). Each of the next nn lines has four space separated integers. The first two are the xx and yy coordinates of an opponent, and the last two are the xx and yy coordinates of a point that lies on that opponent's beam. The last line of a test case has four integers, the xx and yy coordinates of ss followed by the xx and yy coordinates of tt.

No three of the points given in a test case lie on one line, and every coordinate has absolute value at most 10810^8. A line holding a single 00 ends the input, and you do not process it.

Output

For each test case, print one line with the minimum number of beams the path has to cross.