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<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int n, m, np, l, idx[100011], cl, q[100011], v, s, t;
double ans, eps = 1e-10;
bool f[100011], isstop[100011], mark[100011], flag;
struct recedge
{
	int y, nxt;
} edge[2000011];
void build(int x, int y)
{
	edge[++l].y = y;
	edge[l].nxt = idx[x];
	idx[x] = l;
}
struct couple
{
	double x, y;
	couple(){};
	couple(const double & _a, const double & _b) : x(_a), y(_b){}
	double len()
	{
		return sqrt(x * x + y * y);
	}
} b[1111], cp, points[100011];
bool equal(const double  & a, const double & b)
{
	return fabs(a - b) < eps;
}
bool les(const double & a, const double & b)
{
	return a + eps < b;
}
bool operator < (const couple & a, const couple & b)
{
	return les(a.x, b.x) or equal(a.x, b.x) and les(a.y, b.y);
}
bool operator == (const couple & a, const couple & b)
{
	return equal(a.x, b.x) and equal(a.y, b.y);
}
map<couple, int> mp;
vector<couple> vec[311];
couple operator - (const couple & a, const couple & b)
{
	return couple(a.x - b.x, a.y - b.y);
}
couple operator + (const couple & a, const couple & b)
{
		return couple(a.x + b.x, a.y + b.y);
}

couple operator * (const double & lambda, const couple & a)
{
	return couple(lambda * a.x, lambda * a.y);
}
double operator * (const couple & a, const couple & b)
{
	return a.x * b.y - a.y * b.x;
}
double operator % (const couple & a, const couple & b)
{
	return a.x * b.x + a.y * b.y;
}
struct reca
{
	couple a, b;
} a[311];
bool cross(int i, int j)
{
	if((a[i].b - a[i].a) * (a[j].b - a[j].a) == 0)
	{
		if(a[i].b == a[j].a or a[i].b == a[j].b)
		{
			cp = a[i].b;
			return true;
		}else if(a[i].a == a[j].a  or a[i].a == a[j].b)
		{
			cp = a[i].a;
			return true;
		}
		return false;
	}else if(((a[j].a - a[i].a) * (a[i].b - a[i].a)) * ((a[j].b - a[i].a) * (a[i].b - a[i].a)) <= 0 and ((a[i].a - a[j].a) * (a[j].b - a[j].a))*((a[i].b - a[j].a) * (a[j].b - a[j].a)) <= 0)
	{
		double lambda = (a[j].a - a[i].a) * (a[j].b - a[j].a) / ((a[i].b - a[i].a) * (a[j].b - a[j].a));
		cp = a[i].a + lambda * (a[i].b - a[i].a);
		return true;
	}else return false;
}
bool on(int i, int j)
{
	return (a[j].a - b[i]) * (a[j].b - b[i]) == 0 and (a[j].a - b[i]) % (a[j].b - b[i]) <= 0;
}
double dis(int i, int j)
{
	return sqrt((points[i].x - points[j].x) * (points[i].x - points[j].x) + (points[i].y - points[j].y) * (points[i].y - points[j].y));
}
int main()
{
	scanf("%d%d", &n, &m);
	ans = 0;
	for(int i = 1; i <= n; i++)
	{
		scanf("%lf%lf%lf%lf", &a[i].a.x, &a[i].a.y, &a[i].b.x, &a[i].b.y);
		if(a[i].a.x == a[i].b.x and a[i].a.y == a[i].b.y)
		{
			f[i] = false;
		}else f[i] = true;
		ans = ans + (a[i].b - a[i].a).len();
	}
	int n1 = 0;
	for(int i = 1; i <= n; i++) if(f[i]) a[++n1] = a[i];
	n = n1;
	for(int i = 1; i <= m + 2; i++)
	{
		scanf("%lf%lf", &b[i].x, &b[i].y);
	}
	for(int i = 1; i <= n; i++)
	{
		vec[i].clear();
		vec[i].push_back(a[i].a);
		vec[i].push_back(a[i].b);
		mp[a[i].a] = 0;
		mp[a[i].b] = 0;
	}
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			if(cross(i, j))
			{
				vec[i].push_back(cp);
				vec[j].push_back(cp);
				mp[cp] = 0;
			}
	for(int i = 1; i <= m + 2; i++)
		for(int j = 1; j <= n; j++)
			if(on(i, j))
			{
				vec[j].push_back(b[i]);
				mp[b[i]] = 0;
			}
	np = 0;
	for(map<couple, int>::iterator it = mp.begin(); it != mp.end(); it++) 
	{
		it->second = ++np;
		points[np] = it->first;
	}
	l = 1;
	memset(idx, 0, sizeof(idx));
	for(int i = 1; i <= n; i++)
	{
		sort(vec[i].begin(), vec[i].end());
		vec[i].resize(unique(vec[i].begin(), vec[i].end()) - vec[i].begin());
		for(int j = 0; j < vec[i].size() - 1; j++)
		{
			build(mp[vec[i][j]], mp[vec[i][j + 1]]);
			build(mp[vec[i][j + 1]], mp[vec[i][j]]);
		}
		//for(int j = 0; j < vec[i].size(); j++) printf("%d ", mp[vec[i][j]]);
		//printf("\n");
	}
	memset(isstop, 0, sizeof(isstop));
	memset(mark, 0, sizeof(mark));
	memset(f, true, sizeof(f));
	s = mp[b[m + 1]];
	t = mp[b[m + 2]];
	for(int i = 1; i <= m; i++) isstop[mp[b[i]]] = true;
	q[cl = 1] = t;
	flag = true;
	f[t] = false;
	for(int op = 1; op <= cl; op++)
	{
		//printf("%d\n", q[op]);
		for(int p = idx[v = q[op]]; p; p = edge[p].nxt) if(f[edge[p].y] == true)
		{
			if(edge[p].y == s)
			{
				flag = false;
				break;
			}else
			{
				if(isstop[edge[p].y] == true)
				{
					mark[edge[p].y] = true;
					//printf("mark %d\n", edge[p].y);
				}else
				{
					q[++cl] = edge[p].y;
					f[edge[p].y] = false;
				}
			}
		}
		if(flag == false) break;
	}
	if(flag == false)
	{
		printf("-1\n");
		return 0;
	}
	q[cl = 1] = s;
	memset(f, true, sizeof(f));
	f[s] = false;
	for(int op = 1; op <= cl; op++)
	{
		for(int p = idx[v = q[op]]; p; p = edge[p].nxt)
		{
			ans -= dis(v, edge[p].y) / 2;
			if(mark[edge[p].y] == true)
				ans -= dis(v, edge[p].y) / 2;
			else if(f[edge[p].y])
			{
				f[edge[p].y] = false;
				q[++cl] = edge[p].y;
			}
		}
	}
	printf("%.10f\n", ans);
	fclose(stdin);
	return 0;
}