Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ichki-butun-nuqtalar

Interior lattice points

Medium 1000 ms 128 MB 56%
Share

A polygon with $n$ vertices is given on the plane: its vertices $(x_{1}; y_{1}), (x_{2}; y_{2}), \ldots, (x_{n}; y_{n})$ are listed in order (clockwise or counterclockwise), and all coordinates are integers. The polygon does not intersect itself. How many points with both coordinates integer lie strictly inside the polygon (not on its boundary)?

A polygon on the coordinate grid; the lattice points inside it are highlighted

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains two integers: $x_{i}$ and $y_{i}$.

Output

One integer — the number of interior lattice points.

Note

$3 \le n \le 10^{5}$
$-10^{6} \le x_{i}, y_{i} \le 10^{6}$

Examples

Input #1
3
0 0
5 0
0 4
Output #1
6
Input #2
4
0 0
1 0
1 1
0 1
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.