#P6149. Triangular Pasture
Triangular Pasture
Triangular Pasture
Farmer John wants to build a triangular pasture for his cows. There are N fence posts located at distinct points (Xi, Yi) on the 2D plane. He can choose three posts to form a triangular pasture if and only if one edge of the triangle is parallel to the x-axis and another edge is parallel to the y-axis. In other words, if the three chosen points are A = (x, y), B = (x', y) and C = (x, y'), then they form a valid triangle with area \(\frac{1}{2}|x'-x|\cdot|y'-y|\).
Your task is to compute the sum of the areas of all possible valid pastures. In order to avoid dealing with fractions, output 2 times the sum of areas modulo \(10^9+7\). That is, if the sum of areas is A, print \(2A \pmod{10^9+7}\).
Input Constraints: 3 \(\le N \le 10^5\).
inputFormat
The first line contains an integer \(N\), the number of fence posts. Each of the next \(N\) lines contains two space-separated integers, \(X_i\) and \(Y_i\), representing the coordinates of a fence post.
outputFormat
Output a single integer: \(2\) times the sum of areas of all valid triangular pastures modulo \(10^9+7\).
sample
3
0 0
0 1
1 0
1