观察答案易知 答案无非

1.i*i-j*j+ai*ai-aj*aj
2.i*i-j*j+aj*aj-ai*ai
3.j*j-i*i+ai*ai-aj*aj
4.j*j-i*i+aj*aj-ai*ai

答案肯定取4种情况的max...那么我枚举这四种情况的最大值就好了~
观察易知就就两种方式取正负..取最大值,没啥解释的.
下面是代码:

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
#define inf 132913423039
typedef long long ll;
const ll mod=1e9+7;
const ll N=1e5+5;
const double eps=1e-7;
using namespace std;
const int manx=55;
ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);    }
ll qp(ll a,ll b, ll p){ll ans = 1;while(b){if(b&1){ans = (ans*a)%p;--b;}a = (a*a)%p;b >>= 1;}return ans%p;}
ll Inv(ll x)          { return qp(x,mod-2,mod);}
ll C(ll n,ll m){if (m>n) return 0;ll ans = 1;for (int i = 1; i <= m; ++i) ans=ans*Inv(i)%mod*(n-i+1)%mod;return ans%mod;}
ll a[N];
ll b[N];
int main()
{
    ios;
    ll n,x,ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>x;
        a[i]=i*i+x*x;b[i]=i*i-x*x;
    }
    sort(a+1,a+1+n);    sort(b+1,b+1+n);
    ans=max(a[n]-a[1],b[n]-b[1]);
    cout<<ans<<endl;
    return 0;
}