/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
int mcd(int a,int b)
{
    if (a>b)swap(a,b);
    if (a==0)return b;
    a = abs(a),b = abs(b);
    return __gcd(a,b);
}
signed main()
{
    int n;
    cin >> n;
    vector<pii> v(n);
    for (int i = 0; i < n ;i++)
        cin >> v[i].ff >> v[i].ss;
    for (int i = n-1; i >= 0; i--)
        v[i].ff-=v[0].ff,v[i].ss-=v[0].ss;
    int x = 0, y = 0;
    for (int i = 1; i < n; i++)
    {
        y = mcd(v[i].ss,y);
        int add = 0;
        if (v[i].ss == 0 && v[i-1].ss == 0)
            add = mcd(v[i].ff,v[i-1].ff);
        else
        {
            int lc = v[i].ss*v[i-1].ss/mcd(v[i].ss,v[i-1].ss);   
            int c1 = lc/max(1ll,v[i-1].ss);
            int c2 = lc/max(1ll,v[i].ss);
            add = c2*v[i].ff - c1*v[i-1].ff;
        }
        x = mcd(x,add);
    }
    if (x*y == 0)
        cout << -1;
    else
        cout << x*y;
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |