#P17190. [ICPC 2017 Hong Kong R] Triangle

[ICPC 2017 Hong Kong R] Triangle

Problem Description

Bob draws NN black points and NN white points in the plane, and draws directed edges between each pair of them. For each pair of points pp and qq, Bob can draw an edge according to the following rules.

  • If these two points share the same color, put an edge pqp \to q or qpq \to p optionally.
  • If they have different colors, suppose that pp is white and qq is black, then draw the edge pqp \to q if dist(p,q)>D\text{dist}(p, q) > D, or qpq \to p if not.

The distance function is defined as dist(p,q)=p.xq.x+p.yq.y\text{dist}(p, q) = |p.x - q.x| + |p.y - q.y|.

Bob thinks that a beautiful triangle of points pp, qq and rr (which is a triple of three points) should satisfy the following conditions:

  • At least one of them is black, and at least one of them is white.
  • pqp \to q, qrq \to r, and rpr \to p are all the edges between them.

Now Bob wants to know the minimum number and the maximum number of beautiful triangles could exist.

Input Format

The input contains several test cases, please handle it to the end of file.

For each test case, the first line contains two integers NN (N100000N \le 100000) and DD. In the next NN lines, each line contains two integers indicating the coordinate of a white point. In the next NN lines, each line contains two integers indicating the coordinate of a black point. Some points may share the same coordinate.

All numbers in input are non-negative integers and less than 2312^{31}.

Output Format

For each test case, output two integers indicating the minimum number and the maximum number of beautiful triangles.

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