Problem: You are given plans of rooms of polygonal shapes. The walls of the rooms on the plans are placed parallel to either x-axis or y-axis. In addition, the walls are made of special materials so they reflect light from sources as mirrors do, but only once. In other words, the walls do not reflect light already reflected at another point of the walls.

Now we have each room furnished with one lamp. Walls will be illuminated by the lamp directly or indirectly. However, since the walls reflect the light only once, some part of the walls may not be illuminated.

You are requested to write a program that calculates the total length of unilluminated part of the walls.

<image>

Figure 10: The room given as the second case in Sample Input



Input

The input consists of multiple test cases.

The first line of each case contains a single positive even integer N (4 ≤ N ≤ 20), which indicates the number of the corners. The following N lines describe the corners counterclockwise. The i-th line contains two integers xi and yi , where (xi , yi ) indicates the coordinates of the i-th corner. The last line of the case contains x' and y' , where (x' , y' ) indicates the coordinates of the lamp.

To make the problem simple, you may assume that the input meets the following conditions:

* All coordinate values are integers not greater than 100 in their absolute values.
* No two walls intersect or touch except for their ends.
* The walls do not intersect nor touch each other.
* The walls turn each corner by a right angle.
* The lamp exists strictly inside the room off the wall.
* The x-coordinate of the lamp does not coincide with that of any wall; neither does the y-coordinate.



The input is terminated by a line containing a single zero.

Output

For each case, output the length of the unilluminated part in one line. The output value may have an arbitrary number of decimal digits, but may not contain an error greater than 10-3 .

Example

Input

4
0 0
2 0
2 2
0 2
1 1
6
2 2
2 5
0 5
0 0
5 0
5 2
1 4
0


Output

0.000
3.000

Solution (in CPP):

Solution:
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-6;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}

bool intersectLS(const L& l, const L& s){
    return cross(l[1]-l[0], s[0]-l[0])*
        cross(l[1]-l[0], s[1]-l[0]) < EPS;
}
bool intersectSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) <= 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) <= 0 );
}
bool strictItsSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) < 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) < 0 );
}

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 + 2.0*(projection(l, p) -p);
}

bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}
P crosspointLL(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]);
  return m[0] + B/A *(m[1]-m[0]);
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

        VP p(n);
        for(int i=0; i<n; i++){
            int x,y;
            cin >> x >> y;
            p[i] = P(x, y);
        }
        int sx,sy;
        cin >> sx >> sy;
        P source(sx, sy);

        vector<L> edge(n);
        vector<VP> cp(n);
        for(int i=0; i<n; i++){
            edge[i] = L(p[i], p[(i+1)%n]);
            cp[i].push_back(edge[i][0]);
            cp[i].push_back(edge[i][1]);
        }

        for(int v=0; v<n; v++){
            L ray(source, p[v]);
            for(int wr=0; wr<n; wr++){
                if(!isParallel(ray, edge[wr]) && intersectLS(ray, edge[wr])){
                    P cpll = crosspointLL(ray, edge[wr]);
                    //直接頂点を通る
                    cp[wr].push_back(cpll);
                    //その後反射する
                    P ref = reflection(edge[wr], source);
                    L ray2(ref, cpll);
                    for(int wt=0; wt<n; wt++){
                        if(!isParallel(ray2, edge[wt]) && intersectLS(ray2, edge[wt])){
                            cp[wt].push_back(crosspointLL(ray2, edge[wt]));
                        }
                    }
                }
            }

            //反射して頂点を通る
            for(int wr=0; wr<n; wr++){
                P s = reflection(edge[wr], source);
                L ray(s, p[v]);
                for(int wt=0; wt<n; wt++){
                    if(!isParallel(ray, edge[wt]) && intersectLS(ray, edge[wt])){
                        cp[wt].push_back(crosspointLL(ray, edge[wt]));
                    }
                }
            }
        }
        for(int i=0; i<n; i++){
            sort(cp[i].begin(), cp[i].end());
            cp[i].erase(unique(cp[i].begin(), cp[i].end()), cp[i].end());
        }

        double ans = 0;
        for(int i=0; i<n; i++){
            for(int j=0; j<(int)cp[i].size()-1; j++){
                P mid = (cp[i][j] +cp[i][j+1]) /2.0;
                bool light = false;
                //反射する壁を選ぶ
                for(int wr=0; wr<n; wr++){
                    P ref = reflection(edge[wr], mid);
                    if(!intersectSS(L(ref, source), edge[wr])) continue;
                    P rp;
                    if(isParallel(L(ref, source), edge[wr])){
                        rp = (ref +source) /2.0;
                    }else{
                        rp = crosspointLL(L(ref, source), edge[wr]);
                    }
                    vector<L> ray{L(mid, rp), L(rp, source)};

                    bool block = false;
                    for(int k=0; k<2; k++){
                        for(int w=0; w<n; w++){
                            if(!isParallel(ray[k], edge[w]) && strictItsSS(ray[k], edge[w])){
                                block = true;
                                k = 2;
                                break;
                            }
                        }
                    }
                    if(!block){
                        light = true;
                        break;
                    }
                }
                if(!light){
                    ans += abs(cp[i][j+1] -cp[i][j]);
                }
            }
        }

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