You are given a strictly convex polygon. Find the minimal possible area of non-degenerate triangle whose vertices are the vertices of the polygon.
Input
The first line contains a single integer n (3 ≤ n ≤ 200000) — the number of polygon vertices.
Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of polygon vertices.
The polygon is guaranteed to be strictly convex. Vertices are given in the counterclockwise order.
Output
It is known that the area of triangle whose vertices are the integer points on the grid is either integer or half-integer.
Output a single integer — the required area, multiplied by 2.
Examples
Input
4 0 1 3 0 3 3 -1 3
Output
5
Input
3 0 0 1 0 0 1
Output
1
Input
4 -999999991 999999992 -999999993 -999999994 999999995 -999999996 999999997 999999998
Output
3999999948000000156
Note
It is recommended to make all calculations using integer numbers, because floating point precision most likely would not be enough.
显然组成三角形面积最小时三个顶点应该是相邻的三个点,求出这nn个由相邻三个顶点组成的三角形面积维护最小值即为答案
叉积公式:
a(x1,y1),b(x2,y2),c(x3,y3);
S=0.5abs((x2-x1)(y3-y1)-(y2-y1)*(x3-x1));
代码:
//Full of love and hope for life
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f3f3f3f3f
//https://paste.ubuntu.com/
//https://paste.ubuntu.com/p/zh7wFrBqkp/
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll n[maxn];
ll m[maxn];
ll s(ll x,ll y,ll z,ll w){
return abs((ll)x*y-(ll)z*w);
}
int main(){
ll mi,g;
ll a;
ll x,y,z,w;
mi=inf;
cin >> a;
for(ll i=1;i<=a;i++){
cin >> n[i] >> m[i];
}
n[a+1]=n[1];
m[a+1]=m[1];
n[a+2]=n[2];
m[a+2]=m[2];
for(ll i=1;i<=a;i++){
x=n[i+1]-n[i];
y=n[i+2]-n[i];
z=m[i+1]-m[i];
w=m[i+2]-m[i];
g=s(x,w,y,z);
mi=min(mi,g);
}
cout << mi;
return 0;
}