#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    // if (abs(a-b)<EPS) return 0;
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L() {}
};
ostream &operator<<(ostream &os, const L &a) {
  os << a[0] << " -> " << a[1];
  return os;
}

typedef vector<P> G;
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > EPS)   return +1;       // counter clockwise
  if (cross(b, c) < -EPS)   return -1;       // clockwise
  if (dot(b, c) < -EPS)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

P rotate(const P &p, double ang) {
  return p * P(cos(ang), sin(ang));
}

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]);
}
P reflection(const L &l, const P &p) {
  return p + P(2,0) * (projection(l, p) - p);
}

double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}

bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSS2(const L &s, const L &t) {
  if (intersectSP(s,t[0]) || intersectSP(s,t[1]) ||
      intersectSP(t,s[0]) || intersectSP(t,s[1])) return 0;
  return intersectSS(s,t);
}
bool intersectHS(const L &h, const L &s) {
  if (intersectLP(h,s[0]) || intersectLP(h,s[1]) ||
      intersectLP(s,h[0]) || intersectLP(s,h[1])) return 0;
  if (intersectSS(h,s)) return 1;
  if (!intersectLS(h,s)) return 0;
  return (ccw(s[0],s[1],h[0]) == 1) ^ (cross(s[1]-s[0], h[1]-h[0]) > 0);
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

int n;
L pl[20];
vector<P> v[20];

void func(const L &h) {
  double mi = INF;
  int cl_id = -1;
  REP(k,n) {
    if (intersectHS(h,pl[k])) {
      if (chmin(mi,norm(crosspoint(h,pl[k])-h[0]))) {
        cl_id = k;
      }
    }
  }
  if (cl_id != -1) {
    v[cl_id].push_back(crosspoint(h,pl[cl_id]));
  }
}

P c;

bool isVisible(const P &p) {
  // direct
  L l(c,p);
  bool ok = 1;
  REP(i,n) {
    ok &= !intersectSS2(l,pl[i]);
  }
  if (ok) return 1;
  // reflect
  REP(j,n) {                
    if (ccw(pl[j][0], pl[j][1], c) * ccw(pl[j][0], pl[j][1], p) != 1) continue;
    double d1 = distanceLP(pl[j],c);
    double d2 = distanceLP(pl[j],p);
    P refp = P(d2/(d1+d2),0) * projection(pl[j],c) + P(d1/(d1+d2),0) * projection(pl[j],p);
    if (!intersectSP(pl[j], refp)) continue;
    bool ok = 1;
    L l1(c,refp);
    L l2(refp,p);
    REP(k,n) {
      ok &= !intersectSS2(l1,pl[k]);
      ok &= !intersectSS2(l2,pl[k]);
    }
    if (ok) return 1;
  }
  return 0;
}

int main() {
  while(cin >> n, n) {
    P p[20];
    REP(i,n) {
      cin >> p[i].real() >> p[i].imag();
    }
    REP(i,n) {
      pl[i] = L(p[i],p[(i+1)%n]);      
    }
    cin >> c.real() >> c.imag();
    REP(i,n) v[i].clear();
    
    REP(i,n) {
      bool ok = 1;
      L l1 = L(c,p[i]);
      REP(k,n) ok &= !intersectSS2(l1,pl[k]);
      if (ok) {
        // c -> p[i]
        func(l1); 
        // c -> p[i] -> reflection
        int ref_id = -1;
        double mi = INF;
        REP(j,n) {
          if (intersectHS(l1,pl[j])) {
            if (chmin(mi, norm(crosspoint(l1,pl[j])-c))) {
              ref_id = j;
            }
          }
        }
        if (ref_id != -1) {
          // reflect at pl[ref_id]
          P refp = crosspoint(l1,pl[ref_id]);
          P v = refp - reflection(pl[ref_id],c);
          func(L(refp, refp+v));
        }
      }
      // c -> pl[j] -> p[i]
      REP(j,n) {                
        if (ccw(pl[j][0], pl[j][1], c) * ccw(pl[j][0], pl[j][1], p[i]) != 1) continue;
        double d1 = distanceLP(pl[j],c);
        double d2 = distanceLP(pl[j],p[i]);
        P refp = P(d2/(d1+d2),0) * projection(pl[j],c) + P(d1/(d1+d2),0) * projection(pl[j],p[i]);
        if (!intersectSP(pl[j], refp)) continue;
        bool ok = 1;
        L l1(c,refp);
        L l2(refp,p[i]);
        REP(k,n) {
          ok &= !intersectSS2(l1,pl[k]);
        }
        if (!ok) continue;

        func(l2);
      }
      // reflect at corners of pl[i]
      {
        P refp = pl[i][0];
        L l1(c,refp);
        bool ok = 1;        
        REP(k,n) ok &= !intersectSS2(l1,pl[k]);
        if (ok) {
          L l2 = L(refp, refp + refp-reflection(pl[i], c));          
          func(l2);
        }
      }
      {
        P refp = pl[i][1];
        L l1(c,refp);
        bool ok = 1;        
        REP(k,n) ok &= !intersectSS2(l1,pl[k]);
        if (ok) {
          L l2 = L(refp, refp + refp-reflection(pl[i], c));
          func(l2);
        }        
      }
    }
    double ans = 0;
    REP(i,n) {
      // cout << i << endl;
      // FOR(it, v[i]) {
      //   cout << *it << endl;
      // }
      double len = abs(pl[i][1]-pl[i][0]);
      vector<double> vv;
      vv.push_back(0);
      vv.push_back(len);
      FOR(it, v[i]) {
        vv.push_back(abs(*it - pl[i][0]));
      }
      sort(ALL(vv));
      REP(j,vv.size()-1) {
        double s = (vv[j]+vv[j+1])/2 / len;
        P q = (1-s)*pl[i][0] + s*pl[i][1];
        if (!isVisible(q)) {
          ans += vv[j+1]-vv[j];

          double ss = vv[j]/len, tt = vv[j+1]/len;
          P p1 = (1-ss)*pl[i][0] + ss*pl[i][1];
          P p2 = (1-tt)*pl[i][0] + tt*pl[i][1];
          // cout << p1.real() << " " << p1.imag() << endl;
          // cout << p2.real() << " " << p2.imag() << endl;
          // cout << endl;
        }
      }
    }
    printf("%.10f\n", ans);
  }
}

Measured memory_bytes: 1300