#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e16
#define eps (1e-10)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ 
    return equals(x,p.x) ? y-p.y<-eps : x-p.x<-eps; }
  bool operator==(Point p)const{ 
    return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

class Arc{
public:
  Circle c;
  Vector v1,v2;
  Arc(Circle c,Vector v1,Vector v2):c(c),v1(v1),v2(v2){}
};

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return 1;
  if(cross(a,b)<-eps)return -1;
  if(dot(a,b)<-eps)return 2;
  if(a.norm()<b.norm())return -2;
  return 0;
}

int intersect(Circle a,Circle b){
  double d=abs(a.c-b.c);
  if(a.r<b.r)swap(a,b);
  if(a.r+b.r+eps<=d)return 2;
  if(a.r+b.r-eps<=d)return 1;
  if(a.r-b.r+eps<=d)return 0;
  if(a.r-b.r-eps<=d)return -1;
  return -2;
}

double arg(Vector p){ return atan2(p.y,p.x);}
Vector polar(double a,double r){ return Point(cos(r)*a,sin(r)*a);}

pair<Point,Point> getCrossPoints(Circle c1,Circle c2){
  double d=abs(c1.c-c2.c);
  double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
  double t=arg(c2.c-c1.c);
  return mp(c1.c+polar(c1.r,t+a),c1.c+polar(c1.r,t-a));
}

double getAngle(Vector a,Vector b){
  double tmp=dot(a,b)/(abs(a)*abs(b));
  if(tmp<=-1.0)tmp=-1.0;
  if(1.0<=tmp)tmp=1.0;
  double r=acos(tmp)*180.0/pi;
  if(cross(a,b)<0.0)r=360.0-r;
  return r;
}

double arc(Arc a){ return 2.0*pi*a.c.r*getAngle(a.v1,a.v2)/360.0; }
bool in(Circle c,Point p){ return abs(c.c-p)-c.r<eps; }
bool on(Arc a,Point p){ return getAngle(a.v1,p-a.c.c)-getAngle(a.v1,a.v2)<-eps; }

void rotate90(Point &p){ swap(p.x,p.y); p.y*=-1; }

double r;
Point a,b,c,d;

double solve(){
  double res=r*pi;
  Circle C(Point(0,0),r);
  vector<Arc> v1,v2;
  while(a.y<eps || d.y<eps){
    rotate90(a);rotate90(d);
    b.x=min(a.x,d.x);b.y=min(a.y,d.y);
    c.x=max(a.x,d.x);c.y=max(a.y,d.y);
    a=b;d=c;
  }
  b=Point(d.x,a.y);c=Point(a.x,d.y);

  if(r<=a.y)return 2*pi*r;
  if(!in(C,a) && -eps<=a.x)return 2*pi*r;
  if(!in(C,b) && b.x<eps)return 2*pi*r;

  if(!in(C,a))v1.pb(Arc(C,Vector(-sqrt(r*r-a.y*a.y),a.y),Vector(-1,0)));
  else if(a.x<-eps){
    v1.pb(Arc(C,a,Vector(-1,0)));
    v1.pb(Arc(Circle(a,r-abs(a)),Vector(0,1),a));
    double r1=abs(a)+(c.y-a.y);
    double r2=r1+(d.x-c.x);
    if(r1-r<-eps)v1.pb(Arc(Circle(c,abs(r-r1)),Vector(1,0),Vector(0,1)));
    if(r2-r<-eps)v1.pb(Arc(Circle(d,abs(r-r2)),Vector(0,-1),Vector(1,0)));
  }
  else if(in(C,c)){
    v1.pb(Arc(C,c,Vector(-1,0)));
    v1.pb(Arc(Circle(c,r-abs(c)),Vector(1,0),c));
    double r1=abs(c)+(d.x-c.x);
    if(r1-r<-eps)v1.pb(Arc(Circle(d,abs(r-r1)),Vector(0,-1),Vector(1,0)));
  }
  else v1.pb(Arc(C,Vector(a.x,sqrt(r*r-a.x*a.x)),Vector(-1,0)));

  if(!in(C,b))v2.pb(Arc(C,Vector(1,0),Vector(sqrt(r*r-b.y*b.y),b.y)));
  else if(eps<b.x){
    v2.pb(Arc(C,Vector(1,0),b));
    v2.pb(Arc(Circle(b,r-abs(b)),b,Vector(0,1)));
    double r1=abs(b)+(d.y-b.y);
    double r2=r1+(d.x-c.x);
    if(r1-r<-eps)v2.pb(Arc(Circle(d,abs(r-r1)),Vector(0,1),Vector(-1,0)));
    if(r2-r<-eps)v2.pb(Arc(Circle(d,abs(r-r2)),Vector(-1,0),Vector(0,-1)));
  }
  else if(in(C,d)){
    v2.pb(Arc(C,Vector(1,0),d));
    v2.pb(Arc(Circle(d,r-abs(d)),d,Vector(-1,0)));
    double r1=abs(d)+(d.x-c.x);
    if(r1-r<-eps)v2.pb(Arc(Circle(c,abs(r-r1)),Vector(-1,0),Vector(0,-1)));
  }
  else v2.pb(Arc(C,Vector(1,0),Vector(b.x,sqrt(r*r-b.x*b.x))));

  FOR(i,0,v1.size()){
    double sum=0;
    RFOR(j,v2.size(),0){
      if(abs(intersect(v1[i].c,v2[j].c))>=2)continue;
      pair<Point,Point> pp=getCrossPoints(v1[i].c,v2[j].c);
      if(on(v1[i],pp.f) && on(v2[j],pp.f)){
        sum=arc(Arc(v1[i].c,pp.f-v1[i].c.c,v1[i].v2));
        break;
      }
      if(on(v1[i],pp.s) && on(v2[j],pp.s)){
        sum=arc(Arc(v1[i].c,pp.s-v1[i].c.c,v1[i].v2));
        break;
      }
    }
    if(sum==0)res+=arc(v1[i]);
    else { res+=sum; break;}
  }

  FOR(i,0,v2.size()){
    double sum=0;
    RFOR(j,v1.size(),0){
      if(abs(intersect(v2[i].c,v1[j].c))>=2)continue;
      pair<Point,Point> pp=getCrossPoints(v2[i].c,v1[j].c);
      if(on(v2[i],pp.f) && on(v1[j],pp.f)){
        sum=arc(Arc(v2[i].c,v2[i].v1,pp.f-v2[i].c.c));
        break;
      }
      if(on(v2[i],pp.s) && on(v1[j],pp.s)){
        sum=arc(Arc(v2[i].c,v2[i].v1,pp.s-v2[i].c.c));
        break;
      }
    }
    if(sum==0)res+=arc(v2[i]);
    else { res+=sum; break;}
  }

  return res;
}

int main()
{
  while(1){
    cin>>r>>a.x>>a.y>>d.x>>d.y;
    if(r==0)break;
    pd(solve());
  }
  return 0;
}

Measured memory_bytes: 3644