Hole in One

Find the most walls a ball shot from the origin can destroy by bouncing off axis-aligned walls before dropping into the hole.

Hard8BacktrackingGeometrySimulationNo attempts yetTime limit5sMemory limit256 MB

Problem

Janine went to her local game store and bought Hole in One, a new mini golf game for her computer. As the name says, the goal is to shoot the ball into the hole with a single shot. The game also borrows from brick breaker games: the playing field holds several walls, and a wall is destroyed when the ball hits it. The score of a successful shot depends on how many walls were destroyed, so Janine wants to know the largest number of walls she can hit while still making a hole in one.

Think of the playing field as the cartesian plane with the ball starting at the origin. Each wall is a line segment parallel to the xx axis or to the yy axis, and the walls do not intersect. The diameter of the ball is negligible, so the ball is a single point.

Figure: an illustration of the first sample input. The ball bounces off two walls, at point 1 and at point 2. By the time it passes point 3, that wall has already vanished.

Two things happen whenever the ball hits a wall.

  • The direction of the ball changes in the usual way: the angle of incidence equals the angle of reflection.
  • The wall that the ball touched is destroyed. Following common video game logic, no rubble remains and the place where the wall stood is completely empty.

A wall segment contains both of its endpoints. If the ball touches a wall exactly at an endpoint, that wall is destroyed too and the ball is reflected by the same rule.

Janine also picks the power of the shot. The power decides how far the ball rolls, and the ball may roll over the hole several times and drop in on whichever pass she wants. So the best shot may roll over the hole first, hit more walls, and only later drop into the hole.

Input

The first line contains one integer nn (0n80 \le n \le 8), the number of walls.

The second line contains two integers xx and yy, the coordinates of the hole.

Each of the next nn lines contains four integers x1x_1, y1y_1, x2x_2, and y2y_2, describing a wall with endpoints (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). Exactly one of x1=x2x_1 = x_2 and y1=y2y_1 = y_2 holds.

The hole is not at the origin and not on a wall. No two walls touch or intersect. No wall lies completely on the xx axis or on the yy axis. All coordinates in the input are integers with absolute value at most 10001000.

Output

If there is no way to shoot the ball so that it reaches the hole, print impossible. Otherwise print the largest number of walls that can be destroyed in a single hole in one shot.