Problem: In the International City of Pipe Construction, it is planned to repair the water pipe at a certain point in the water pipe network. The network consists of water pipe segments, stop valves and source point. A water pipe is represented by a segment on a 2D-plane and intersected pair of water pipe segments are connected at the intersection point. A stop valve, which prevents from water flowing into the repairing point while repairing, is represented by a point on some water pipe segment. In the network, just one source point exists and water is supplied to the network from this point.

Of course, while repairing, we have to stop water supply in some areas, but, in order to reduce the risk of riots, the length of water pipes stopping water supply must be minimized. What you have to do is to write a program to minimize the length of water pipes needed to stop water supply when the coordinates of end points of water pipe segments, stop valves, source point and repairing point are given.



Input

A data set has the following format:

> N M
>  xs1 ys1 xd1 yd1
>  ...
>  xsN ysN xdN ydN
>  xv1 yv1
>  ...
>  xvM yvM
>  xb yb
>  xc yc
>

The first line of the input contains two integers, N (1 ≤ N ≤ 300) and M (0 ≤ M ≤ 1,000) that indicate the number of water pipe segments and stop valves. The following N lines describe the end points of water pipe segments. The i-th line contains four integers, xsi, ysi, xdi and ydi that indicate the pair of coordinates of end points of i-th water pipe segment. The following M lines describe the points of stop valves. The i-th line contains two integers, xvi and yvi that indicate the coordinate of end points of i-th stop valve. The following line contains two integers, xb and yb that indicate the coordinate of the source point. The last line contains two integers, xc and yc that indicate the coordinate of the repairing point.

You may assume that any absolute values of coordinate integers are less than 1,000 (inclusive.) You may also assume each of the stop valves, the source point and the repairing point is always on one of water pipe segments and that that each pair among the stop valves, the source point and the repairing point are different. And, there is not more than one intersection between each pair of water pipe segments. Finally, the water pipe network is connected, that is, all the water pipes are received water supply initially.

Output

Print the minimal length of water pipes needed to stop water supply in a line. The absolute or relative error should be less than or 10-6. When you cannot stop water supply to the repairing point even though you close all stop valves, print "`-1`" in a line.

Examples

Input

1 2
0 0 10 0
1 0
9 0
0 0
5 0


Output

9.0


Input

5 3
0 4 2 4
0 2 2 2
0 0 2 0
0 0 0 4
2 0 2 4
0 2
1 0
2 2
1 4
2 1


Output

3.0


Input

2 1
0 0 0 4
0 2 2 2
1 2
0 1
0 3


Output

-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define bcnt __builtin_popcountll

typedef long double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-12;
const D inf=1e12;
const D PI=acos(-1);

bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return a.Y==b.Y?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};
P crosspoint(L l,L m) {
  D A=cross(l[1]-l[0],m[1]-m[0]);
  D 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) return P(-100000,-100000);
  return m[0]+B/A*(m[1]-m[0]);
}
bool intersectSP(L s,P p){
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0])<eps;
}

int N,M;
P sp,tp;
vector<L> ls;
vector<P> ps;
struct edge{
  int u,v;
  D cost;
};
vector<int> g[100010];
vector<edge> es;
bool vis[2][100010];

bool exist(P p){
  rep(i,ps.size())if(abs(p-ps[i])<eps)return true;
  return false;
}

int main(){
  cin>>N>>M;
  rep(i,N){
    int x0,y0,x1,y1;
    cin>>x0>>y0>>x1>>y1;
    ls.push_back(L(P(x0,y0),P(x1,y1)));
  }
  rep(i,M){
    int x,y;
    cin>>x>>y;
    ps.push_back(P(x,y));
  }
  {
    int x,y;
    cin>>x>>y;
    sp=P(x,y);
    cin>>x>>y;
    tp=P(x,y);
  }

  ps.push_back(sp); ps.push_back(tp);

  rep(i,N){
    if(!exist(ls[i][0]))ps.push_back(ls[i][0]);
    if(!exist(ls[i][1]))ps.push_back(ls[i][1]);
    rep(j,i){
      P cp=crosspoint(ls[i],ls[j]);
      if(cp==P(-100000,-100000))continue;
      D x0=max(min(ls[i][0].X,ls[i][1].X),min(ls[j][0].X,ls[j][1].X));
      D x1=min(max(ls[i][0].X,ls[i][1].X),max(ls[j][0].X,ls[j][1].X));
      D y0=max(min(ls[i][0].Y,ls[i][1].Y),min(ls[j][0].Y,ls[j][1].Y));
      D y1=min(max(ls[i][0].Y,ls[i][1].Y),max(ls[j][0].Y,ls[j][1].Y));
      if(cp.X<x0||cp.X>x1||cp.Y<y0||cp.Y>y1)continue;
      if(!exist(cp))ps.push_back(cp);
    }
  }

  D sum=0;
  rep(i,N){
    vector<int> idxs;
    rep(j,ps.size()){
      if(intersectSP(ls[i],ps[j]))idxs.push_back(j);
    }
    sort(all(idxs),[=](const int& a,const int& b){ return cmp_x(ps[a],ps[b]); });
    rep(j,idxs.size()-1){
      es.push_back((edge){idxs[j],idxs[j+1],abs(ps[idxs[j]]-ps[idxs[j+1]])});
      sum+=abs(ps[idxs[j]]-ps[idxs[j+1]]);
      g[idxs[j]].push_back(idxs[j+1]);
      g[idxs[j+1]].push_back(idxs[j]);
    }
  }

  {
    queue<int> que;
    que.push(M+1); vis[0][M+1]=true;
    while(que.size()){
      int v=que.front(); que.pop();
      if(v<M)continue;
      for(int nv : g[v]){
        if(vis[0][nv])continue;
        vis[0][nv]=true;
        que.push(nv);
      }
    }
  }
  if(vis[0][M]){
    printf("-1\n");
    return 0;
  }

  {
    queue<int> que;
    que.push(M); vis[1][M]=true;
    while(que.size()){
      int v=que.front(); que.pop();
      if(v<M&&vis[0][v])continue;
      for(int nv : g[v]){
        if(vis[1][nv])continue;
        vis[1][nv]=true;
        que.push(nv);
      }
    }
  }

  D res=sum;
  rep(i,es.size()){
    if(vis[1][es[i].u]&&vis[1][es[i].v]){
      res-=es[i].cost;
    }
  }
  printf("%.10Lf\n", res);

  return 0;
}