B - Minimal Area Gym - 101755B (三角形叉积面积公式)

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值