#include using namespace std; template struct Point { typedef Point P; T x, y; explicit Point(T x=0, T y=0) : x(x), y(y) {} P operator+(P p) const { return P(x+p.x, y+p.y); } P operator-(P p) const { return P(x-p.x, y-p.y); } P operator*(T d) const { return P(x*d, y*d); } P operator/(T d) const { return P(x/d, y/d); } T dist2() const { return x*x + y*y; } double dist() const { return sqrt((double)dist2()); } }; typedef Point P; vector> segments; template long double ternSearch(P a, P b, F f) { while((b - a).dist2() > 1e-15) { P p1 = (a*2 + b) / 3; P p2 = (a + b*2) / 3; if (f(p1) > f(p2)) a = p1; else b = p2; } return f(a); } long double solve(int lo, int hi, P start, P end) { if(lo == hi) return (end - start).dist(); int mid = (lo + hi) / 2; P p1, p2; tie(p1, p2) = segments[mid]; auto eval = [&](P midpoint) { return solve(lo, mid, start, midpoint) + solve(mid+1, hi, midpoint, end); }; return ternSearch(p1, p2, eval); } int main() { int n; cin >> n; P start, end; segments.resize(n); cin >> start.x >> start.y; for(int i = 0; i < n; i++) cin >> segments[i].first.x >> segments[i].first.y >> segments[i].second.x >> segments[i].second.y; cin >> end.x >> end.y; cout << setprecision(12) << fixed << solve(0, n, start, end) << "\n"; }