#P8858. Balanced Polyline Partition

    ID: 22022 Type: Default 1000ms 256MiB

Balanced Polyline Partition

Balanced Polyline Partition

In the first quadrant, there is a rectangular region with its bottom‐left corner at \((0,0)\) and its top‐right corner at \((10^{100},10^{100})\). There are a positive even number of given integer points inside the region. Your task is to construct a polyline inside the region from \((0,0)\) to \((10^{100},10^{100})\) that satisfies the following conditions:

  • Each segment of the polyline is parallel to the \(x\)-axis or the \(y\)-axis.
  • The polyline does not pass through any of the given integer points.
  • The polyline divides the entire region into two parts, each containing an equal number of the given integer points.
  • The polyline has as few bending points (points where the direction changes) as possible.

It can be proved that at least one such polyline exists. You only need to output the number of bending points in a polyline with the minimum possible number of bends that satisfies all the conditions.

Note: The coordinates of the bending points may be non-integer.

inputFormat

The first line contains a single even integer \(n\) (\(2 \le n \le 10^5\)), the number of given integer points inside the region.

Each of the following \(n\) lines contains two integers \(x_i\) and \(y_i\) (with \(0 < x_i, y_i < 10^{100}\)), representing the coordinates of a point.

outputFormat

Output a single integer: the number of bending points in a valid polyline that meets the conditions and has the minimum possible number of bends.

sample

2
1 1
2 2
2