Rectangles online#5214

Rectangles online

3 seconds
64 megabytes
Medium

Vasya has plotted distinct points on a plane, each with integer coordinates.

He now needs a fast way to determine how many of these points fall within a specified rectangle, where the rectangle's sides are parallel to the coordinate axes.

Input

The first line provides the number of points (1 \le N \le 50000). The next lines list the coordinates of these points as x_i y_i. Following this, a line indicates the number of queries (1 \le M \le 50000). Each of the next lines describes a query in the format x_1, y_1, x_2, y_2 (0 \le x_1 \le x_2 \le 10^9, 0 \le y_1 \le y_2 \le 10^9). For each query, you must:

  • Count the number of points located within the specified rectangle, including those on the boundary.

  • Remove all points that were counted.

Output

For each query, output the number of points counted.

Examples

Example 1

Loading
Loading