#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : VP{
    L(const P& a, const P& b){ resize(2); at(0)=a; at(1)=b; }
    L(){ resize(2); }
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
};
double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
double angle(P a, P b){
    return acos(dot(a,b)/(abs(a)*abs(b)));
}
P projection(const L& l, const P& p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}
VP crosspointCC(const C& a, const C& b){
    VP ps;
    P ab = b.p-a.p;
    double dist = abs(ab);
    if(GE(dist, a.r +b.r) || LE(dist, abs(a.r-b.r))){
        return ps;
    }
    if(EQ(dist, a.r+b.r)){
        ps.push_back( a.p +ab*(a.r/dist) );
        return ps;
    }
    if(EQ(dist, a.r-b.r)){
        ps.push_back( a.p +ab*(a.r/dist) );
        return ps;
    }
    if(EQ(dist, b.r-a.r)){
        ps.push_back( b.p -ab*(b.r/dist) );
        return ps;
    }
    double l = ((a.r*a.r -b.r*b.r)/dist +dist) /2;
    double n = sqrt(a.r*a.r -l*l);
    P mid = a.p + (ab)*(l/dist);
    P hei = ab *(n/dist) *P(0,1);
    ps.push_back(mid+hei);
    ps.push_back(mid-hei);
    return ps;
}

VP crosspointLC(const L &l, const C &c){
    VP ret;
    P mid = projection(l, c.p);
    double dlp = distanceLP(l, c.p);
    if(EQ(dlp, c.r)){
        ret.push_back(mid);
        return ret;
    }
    if(dlp > c.r){
        return ret;
    }
    P d = sqrt(c.r*c.r -dlp*dlp)/abs(l[1]-l[0]) *(l[1]-l[0]);
    ret.push_back(mid-d);
    ret.push_back(mid+d);
    return ret;
}

int main(){
    while(1){
        int len,x1,y1,x2,y2;
        cin >> len >> x1 >> y1 >> x2 >> y2;
        if(len==0) break;

        //trans coord.
        if(x1<0 && x2<=0){
            x1= -x1;
            x2= -x2;
            swap(x1,x2);
        }
        if(y1<0 && y2<=0){
            y1= -y1;
            y2= -y2;
            swap(y1,y2);
        }
        if(y1*y2 < 0){
            swap(x1,y1);
            swap(x2,y2);
        }
        if(abs(x1)>abs(x2)){
            x1 = -x1;
            x2 = -x2;
            swap(x1,x2);
        }

        P ll(x1,y1), lr(x2,y1), ul(x1,y2), ur(x2,y2);
        double ans=0.0;
        if(x1*x2 < 0){ //case 1. on the y-axis
            if(len <= y1){
                ans= 2*len*M_PI;
            }else{
                if(len < abs(ll)){
                    VP ret = crosspointLC(L(ll, lr), C(P(0,0), len));
                    ans += len *angle(P(0,-1), ret[0]);
                }else{
                    ans += len *angle(P(0,-1), ll) + (len-abs(ll)) *angle(ll, P(0,1));
                }
                if(len < abs(lr)){
                    VP ret = crosspointLC(L(ll, lr), C(P(0,0), len));
                    ans += len *angle(P(0,-1), ret[1]);
                }else{
                    ans += len *angle(P(0,-1), lr);
                }
                
                double rad_l = len -abs(ll) -(y2-y1);
                double rad_r = len -abs(lr);
                VP cp = crosspointCC(C(ul, rad_l), C(lr, rad_r));
                if(rad_l>0 && rad_r>0 && (int)cp.size()==2 && cp[0].X > x2){
                    ans += rad_l *angle(P(0,1), cp[0]-ul) + rad_r *angle(lr, cp[0]-lr);
                }else{
                    if(rad_r>0){
                        ans += rad_r *angle(lr, P(0,1));
                    }
                    rad_r -= y2-y1;
                    if(rad_l + rad_r > x2-x1){
                        cp = crosspointCC(C(ul, rad_l), C(ur, rad_r));
                        ans += rad_l *angle(P(0,1), cp[0]-ul) + rad_r *angle(P(0,1), cp[0]-ur);
                    }else{
                        if(rad_l>0){
                            ans += rad_l *M_PI/2;
                            rad_l -= x2-x1;
                            if(rad_l>0){
                                ans += rad_l *M_PI/2;
                            }
                        }
                        if(rad_r>0){
                            ans += rad_r *M_PI/2;
                        }
                    }
                }
            }
        }else{ //case 2. in the first quadrant
            if(len <= abs(ll)){
                ans = 2*len*M_PI;
            }else{
                ans += len *M_PI/2;
                if(len < abs(ul)){
                    VP ret = crosspointLC(L(ll, ul), C(P(0,0), len));
                    ans += len *angle(P(-1,0), ret[1]);
                }else{
                    ans += len *angle(P(-1,0), ul);
                }
                if(len < abs(lr)){
                    VP ret = crosspointLC(L(ll, lr), C(P(0,0), len));
                    ans += len *angle(P(0,-1), ret[1]);
                }else{
                    ans += len *angle(P(0,-1), lr);
                }

                double rad_l = len -abs(ul);
                double rad_r = len -abs(lr);
                if(rad_l + rad_r > (x2-x1)+(y2-y1)){ //implies rad_l>0 and rad_r>0
                    VP cp = crosspointCC(C(ul, rad_l), C(lr, rad_r));
                    if(cp[0].X > x2 && cp[0].Y > y2){
                        ans += rad_l *angle(ul, cp[0]-ul) + rad_r *angle(lr, cp[0]-lr);
                    }else{
                        if(cp[0].X > x2){
                            ans += rad_l *angle(ul, P(1,0));
                            rad_l -= x2-x1;
                            cp = crosspointCC(C(ur, rad_l),C(lr, rad_r));
                            ans += rad_l *angle(P(1,0), cp[0]-ur) + rad_r *angle(lr, cp[0]-lr);
                        }else if(cp[0].Y > y2){
                            ans += rad_r *angle(lr, P(0,1));
                            rad_r -= y2-y1;
                            cp = crosspointCC(C(ul, rad_l),C(ur, rad_r));
                            ans += rad_l *angle(ul, cp[0]-ul) + rad_r *angle(P(0,1), cp[0]-ur);
                        }
                    }
                }else{
                    if(rad_l>0){
                        ans += rad_l *angle(ul, P(1,0));
                        rad_l -= x2-x1;
                        if(rad_l>0){
                            ans += rad_l *M_PI/2;
                        }
                    }         
                    if(rad_r>0){
                        ans += rad_r *angle(lr, P(0,1));
                        rad_r -= y2-y1;
                        if(rad_r>0){
                            ans += rad_r *M_PI/2;
                        }
                    }
                }
            }
                    
        }

        cout << fixed;
        cout << setprecision(8);
        cout << ans << endl;
    }    
    return 0;
}

Measured memory_bytes: 3628