#include <bits/stdc++.h>

using namespace std;

using ld = long double;
using Point = complex<ld>;

struct Line{
    Point a, b;
    Line (Point a, Point b) : a(a), b(b) {}
    Line () : Line(Point(), Point()) {}
};

struct Circle{
    Point p;
    ld r;
    Circle (Point p, ld r) : p(p), r(r) {}
    Circle () : Circle(Point(),0.0) {}
};

constexpr ld eps=1e-9, pi=acos(-1.0);

namespace std {
  bool operator<(const Point &lhs, const Point &rhs) {
    if (lhs.real() < rhs.real() - eps) return true;
    if (lhs.real() > rhs.real() + eps) return false;
    return lhs.imag() < rhs.imag();
  }
}

namespace Geometry{
    bool eq(ld a, ld b){
        return abs(a-b) < eps;
    }
    //内積
    ld dot(Point a, Point b){
        return real(conj(a) * b);
    }
    //外積
    ld cross(Point a, Point b){
        return imag(conj(a) * b);
    }
    //3点の位置関係
    int ccw (Point a, Point b, Point c) {
        b -= a; c -= a;
        if (cross(b, c) > eps) return 1;//a,b,cで反時計周り
        if (cross(b, c) < -eps) return -1;//a,b,cで時計周り
        if (dot(b, c) < 0) return 2;//c,a,bで直線
        if (norm(b) < norm(c)) return -2;//a,b,cで直線
        return 0;//a,c,bで直線
    }

//====================================================
    Point inputPoint(){
        ld x, y;
        cin>>x>>y;
        return Point(x, y);
    }
    //2直線の交差判定
    bool isCrossed_ll(Line l, Line m){
        return !eq(cross(l.b-l.a, m.b-m.a), 0);
    }
    //直線と線分の交差判定
    bool isCrossed_ls(Line l, Line s){
        return isCrossed_ll(l, s) && 
            cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps;
    }
    //線分と線分の交差判定
    bool isCrossed_ss(Line s, Line t){
        return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
            ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
    }
    //点が直線上にあるか
    bool isON_l(Line l, Point p){
        return abs(cross(l.b-p, l.a-p)) < eps;
    }
    //点が線分上にあるか
    bool isON_s(Line s, Point p){
        return abs(s.a-p)+abs(s.b-p)-abs(s.b-s.a) < eps;
    }

    //点から直線への垂線の足
    Point foot(Line l, Point p){
        ld t = dot(p-l.a,l.a-l.b)/norm(l.a-l.b);
        return l.a+t*(l.a-l.b);
    }
    //直線と直線の交点
    Point intersection_ll(Line l, Line m){
        Point lv=l.b-l.a, mv=m.b-m.a;
        assert(cross(lv,mv)!=0);//平行
        return l.a+lv*cross(mv,m.a-l.a)/cross(mv,lv);
    }
    //線分と線分の交点
    Point intersection_ss(Line s, Line t){
        assert(isCrossed_ll(s, t));
        return intersection_ll(s,t);
    }

    //点と直線の距離
    ld dist_lp(Line l, Point p) {
        return abs(p - foot(l, p));
    }
    //直線と直線の距離
    ld dist_ll(Line l, Line m){
        return isCrossed_ll(l, m)?0:dist_lp(l, m.a);
    }
    //直線と線分の距離
    ld dist_ls(Line l, Line s){
        return isCrossed_ls(l, s)?0:min(dist_lp(l, s.a), dist_lp(l, s.b));
    }
    //線分と点の距離
    ld dist_sp (Line s, Point p) {
        Point r = foot(s, p);
        return isON_s(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
    }
    //線分と線分の距離
    ld dist_ss (Line s, Line t) {
        if (isCrossed_ss(s, t)) return 0;
        return min({dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)});
    }
    //円と円の交点
    
};

int main(){
    int n;
    using namespace Geometry;
    while(cin>>n,n){
        Point s=inputPoint();
        Point e=inputPoint();
        Line l{s,e};
        ld ans=1e9;
        for(int i=0;i<n;++i){
            Point p[2];
            p[0]=inputPoint();
            p[1]=inputPoint();
            if(s.real()>=p[0].real() && s.real()<=p[1].real()){
                if(p[0].imag() <= s.imag() && s.imag() <= p[1].imag())ans=0.0;
            }
            if(e.real()>=p[0].real() && e.real()<=p[1].real()){
                if(p[0].imag() <= e.imag() && e.imag() <= p[1].imag())ans=0.0;
            }
            ld h;
            cin>>h;
            for(int j=0;j<2;++j){
                for(int k=0;k<2;++k){
                    Line m;
                    if(k)m={Point(p[j].real(),p[j].imag()),Point(p[j].real(),p[1-j].imag())};
                    else m={Point(p[j].real(),p[j].imag()),Point(p[1-j].real(),p[j].imag())};
                    if(isCrossed_ss(l,m)){
                        ans=0.0;
                    }else{
                        ld d=dist_ss(l,m);
                        if(d - h > eps){
                            Point o(0,0),c(d,h);
                            Line q{o,Point(0,1)};
                            Line z{Point(d/2.0,h/2.0),Point(d/2.0+1,h/2.0-d/h)};
                            Point g=intersection_ll(q,z);
                            ans=min(ans,g.imag());
                        }else{
                            ans=min(ans,d);
                        }
                    }
                }
            }
        }
        BREAK:
        cout<<fixed;
        cout<<setprecision(6)<<ans<<endl;
    }
}


Measured memory_bytes: 3244