#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <vector>
using namespace std;

const long double EPS = 1e-9;
const long double PI = acosl(-1);

struct point {
	long double x, y;
	point(long double x = 0.0, long double y = 0.0):x(x), y(y) {}
	point(const point& p):x(p.x), y(p.y) {}

	point operator+ (const point& p) const {
		return point(x + p.x, y + p.y);
	}

	point operator- (const point& p) const {
		return point(x - p.x, y - p.y);
	}

	point operator* (const long double s) const {
		return point(x * s, y * s);
	}

	point operator* (const point& p) const {
		return point(x * p.x - y * p.y, x * p.y + y * p.x);
	}

	point operator/ (const long double s) const {
		return point(x / s, y / s);
	}

	bool operator< (const point& p) const {
		return x + EPS < p.x || abs(x - p.x) < EPS && y + EPS < p.y;
	}

	bool operator== (const point& p) const {
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
};

inline point rotate(const point& p, const long double theta) {
	const long double s = sin(theta), c = cos(theta);
	return point(c * p.x - s * p.y, s * p.x + c * p.y);
}

inline long double angle(const point& p) {
	return atan2(p.y, p.x);
}

inline long double abs(const point& p) {
	return sqrt(p.x * p.x + p.y * p.y);
}

inline long double norm(const point& p) {
	return p.x * p.x + p.y * p.y;
}

inline long double dot(const point& l, const point& r) {
	return l.x * r.x + l.y * r.y;
}

inline long double cross(const point& l, const point& r) {
	return l.x * r.y - l.y * r.x;
}

struct line {
	point a, b;
	line(point a, point b):a(a), b(b){}
};

struct segment {
	point a, b;
	segment(point a, point b):a(a), b(b){}
};

struct circle {
	point c;
	long double r;
	circle(point c, long double r):c(c), r(r){}
};

inline int ccw(const point& a, point b, point c) {
	b = b - a;
	c = c - a;
	const long double tmp = cross(b, c);
	if(tmp > EPS) return 1;
	if(tmp < -EPS) return -1;
	if(dot(b, c) < 0) return 2;
	if(norm(b) < norm(c)) return -2;
	return 0;
}

inline point projection(const line& l, const point& p) {
	const point dif = l.b - l.a;
	const long double tmp = dot(p - l.a, dif) / norm(dif);
	return l.a + dif * tmp;
}

inline bool intersect(const segment& s, const point& p) {
	return ccw(s.a, s.b, p) == 0;
}

inline bool intersect(const line& l, const line& m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > EPS || abs(cross(l.b - l.a, m.b - l.a)) < EPS;
}

inline bool intersect(const circle& c, const point& p) {
	return abs(c.c - p) < c.r - EPS;
}

inline bool intersect(const circle& c, const circle& d) {
	return abs(c.c - d.c) <= c.r + d.r && abs(c.c - d.c) >= abs(c.r - d.r);
}

inline long double dist(const point& a, const point& b) {
	return abs(a - b);
}

inline vector<point> crosspoint(const circle &c, const circle& d) {
	vector<point> res;
	if(abs(c.c - d.c) < EPS)
		return res;

	const long double tmp = abs(c.c - d.c);
	const long double rc = (tmp * tmp + c.r * c.r - d.r * d.r) / (tmp + tmp);
	const long double rs = sqrt(c.r * c.r - rc * rc);
	const point diff = (d.c - c.c) / tmp;
	res.push_back(point(c.c + diff * point(rc, rs)));
	res.push_back(point(c.c + diff * point(rc, -rs)));
	return res;
}

inline vector<point> crosspoint(const circle& c, const line& l) {
	vector<point> res;
	const point h = projection(l, c.c);
	const long double d = abs(h - c.c);
	if(abs(d - c.r) < EPS) {
		res.push_back(h);
	}
	else if(d < c.r - EPS) {
		point v = l.b - l.a;
		v = v * sqrt(c.r * c.r - d * d) / abs(v);
		res.push_back(h + v);
		res.push_back(h - v);
	}

	return res;
}

inline vector<point> crosspoint(const circle& c, const segment& s) {
	vector<point> res;
	vector<point> tmp = crosspoint(c, line(s.a, s.b));
	for(int i = 0; i < tmp.size(); ++i)
		if(intersect(s, tmp[i]))
			res.push_back(tmp[i]);

	return res;
}

inline long double calc_circumference(const circle& c) {
	return 2.0 * PI * c.r;
}

inline long double calc_length_of_arc(const circle& c, long double a) {
	return calc_circumference(c) * (a / (2 * PI));
}

inline void convert(int len, int& x1, int& y1, int& x2, int& y2) {
	if(abs(y2 - y1) > abs(x2 - x1)) swap(x1, y1), swap(x2, y2);
	if(x1 < 0 && x2 < 0) x1 = -x1, x2 = -x2;
	if(y1 < 0 && y2 < 0) y1 = -y1, y2 = -y2;
	if(y1 * y2 <= 0) swap(x1, y1), swap(x2, y2);
	if(x1 > x2) swap(x1, x2);
	if(y1 > y2) swap(y1, y2);
	if(x1 * x2 <= 0 && abs(x1) > abs(x2)) {
		const int d = abs(x1) - abs(x2);
		x1 += d, x2 += d;
	}
	if(0 < x1 && 0 < y1 && x2 < len && y2 < len && y1 * 40 < len) {
		swap(x1, y1);
		swap(x2, y2);
	}
}

typedef array<point, 4> rectangle;

int main() {
	const point origin(0.0, 0.0);

	for(int len, x1, y1, x2, y2; scanf("%d %d %d %d %d", &len, &x1, &y1, &x2, & y2) == 5 && len;) {
		convert(len, x1, y1, x2, y2);

		rectangle building;
		building[0] = point(x1, y1);
		building[1] = point(x2, y1);
		building[2] = point(x2, y2);
		building[3] = point(x1, y2);

		circle leash(origin, len);
		vector<pair<long double, point>> cross_points;
		for(int i = 0; i < 4; ++i) {
			if(intersect(leash, building[i])) {
				cross_points.emplace_back(angle(building[i]), building[i]);
			}
		}

		for(int i = 0; i < 4; ++i) {
			const segment edge(building[i], building[(i + 1) % 4]);
			const vector<point> cp = crosspoint(leash, edge);
			for(int j = 0; j < (int)cp.size(); ++j) {
				cross_points.emplace_back(angle(cp[j]), cp[j]);
			}
		}

		sort(cross_points.begin(), cross_points.end());
		cross_points.erase(unique(cross_points.begin(), cross_points.end()), cross_points.end());

		if(cross_points.size() <= 1) {
			printf("%.6Lf\n", calc_circumference(leash));
			continue;
		}

		long double ans = calc_circumference(leash) / 2.0;

		long double left_angle = PI - cross_points.back().first;
		point left_point = cross_points.back().second;
		circle left_circle(left_point, len - dist(left_point, origin));
		ans += calc_length_of_arc(leash, left_angle);

		long double right_angle = cross_points.front().first;
		point right_point = cross_points.front().second;
		circle right_circle(right_point, len - dist(right_point, origin));
		ans += calc_length_of_arc(leash, right_angle);

		if(left_point == building[3]) {
 			ans -= calc_length_of_arc(left_circle, left_angle - PI / 2.0);
		}

		else if(left_point == building[0]) {
			ans += calc_length_of_arc(left_circle, (PI / 2.0 - left_angle));
			const int length_of_edge = y2 - y1;
			if(length_of_edge + EPS < left_circle.r) {
				left_point = building[3];
				left_circle = circle(left_point, left_circle.r - length_of_edge);
			}
		}

		if(left_point == building[3] && right_point == building[1] && intersect(left_circle, right_circle)) {
			vector<point> tmp = crosspoint(left_circle, right_circle);
			point cp = (tmp[0].y > tmp[1].y ? tmp[0] : tmp[1]);
			if(cp.x - EPS > building[2].x) {
				long double a = PI / 2.0 - angle(cp - left_point);
				ans += calc_length_of_arc(left_circle, a);

				a = angle(cp - right_point) - right_angle;
				ans += calc_length_of_arc(right_circle, a);
				printf("%.6Lf\n", ans);
				continue;
			}
		}

		if(right_point == building[1]) {
			ans += calc_length_of_arc(right_circle, (PI / 2.0 - right_angle));
			const int length_of_edge = y2 - y1;
			if(length_of_edge + EPS < right_circle.r) {
				right_point = building[2];
				right_circle = circle(right_point, right_circle.r - length_of_edge);
			}
		}

		if(left_point == building[3] && right_point == building[2]
		   && intersect(left_circle, right_circle)) {
			vector<point> tmp = crosspoint(left_circle, right_circle);
			point cp = (tmp[0].y > tmp[1].y ? tmp[0] : tmp[1]);

			long double a = PI / 2.0 - angle(cp - left_point);
			ans += calc_length_of_arc(left_circle, a);

			a = angle(cp - right_point) - PI / 2.0;
			ans += calc_length_of_arc(right_circle, a);
		}
		else {
			if(left_point == building[3]) ans += calc_length_of_arc(left_circle, PI / 2.0);
			if(right_point == building[2])  ans += calc_length_of_arc(right_circle, PI / 2.0);
		}

		printf("%.6Lf\n", ans);
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1080