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>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1<<30
#define MAX 200010
#define eps (1e-6)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

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 (x!=p.x ? x<p.x : y<p.y);}
  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;

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);}

bool isParallel(Segment s,Segment t){
    return equals(cross(s.p1-s.p2,t.p1-t.p2),0.0);
}

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;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 &&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPointLL(Line a,Line b){
  double A=cross(a.p2-a.p1,b.p2-b.p1);
  double B=cross(a.p2-a.p1,a.p2-b.p1);
  if(abs(A)<eps || abs(B)<eps)return b.p1;
  return b.p1+(b.p2-b.p1)*(B/A);
}

bool merge_if_able(Segment &s,Segment t) {
  if(!isParallel(s,t))return false;
  if(ccw(s.p1,t.p1,s.p2)==1 ||
     ccw(s.p1,t.p1,s.p2)==-1)return false;
  if(ccw(s.p1,s.p2,t.p1)==-2 ||
     ccw(t.p1,t.p2,s.p1)==-2)return false;
  s=Segment(min(s.p1,t.p1),max(s.p2,t.p2));
  return true;
}

void merge(vector<Segment>& v) {
  for(int i=0;i<v.size();i++){
    if(v[i].p2<v[i].p1)swap(v[i].p2,v[i].p1);
  }
  for(int i=0;i<v.size();i++)
    for(int j=i+1;j<v.size();j++)
      if(merge_if_able(v[i],v[j]))
        v[j--]=v.back(),v.pop_back();
}

typedef vector<vector<pair<int,double> > > Graph;

Graph SegmentArrangement(vector<Segment> v,vector<Point> &ps){
  for(int i=0;i<v.size();i++){
    ps.push_back(v[i].p1);
    ps.push_back(v[i].p2);
    for(int j=i+1;j<v.size();j++){
      if(intersect(v[i],v[j]))ps.push_back(getCrossPointLL(v[i],v[j]));
    }
  }
  sort(ps.begin(),ps.end());
  ps.erase(unique(ps.begin(),ps.end()),ps.end());
  Graph g(ps.size());
  for(int i=0;i<v.size();i++){
    vector<pair<double,int> > list;
    for(int j=0;j<ps.size();j++)
      if(ccw(v[i].p1,v[i].p2,ps[j])==0)
        list.push_back(mp(norm(v[i].p1-ps[j]),j));
    sort(list.begin(),list.end());
    for(int j=0;j<list.size()-1;j++){
      int a=list[j].s,b=list[j+1].s;
      g[a].push_back(mp(b,abs(ps[b]-ps[a])));
      g[b].push_back(mp(a,abs(ps[a]-ps[b])));
    }
  }
  return g;
}

int n,m;
vector<Segment> vs;
vector<Point> vp;
set<Point> st;
Point s,t;
int c,d;
Graph g;
bool checked[MAX]={};
bool visited[MAX]={};
bool valve[MAX]={};

void dfs(int v){ 
  checked[v]=true;
  if(valve[v])return;
  for(int i=0;i<g[v].size();i++){
    pair<int,double> next=g[v][i];
    if(!checked[next.f]){
      dfs(next.f);
    }
  }
  return;
}

double bfs(int v){
  double res=0.0;
  queue<int> q;
  q.push(v);
  while(q.size()){
    int u=q.front();
    q.pop();
    if(visited[u])continue;
    visited[u]=true;
    for(int i=0;i<g[u].size();i++){
      pair<int,double> next=g[u][i];
      if(checked[next.f])res+=next.s;
      else if(!visited[next.f]){
        res+=next.s;
        q.push(next.f);
      }
    }
  }
  return res;
}

int main()
{
  cin>>n>>m;
  for(int i=0;i<n;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    vs.push_back(Segment(Point(a,b),Point(c,d)));
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    vp.push_back(Point(a,b));
    st.insert(Point(a,b));
  }
  cin>>s.x>>s.y>>t.x>>t.y;
  vp.push_back(s);
  vp.push_back(t);
  //merge(vs);
  g=SegmentArrangement(vs,vp);
  for(int i=0;i<vp.size();i++){
    if(st.find(vp[i])!=st.end())valve[i]=true;
    if(vp[i]==s)c=i;
    if(vp[i]==t)d=i;
  }
  dfs(d);
  if(checked[c])cout<<-1<<endl;
  else {
    double ans=0.0;
    for(int i=0;i<g.size();i++){
      for(int j=0;j<g[i].size();j++)ans+=g[i][j].s/2.0;
    }
    ans-=bfs(c);
    printf("%.10f\n",ans);
  }
  return 0;
}