This page is still under construction.

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

Grid

Time limit1sMemory limit128 MB

Summary
Given n points, decide whether there exist an axis-aligned grid of evenly spaced lines and a straight line whose intersection set is exactly those points.
Level

Hard8 of 10

Topics
Geometry, Math, Implementation, Brute force
Solved
No attempts yet

Problem

Gerald spent several hours drawing a rectangular grid on a sheet of paper. First he drew several vertical lines, keeping the same distance dxdx between neighbouring ones. Then he drew several horizontal lines, keeping the same distance dydy between neighbouring ones. Both dxdx and dydy are positive, and every line he drew is a full straight line that never ends.

While Gerald was relaxing with a cup of tea, his brother Mike came in and scratched one straight line on the sheet. Gerald felt outraged and ordered Mike to remove everything odd from the paper. Mike rubbed out almost all of the drawing with an eraser, but he did not notice the points where his line crossed the grid, and those points stayed bold enough to read.

Mike copied the surviving points into his notebook, and the brothers now argue about whether that list can be right.

A grid is described by integers x1≤x2x_1 \le x_2, dx>0dx > 0, y1≤y2y_1 \le y_2 and dy>0dy > 0, where x2−x1x_2 - x_1 is a multiple of dxdx and y2−y1y_2 - y_1 is a multiple of dydy. It consists of the vertical lines x=x1,x1+dx,…,x2x = x_1, x_1 + dx, \ldots, x_2 and the horizontal lines y=y1,y1+dy,…,y2y = y_1, y_1 + dy, \ldots, y_2. Mike's line is an arbitrary straight line. The list is right when some grid and some straight line have exactly the listed points in common. Mike's line then cannot lie on top of a grid line, because that would leave infinitely many common points.

Decide whether the list can be right.

Input

The first line contains one integer nn, the number of points (3≤n≤100 0003 \le n \le 100\,000).

Each of the next nn lines contains two integers xix_i and yiy_i, the coordinates of one point. Every coordinate is at most 10910^9 in absolute value.

All the points are distinct.

Output

Print YES if such a grid and such a straight line exist, and NO otherwise.

Examples3

  1. Example 1

    Input
    4
    1 1
    5 3
    3 2
    9 5
    
    Expected output
    YES
    
  2. Example 2

    Input
    3
    0 0
    1 1
    2 3
    
    Expected output
    NO
    
  3. Example 3

    Input
    4
    5 8
    5 -1
    5 5
    5 2
    
    Expected output
    YES