#icpc2015summerday4h. [icpc2015summer_day4_h]Laser Cutter

[icpc2015summer_day4_h]Laser Cutter

MathJax.Hub.Config({ tex2jax: { inlineMath: [["","",""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }

Problem Statement

Ciel is going to do woodworking. Ciel wants to make a cut in a wooden board using a laser cutter.

To make it simple, we assume that the board is a two-dimensional plane. There are several segments on the board along which Ciel wants to cut the board. Each segment has a direction and Ciel must cut those segments along their directions. Those segments are connected when you ignore the directions, that is, any two points on the segments are directly or indirectly connected by the segments.

While the laser cutter is powered on, it emits a laser which hits the board at a point and cuts the board along its trace. The laser initially points to (x,y)(x, y). Ciel can conduct the following two operations:

  • Move the laser cutter with its power on and cut (a part of) a segment along its direction, or
  • Move the laser cutter to any position with its power off. Ciel should not necessarily cut the whole segment at a time; she can start or stop cutting a segment at any point on the segments.

Ciel likes to be efficient, so she wants to know the shortest route such that the laser cutter cuts the whole parts of all the segments and then move back to the initial point. Your task is to write a program that calculates the minimum total moving distance of the laser cutter.


Input

The first line of the input contains an integer nn (1leqnleq3001 \\leq n \\leq 300), the number of segments. The next line contains two integers xx and yy (1,000leqx,yleq1,000-1{,}000 \\leq x, y \\leq 1{,}000), which is the initial position (x,y)(x, y) of the laser. The ii-th of the following nn lines contains four integers sx_isx\_i, sy_isy\_i, tx_itx\_i and ty_ity\_i ($-1{,}000 \\leq sx\_i, sy\_i, tx\_i, ty\_i \\leq 1{,}000$), which indicate that they are the end points of the ii-th segment, and that the laser cutter can cut the board in the direction from (sx_i,sy_i)(sx\_i, sy\_i) to (tx_i,ty_i)(tx\_i, ty\_i). The input satisfies the following conditions: For all ii (1leqileqn1 \\leq i \\leq n), (sx_i,sy_i)neq(tx_i,ty_i)(sx\_i, sy\_i) \\neq (tx\_i, ty\_i). The initial point (x,y)(x, y) lies on at least one of the given segments. For all distinct i,ji, j (1leqi,jleqn1 \\leq i, j \\leq n), the ii-th segment and the jj-th segment share at most one point.

Output

Output a line containing the minimum total moving distance the laser cutter needs to travel to cut all the segments and move back to the initial point. The absolute error or the relative error should be less than 10610^{-6}.


Sample Input 1

3
0 1
0 0 0 1
0 1 0 2
0 2 0 3```

### Output for the Sample Input 1

```plain
6.0000000000000000```

* * *

### Sample Input 2

```plain
2
0 1
0 0 0 2
-1 1 1 1```

### Output for the Sample Input 2

```plain
6.8284271247461900```

* * *

### Sample Input 3

```plain
5
0 0
0 0 1 0
1 1 -1 1
-1 1 -1 -1
-1 -1 1 -1
1 -1 1 1```

### Output for the Sample Input 3

```plain
10.0000000000000000```

* * *