Game with Tokens
Contest: Codeforces Round 468 (Div. 1, based on Technocup 2018 Final Round)
Difficulty rating: 2500
Tags: data structures, games, implementation

Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates x and y.

The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or right. Black player can choose directions for each token independently.

After a turn of the white player the white token can not be in a point where a black token is located. There are no other constraints on locations of the tokens: positions of black tokens can coincide, after a turn of the black player and initially the white token can be in the same point with some black point. If at some moment the white player can't make a move, he loses. If the white player makes 10100500 moves, he wins.

You are to solve the following problem. You are given initial positions of all black tokens. It is guaranteed that initially all these positions are distinct. In how many places can the white token be located initially so that if both players play optimally, the black player wins?

Input format:
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of black points.

The (i + 1)-th line contains two integers xi, yi ( - 105 ≤ xi, yi,  ≤ 105) — the coordinates of the point where the i-th black token is initially located.

It is guaranteed that initial positions of black tokens are distinct.

Output format:
Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

Note:
In the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.

The first example:

The second example:

In the third example the white tokens should be located in the inner square 2 × 2, to make the black player win.

Example input:
4
-2 -1
0 1
0 -3
2 -1

Example output:
4

Example input:
4
-2 0
-1 1
0 -2
1 -1

Example output:
2

Editorial:
Note that if black and white chip are placed in the beginning in points {x, y} with the same parity of x + y then black chip can't be on the manhattan distance 1 from white chip before white's move. So black chip can't block white chip and can't somehow affect the game. We can solve the problem independently for black chips with odd x + y, white chip with even x + y and for black chips with even x + y, white chip with odd x + y.
Note that we can solve the problem for black chips with even x + y if we move all of them on 1 upward and then solve the problem for odd x + y. Let's now consider only black chips with odd x + y.
Look at the image. If black chip is placed in black point then it can stop white chip placed in red, blue, yellow, green points if it will move up, down, left, right, respectively (i.e. white point can't make infinite number of move in these directions whatever moves it will make).
Note that one black chip can stop white chip only in one or zero directions. If there are four black chips that can stop white chip in different directions then black will win. Else white chip can move in some direction infinitely and white will win.
So, every black chip generates four angles of different types. If point {x, y} is contained in intersection of four angles of different types and x + y is even then we should count this point in answer.
Let's substitute every point {x, y} to point {x + y, x - y}. There are still four types of angles but now every coordinate of white chip must be even number. In particular, the first image will look like this:
Let's leave only points with even coordinates and divide every coordinate by two. Still every black chip generates four angles, white chip must be in intersection of four angles of different types but now there are no restrictions about parity of anything.
How to count points in intersection of four angles of different types effectively? Find for each type of angles and for each x-coordinate half-interval of y-coordinates such that every point in this half-interval will be in some angle of current type. If we can find these half-intervals then we can find for every x-coordinate length of intersections of four half-intervals and answer will be equal to sum of these lengths.
Let's consider angles of only one type because for other types we can do something symmetric. Let's these angles will have sides directed upward and rightward. Then for each x-coordinate half-interval is [Lx, ∞) where Lx is minimal y-coordinate of vertices of angles which aren't placed to the right from x. So we can sort all vertices by x and then write some easy scanline.