#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const double EPS = 1e-6;

struct Point
{
	double x, y;

	Point() : x( 0 ), y( 0 ) {}
	Point( const double x, const double y ) : x( x ), y( y ) {}
	Point( const Point &a ) : x( a.x ), y( a.y ) {}
	
	const Point operator + ( const Point &a ) const
	{
		return Point( x + a.x, y + a.y );
	}

	Point& operator += ( const Point &a ) 
	{
		x += a.x;
		y += a.y;

		return *this;
	}

	const Point operator - ( const Point &a ) const
	{
		return Point( x + ( -a.x ), y + ( -a.y ) );
	}

	Point& operator -= ( const Point &a )
	{
		x -= a.x;
		y -= a.y;

		return *this;
	}

	const Point operator * ( const double a ) const
	{
		return Point( x * a, y * a );
	}

	Point& operator *= ( const double a )
	{
		x *= a;
		y *= a;

		return *this;
	}

	const Point operator / ( const double a ) const
	{
		return Point( x / a, y / a );
	}

	Point& operator /= ( const double a )
	{
		x /= a;
		y /= a;

		return *this;
	}

	bool operator < ( const Point &a ) const
	{
		return x == a.x ? y < a.y : x < a.x;
	}

	double abs() const
	{
		return sqrt( pow( x, 2. ) + pow( y, 2. ) );
	}
};

// 二点間の距離
double distance( const Point &a, const Point &b )
{
	return sqrt( pow( a.x - b.x, 2. ) + pow( a.y - b.y, 2. ) );
}

// 内積（ドット積）
double dot( const Point &a, const Point &b )
{
	return a.x * b.x + a.y * b.y;
}

// 外積（クロス積）
double cross( const Point &a, const Point &b )
{
	return a.x * b.y - a.y * b.x;
}

// 線分 ( p1, p2 ) と点 q の距離
double distance_segment_point( const Point &p1, const Point &p2, const Point q )
{
	if ( EPS < dot( p2 - p1, q - p1 ) && EPS < dot( p1 - p2, q - p2 ) )
	{
		return abs( cross( p2 - p1, q - p1 ) ) / ( p2 - p1 ).abs();
	}
	else
	{
		return min( distance( p1, q ), distance( p2, q ) );
	}
}

// 線分 ( p1, p2 ) に点 q が乗っているか
bool point_on_segment( const Point &p1, const Point &p2, const Point &q )
{
	return abs( cross( p1 - q, p2 - q ) ) <= EPS && dot( p1 - q, p2 - q ) <= EPS;
}

// 直線 ( p1, p2 ) と直線 ( q1, q2 ) の交点
Point lines_intersection( const Point &p1, const Point &p2, const Point &q1, const Point &q2 )
{
	return p1 + ( p2 - p1 ) * ( cross( q2 - q1, q1 - p1 ) / cross( q2 - q1, p2 - p1 ) );
}

// 線分 ( p1, p2 ) と線分 ( q1, q2 ) が交差するか
bool segments_intersection( const Point &p1, const Point &p2, const Point &q1, const Point &q2 )
{		
	if ( abs( cross( p1 - p2, q1 - q2 ) ) <= EPS ) // is parallel
	{
		return point_on_segment( p1, p2, q1 ) ||
			   point_on_segment( p1, p2, q2 ) ||
			   point_on_segment( q1, q2, p1 ) ||
			   point_on_segment( q1, q2, p2 );
	}
	else
	{
		Point r( lines_intersection( p1, p2, q1, q2 ) );
		return point_on_segment( p1, p2, r ) && point_on_segment( q1, q2, r );
	}
}

// 三角形 ( a, b, c ) の中に点 p があるか
bool point_in_triangle( const Point &a, const Point &b, const Point &c, const Point &p )
{
	int res = 0;
	res += EPS < cross( b - a, p - a ) ? 1 : -1;
	res += EPS < cross( c - b, p - b ) ? 1 : -1;
	res += EPS < cross( a - c, p - c ) ? 1 : -1;

	if ( abs( res ) == 3 )
	{
		return true;
	}
	return point_on_segment( a, b, p ) || point_on_segment( b, c, p ) || point_on_segment( c, a, p );
}

double search( const Point &p1, const Point &p2, const Point &q, const int h )
{
	const double dist = distance_segment_point( p1, p2, q );
	if ( dist - EPS <= h )
	{
		return dist;
	}

	double lb = 0, ub = 1000;
	REP( i, 0, 100 )
	{
		double r = ( lb + ub ) / 2;
		if ( r <= distance( Point( 0, r ), Point( dist, h ) ) + EPS )
		{
			lb = r;
		}
		else
		{
			ub = r;
		}
	}

	return lb;
}

double solve( const int n )
{
	int sx, sy, ex, ey;
	cin >> sx >> sy >> ex >> ey;
	Point s( sx, sy ), e( ex, ey );

	VI hs;
	vector< Point > points;
	vector< pair<Point,Point> > lines;

	REP( i, 0, n )
	{
		int x1, y1, x2, y2, h;
		cin >> x1 >> y1 >> x2 >> y2 >> h;

		points.PB( Point( x1, y1 ) );
		points.PB( Point( x2, y2 ) );
		points.PB( Point( x1, y2 ) );
		points.PB( Point( x2, y1 ) );

		lines.PB( MP( Point( x1, y1 ), Point( x1, y2 ) ) );
		lines.PB( MP( Point( x1, y1 ), Point( x2, y1 ) ) );
		lines.PB( MP( Point( x2, y2 ), Point( x1, y2 ) ) );
		lines.PB( MP( Point( x2, y2 ), Point( x2, y1 ) ) );

		hs.PB( h );
	}

	REP( i, 0, lines.size() )
	{
		if ( segments_intersection( s, e, lines[i].fst, lines[i].snd ) )
		{
			return 0;
		}
	}
	REP( i, 0, n )
	{
		if ( point_in_triangle( points[ i * 4 ], points[ i * 4 + 1 ], points[ i * 4 + 2 ], s ) ||
			 point_in_triangle( points[ i * 4 ], points[ i * 4 + 1 ], points[ i * 4 + 2 ], e ) ||
			 point_in_triangle( points[ i * 4 ], points[ i * 4 + 1 ], points[ i * 4 + 3 ], s ) ||
			 point_in_triangle( points[ i * 4 ], points[ i * 4 + 1 ], points[ i * 4 + 3 ], e ) )
		{
			return 0;
		}
	}

	double res = 1000;
	REP( i, 0, n * 4 )
	{
		res = min( res, search( s, e, points[i], hs[ i / 4 ] ) );
		res = min( res, search( lines[i].fst, lines[i].snd, s, hs[ i / 4 ] ) );
		res = min( res, search( lines[i].fst, lines[i].snd, e, hs[ i / 4 ] ) );
	}

	return res;
}

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	cout << setprecision( 4 ) << fixed;

	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		cout << solve( n ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1312