A4498 「ICPC World Finals 2025」阳光下行走

暂无评定 传统题 ICPC 上传者
时间限制2000ms
内存限制2048MiB
通过 / 提交0/0

A4498「ICPC World Finals 2025」阳光下行走

暂无评定 传统题 ICPC 上传者
时间限制2000ms
内存限制2048MiB
通过 / 提交0/0

Description

I'm walking on sunshine, and it don't feel good - my eyes hurt! Baku has plenty of sunshine. If you walk away from the sun, or at least perpendicular to its rays, it does not shine in your eyes. For this problem assume that the sun shines from the south. Walking west or east or in any direction between west and east with a northward component avoids looking into the sun. Your eyes will hurt if you walk in any direction with a southward component.

Baku also has many rectangular areas of shade, and staying in these protects your eyes regardless of which direction you walk in. For example, Figure L. 1 shows two shaded areas.

Find the minimum distance you need to walk with the sun shining in your eyes to get from the contest location to the awards ceremony location.

Figure L.1: Sample Input 1 and a path that minimizes the sun shining in your eyes.

Input

The first line of input contains five integers n,xc,yc,xan, x_{c}, y_{c}, x_{a}, and yay_{a}, where n(0≤n≤105)n\left(0 \leq n \leq 10^{5}\right) is the number of shaded areas, (xc,yc)\left(x_{c}, y_{c}\right) is the location of the contest, and ( xa,yax_{a}, y_{a} ) is the location of the awards ceremony ( $-10^{6} \leq x_{c}, y_{c}, x_{a}, y_{a} \leq 10^{6}$ ). The sun shines in the direction (0,1)(0,1) from south towards north. You look into the sun if you walk in direction (x,y)(x, y) for any y<0y<0 and any xx.

The next nn lines describe the shaded areas, which are axis-aligned rectangles. Each of these lines contains four integers x1,y1,x2x_{1}, y_{1}, x_{2}, and y2y_{2} $\left(-10^{6} \leq x_{1}<x_{2} \leq 10^{6} ;-10^{6} \leq y_{1}<y_{2} \leq 10^{6}\right)$. The southwest corner of the rectangle is (x1,y1)(x_{1}, y_{1}) and its northeast corner is ((x2,y2)(x_{2}, y_{2}). The rectangles describing the shaded areas do not touch or intersect.

Output

Output the minimum distance you have to walk with the sun shining in your eyes. Your answer must have an absolute or relative error of at most 10−710^{-7}.

2 1 7 5 1
3 6 5 9
2 3 6 5

3.0

Figure L. 1 shows an optimal path from the contest location to the awards ceremony location with 55 segments. On the first segment you walk away from the sun. On the second and fourth segments you walk towards the sun but in a shaded area. On the third and fifth segments you walk towards the sun outside the shaded areas. The total length of these two segments is 33.

2 0 10 10 0
2 7 3 8
4 3 8 5

7.0

2 11 -1 -1 11
2 7 3 8
4 3 8 5

0.0

3 1 5 9 5
-5 6 2 9
4 7 12 8
1 1 7 3

0.0

3 1 7 9 3
2 6 3 8
4 4 5 6
6 2 7 4

0.0

1 0 0 0 0
-5 -5 5 5

0.0