#P6137. [IOI 2012] 理想城

[IOI 2012] 理想城

Description

Like many scientists and artists of his age, Little L is very interested in city planning and urban design. He is devoted to building an ideal city. The ideal city consists of NN blocks, and these blocks are placed on an infinite square grid. The cell in row xx and column yy is identified by the ordered pair (x,y)(x,y). The cell (0,0)(0,0) is located at the upper-left corner of the grid. Given a cell (x,y)(x,y), the adjacent cells (if they exist) are: (x1,y)(x-1,y), (x+1,y)(x+1,y), (x,y1)(x,y-1), (x,y+1)(x,y+1). Each block covers exactly one cell on the grid. A block can be placed on cell (x,y)(x,y) if and only if 1x,y23121 \le x,y \le 2^{31}-2. We will use the coordinates of a cell to also denote the block on that cell. If two blocks are placed in adjacent cells, they are considered adjacent blocks. All blocks in the ideal city are connected, and there are no “holes” inside. In other words, all cells must satisfy the following two conditions:

  • For any two empty cells, there exists at least one sequence of adjacent empty cells connecting them.
  • For any two non-empty cells, there exists at least one sequence of adjacent non-empty cells connecting them.

The block placements in the following 44 figures do not satisfy the conditions of an ideal city. The first two figures do not satisfy the first condition. The 33rd figure does not satisfy the second condition, and the 44th figure satisfies neither condition.

When traversing the ideal city, one step means moving from one block to an adjacent block. During a step, you cannot move into an empty cell. Suppose v0,v1,,vN1v_0,v_1,\cdots,v_{N-1} are the coordinates of the NN blocks. For any two different blocks viv_i and vjv_j, their distance d(vi,vj)d(v_i,v_j) is the minimum number of steps needed to move from viv_i to vjv_j.

The figure below shows an ideal city consisting of 1111 blocks. The block coordinates are:

v0=(2,5)v1=(2,6)v2=(3,3)v_0=(2,5) \quad v_1=(2,6) \quad v_2=(3,3) v3=(3,6)v4=(4,3)v5=(4,4)v_3=(3,6) \quad v_4=(4,3) \quad v_5=(4,4) v6=(4,5)v7=(4,6)v8=(5,3)v_6=(4,5) \quad v_7=(4,6) \quad v_8=(5,3) v9=(5,4)v10=(5,6)v_9=(5,4) \quad v_{10}=(5,6)

Here, d(v1,v3)=1d(v_1,v_3)=1, d(v1,v8)=6d(v_1,v_8)=6, d(v6,v10)=2d(v_6,v_{10})=2, and d(v9,v10)=4d(v_9,v_{10})=4.

Given an ideal city, compute

S=i=0N2j=i+1N1d(vi,vj)S=\sum_{i=0}^{N-2}\sum_{j=i+1}^{N-1}d(v_i,v_j)

Input Format

The first line contains a positive integer NN, the number of blocks in the ideal city.

Lines 22 to N+1N+1 each contain two non-negative integers. Line i+2i+2 gives the coordinates of the ii-th block vi=(xi,yi)v_i = (x_i, y_i).

Output Format

Output a single line containing a positive integer, the value of SS. Since SS may be very large, you only need to output SS modulo 10910^9.

11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6

174

Hint

For 100%100\% of the testdata, 1N1051 \le N \le 10^5, and 1xi,yi23121 \le x_i,y_i \le 2^{31}-2.

Translated by ChatGPT 5