This page is still under construction.

Parts of this page are still being built. What you see may change.

Sinchon Defense Headquarters

Time limit1.5sMemory limit1024 MB

Summary
Given N missile points, count the lattice points that lie in the convex hull of the missiles (including boundary) but are not shield locations.
Level

Hard9 of 10

Topics
Geometry, Math, Sorting, Implementation
Solved
No attempts yet

Problem

In a peaceful forest near Sinchon, one tree is planted at every lattice point, as in the picture below. The organizers liked this forest, so they decided to gather people here and hold the ICPC Sinchon Camp.

So on August 21, 2021, the ICPC Sinchon Camp Contest was held in the forest, breathing the fresh air. Just as the contest was about to proceed peacefully, an unidentified organization suddenly began attacking the forest. Missiles are falling on NN distinct locations in the Sinchon forest. To minimize the damage from the missiles, the ICPC Sinchon organizers installed MM shields on trees throughout the forest.

The trees with shields installed were unharmed, but due to interactions between the missiles, several trees without shields were burning, as in the picture. Let the coordinates of a tree without a shield be (a,b)(a,b), and let the coordinates of the point where the ii-th missile fell be (xi,yi)(x_i, y_i). If there exist c1,…,cNc_1, \dots, c_N satisfying the following conditions, that tree burns.

  • a=∑i=1Ncixi\displaystyle a=\sum_{i=1}^N c_i x_i
  • b=∑i=1Nciyi\displaystyle b=\sum_{i=1}^N c_i y_i
  • ∑i=1Nci=1\displaystyle \sum_{i=1}^N c_i = 1
  • 0≤ci≤10 \le c_i \le 1 (1≤i≤N1 \le i \le N)

The organizers are going to mobilize firefighting helicopters to quickly extinguish the fire and rescue the people. However, if too much water is loaded onto a firefighting helicopter, its movement speed becomes slow, so they will load an appropriate amount of water to extinguish the fire. To find the appropriate amount of water, the number of burning trees must be computed exactly. Given the coordinates of the points where the missiles fell, find the number of burning trees.

Input

The first line gives the number of falling missiles NN and the number of installed shields MM. (1≤N,M≤500 0001 \le N, M \le 500\,000)

From the second line through the NN-th line, the xx-coordinate and yy-coordinate of the location where each missile fell are given. Each coordinate value is an integer between −109-10^9 and 10910^9 inclusive, and the locations where the missiles fell are all distinct.

From line N+2N+2 through MM lines, the xx-coordinate and yy-coordinate of the location where each shield is installed are given. Each coordinate value is an integer between −109-10^9 and 10910^9 inclusive, and the locations where the shields are installed are all distinct.

Output

Output the number of burning trees.

Examples1

  1. Example 1

    Input
    5 5
    3 1
    1 4
    4 3
    4 5
    6 3
    3 1
    1 2
    5 3
    1 4
    3 4
    
    Expected output
    10