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 <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

constexpr double EPS = 1e-9;

struct point {
	double x, y;
	explicit point(double x_ = 0.0, double y_ = 0.0):x(x_), y(y_) {}
	point(const point &p):x(p.x), y(p.y) {}

	point operator+(const point &p) const {
		return point(x + p.x, y + p.y);
	}

	point operator-(const point &p) const {
		return point(x - p.x, y - p.y);
	}

	point operator*(double s) const {
		return point(x * s, y * s);
	}

	bool operator<(const point &p) const {
		return x + EPS < p.x || (abs(x - p.x) < EPS && y + EPS < p.y);
	}

	bool operator==(const point &p) const {
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
};

double norm(const point &p) {
	return p.x * p.x + p.y * p.y;
}

double abs(const point &p) {
	return sqrt(norm(p));
}

double dot(const point &a, const point &b) {
	return a.x * b.x + a.y * b.y;
}

double cross(const point &a, const point &b) {
	return a.x * b.y - a.y * b.x;
}

struct segment {
	point a, b;
	segment(const point &a_, const point &b_):a(a_), b(b_){}
};

int ccw(const point &a, point b, point c) {
	b = b - a;
	c = c - a;
	const double tmp = cross(b, c);
	if(tmp > EPS) return 1; // ccw
	if(tmp < -EPS) return -1; // cw
	if(dot(b, c) < 0) return 2; // c, a, b 順に一直線上
	if(norm(b) < norm(c)) return -2; // a, b, c 順に一直線上
	return 0; //a, c, b 順で一直線上
}

bool intersect(const segment &s, const segment &t) {
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0
		&& ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}


bool intersect(const segment &s, const point &p) {
	return ccw(s.a, s.b, p) == 0;
}

// 先にintersectで交差判定をすること
point crosspoint(const segment &s, const segment &t) {
	const double tmp = cross(s.b - s.a, t.b - t.a);
	if(abs(tmp) < EPS) { // 一直線上
		if(intersect(s, t.a)) return t.a;
		if(intersect(s, t.b)) return t.b;
		if(intersect(t, s.a)) return s.a;
		return s.b;
	}
	return t.a + (t.b - t.a) * (cross(s.b - s.a, s.b - t.a) / tmp);
}

struct edge {
	int to;
	double cost;
	edge(int to_, double cost_):to(to_), cost(cost_) {}
};

void merge(vector<segment> &segments) {
    for(int i = 0; i < static_cast<int>(segments.size());) {
        const auto &s1 = segments[i];
        bool ok = true;
        for(int j = i + 1; j < static_cast<int>(segments.size()); ++j) {
            const auto &s2 = segments[j];
 
            if(intersect(s1, s2) && abs(cross(s1.a - s1.b, s2.a - s2.b)) < EPS) {
				const auto a = min({s1.a, s1.b, s2.a, s2.b});
				const auto b = max({s1.a, s1.b, s2.a, s2.b});
                segments.emplace_back(a, b);
 
                segments.erase(segments.begin() + j);
                segments.erase(segments.begin() + i);
                ok = false;
                break;
            }
        }
        if(ok) ++i;
    }
}

vector<vector<edge>> arrangement(vector<segment> &segments, vector<point> &points) {
	merge(segments);
	const int n = segments.size();

	for(int i = 0; i < n; ++i) {
		const auto &s1 = segments[i];
		points.emplace_back(s1.a);
		points.emplace_back(s1.b);

		for(int j = i + 1; j < n; ++j) {
			const auto &s2 = segments[j];
			if(intersect(s1, s2)) {
				points.emplace_back(crosspoint(s1, s2));
			}
		}
	}

	sort(points.begin(), points.end());
	points.erase(unique(points.begin(), points.end()), points.end());

	const int V = points.size();
	vector<vector<edge>> G(V);

	for(const auto &s : segments) {
		vector<pair<double, int>> vs;
		for(int i = 0; i < V; ++i) {
			if(intersect(s, points[i])) {
				vs.emplace_back(abs(s.a - points[i]), i);
			}
		}

		sort(vs.begin(), vs.end());
		for(int i = 1; i < static_cast<int>(vs.size()); ++i) {
			const int v = vs[i].second;
			const int u = vs[i - 1].second;
			const double d = vs[i].first - vs[i - 1].first;
			G[v].emplace_back(u, d);
			G[u].emplace_back(v, d);
		}
	}

	return G;
}

inline int get_index(const point &p, const vector<point> &points) {
	return lower_bound(begin(points), end(points), p) - begin(points);
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);

	int n, m;
	cin >> n >> m;

	vector<segment> segments;
	segments.reserve(n);

	for(int i = 0; i < n; ++i) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		segments.emplace_back(point(x1, y1), point(x2, y2));
	}

	vector<point> stop;
	stop.reserve(m + 2);

	for(int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		stop.emplace_back(x, y);
	}

	point source, repair;
	cin >> source.x >> source.y;
	cin >> repair.x >> repair.y;

	vector<point> points(stop);
	points.emplace_back(source);
	points.emplace_back(repair);

	const auto G = arrangement(segments, points);
	const int V = G.size();

	vector<bool> is_stop(V, false);
	for(const auto &p : stop) {
		is_stop[get_index(p, points)] = true;
	}

	vector<bool> visited(V, false);
	queue<int> que;

	const int s = get_index(source, points);
	const int r = get_index(repair, points);
	visited[r] = true;
	que.push(r);

	while(!que.empty()) {
		const int v = que.front();
		que.pop();

		if(v == s) {
			cout << "-1" << endl;
			return EXIT_SUCCESS;
		}

		for(const auto &e : G[v]) {
			if(!visited[e.to] && !is_stop[e.to]) {
				visited[e.to] = true;
				que.push(e.to);
			}
		}
	}

	double ans = 0.0;
	for(const auto &seg : segments) ans += abs(seg.a - seg.b);
	
	vector<bool> used(V, false);
	used[s] = true;
	que.push(s);

	while(!que.empty()) {
		const int v = que.front();
		que.pop();

		if(visited[v]) continue;

		for(const auto &e : G[v]) {
			if(visited[e.to]) continue;

			ans -= e.cost * 0.5;
			
			if(!used[e.to]) {
				used[e.to] = true;
				que.push(e.to);
			}
		}
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}