#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;
ll a[N];
pll tmp[N];

ll go(int n, ll mn){
    sort(tmp+1, tmp+1+n, [](pll i, pll j){return i.s < j.s;});
    lp(i,1,n) for(int j = i+1; j <= n and tmp[j].s - tmp[i].f < mn; ++j)
        mn = min(mn, (tmp[i].f - tmp[j].f) * (tmp[i].f - tmp[j].f)
                   + (tmp[i].s - tmp[j].s) * (tmp[i].s - tmp[j].s));
    return mn;
}

ll solve(int l, int r){
    if(r-l < 3){
        ll ret = infll;
        lp(i,l,r) lp(j,i+1,r)
            ret = min(ret, 1ll*(i-j)*(i-j) + (a[i]-a[j])*(a[i]-a[j]));
        return ret;
    }
    int mid = (l + r) / 2, j = 0;
    ll ret = min(solve(l, mid), solve(mid+1, r));
    lp(i,1,n) if(abs(i - mid) < ret) tmp[++j] = pll(i, a[i]);
    return min(ret, go(j, ret));
}

int main(){
    readi(n);
    lp(i,1,n) scanf("%I64d", a+i), a[i] += a[i-1];
    printf("%I64d\n", solve(1, n));
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;
ll a[N];
pll b[N],tmp[N];

ll go(int n, ll mn){
    lp(i,1,n) for(int j = i+1; j <= n and (tmp[j].s - tmp[i].s) * (tmp[j].s - tmp[i].s) < mn; ++j)
        mn = min(mn, (tmp[i].f - tmp[j].f) * (tmp[i].f - tmp[j].f)
                   + (tmp[i].s - tmp[j].s) * (tmp[i].s - tmp[j].s));
    return mn;
}

ll solve(int l, int r, pll b[]){
    if(r-l < 3){
        ll ret = infll;
        lp(i,l,r) lp(j,i+1,r)
            ret = min(ret, 1ll*(i-j)*(i-j) + (a[i]-a[j])*(a[i]-a[j]));
        return ret;
    }

    int mid = (l + r) / 2, j = 0, nl = 0, nr = 0;
    pll bl[mid-l+2], br[r-mid+1];
    lp(i,1,r-l+1)
        if(b[i].f <= mid) bl[++nl] = b[i];
        else br[++nr] = b[i];

    ll ret = min(solve(l, mid, bl), solve(mid+1, r, br));

    lp(i,1,r-l+1) if(1ll * (b[i].f - mid) * (b[i].f - mid) < ret)
        tmp[++j] = b[i];
    return min(ret, go(j, ret));
}

int main(){
    readi(n);
    lp(i,1,n) scanf("%I64d", a+i), a[i] += a[i-1], b[i] = pll(i, a[i]);
    sort(b+1, b+1+n, [](pll x, pll y){return x.s < y.s;});
    printf("%I64d\n", solve(1, n, b));
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
//

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end()

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
// #define ret return

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x=0, T y=0) : x(x), y(y) {}
    bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
    bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator*(T d) const { return P(x*d, y*d); }
    P operator/(T d) const { return P(x/d, y/d); }
    T dot(P p) const { return x*p.x + y*p.y; }
    T cross(P p) const { return x*p.y - y*p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    T dist2() const { return x*x + y*y; }
    double dist() const { return sqrt((double)dist2()); }
    // angle to x-axis in interval [-pi, pi]
    double angle() const { return atan2(y, x); }
    P unit() const { return *this/dist(); } // makes dist()=1
    P perp() const { return P(-y, x); } // rotates +90 degrees
    P normal() const { return perp().unit(); }
    // returns point rotated 'a' radians ccw around the origin
    P rotate(double a) const {
        return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};
typedef Point<ll> P;
pair<P, P> closest(vector<P> v) {
    assert(v.size() > 1);
    set<P> S;
    sort(all(v), [](P a, P b) { return a.y < b.y; });
    pair<ll, pair<P, P>> ret{LLONG_MAX, {P(), P()}};
    int j = 0;
    for(auto p: v) {
        P d{1 + (ll)sqrt(ret.first), 0};
        while (v[j].y <= p.y - d.x) S.erase(v[j++]);
        auto lo = S.lower_bound(p - d), hi = S.upper_bound(p + d);
        for (; lo != hi; ++lo)
            ret = min(ret, {(*lo - p).dist2(), {*lo, p}});
        S.insert(p);
    }
    return ret.second;
}

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0; i<n; i++){
        cin>>a[i];
    }
    ll ps[n];
    ps[0] = a[0];
    for(ll i=1; i<n; i++) ps[i] = ps[i-1] + a[i];
    vector<P> pp(n);
    for(ll i=0; i<n; i++){
        pp[i].x = i+1;
        pp[i].y = ps[i];
    }

    pair<P, P> answer = closest(pp);
    P ppp1 = answer.fi;
    P ppp2 = answer.se;
    ll x = (ppp1.x-ppp2.x)*(ppp1.x-ppp2.x) +  (ppp1.y-ppp2.y)*(ppp1.y-ppp2.y);
    print(x);

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
//

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end()

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

class Point
{
    public:
    int x, y;
};

/* Following two functions are needed for library function qsort().
Refer: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */

// Needed to sort array of points
// according to X coordinate
int compareX(const void* a, const void* b)
{
    Point *p1 = (Point *)a, *p2 = (Point *)b;
    return (p1->x - p2->x);
}

// Needed to sort array of points according to Y coordinate
int compareY(const void* a, const void* b)
{
    Point *p1 = (Point *)a, *p2 = (Point *)b;
    return (p1->y - p2->y);
}

// A utility function to find the
// distance between two points
float dist(Point p1, Point p2)
{
    return sqrt( (p1.x - p2.x)*(p1.x - p2.x) +
                (p1.y - p2.y)*(p1.y - p2.y)
            );
}

// A Brute Force method to return the
// smallest distance between two points
// in P[] of size n
float bruteForce(Point P[], int n)
{
    float min = FLT_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
            if (dist(P[i], P[j]) < min)
                min = dist(P[i], P[j]);
    return min;
}

// A utility function to find
// minimum of two float values
float min(float x, float y)
{
    return (x < y)? x : y;
}

// A utility function to find the
// distance beween the closest points of
// strip of given size. All points in
// strip[] are sorted accordint to
// y coordinate. They all have an upper
// bound on minimum distance as d.
// Note that this method seems to be
// a O(n^2) method, but it's a O(n)
// method as the inner loop runs at most 6 times
float stripClosest(Point strip[], int size, float d)
{
    float min = d; // Initialize the minimum distance as d

    qsort(strip, size, sizeof(Point), compareY);

    // Pick all points one by one and try the next points till the difference
    // between y coordinates is smaller than d.
    // This is a proven fact that this loop runs at most 6 times
    for (int i = 0; i < size; ++i)
        for (int j = i+1; j < size && (strip[j].y - strip[i].y) < min; ++j)
            if (dist(strip[i],strip[j]) < min)
                min = dist(strip[i], strip[j]);

    return min;
}

// A recursive function to find the
// smallest distance. The array P contains
// all points sorted according to x coordinate
float closestUtil(Point P[], int n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);

    // Find the middle point
    int mid = n/2;
    Point midPoint = P[mid];

    // Consider the vertical line passing
    // through the middle point calculate
    // the smallest distance dl on left
    // of middle point and dr on right side
    float dl = closestUtil(P, mid);
    float dr = closestUtil(P + mid, n - mid);

    // Find the smaller of two distances
    float d = min(dl, dr);

    // Build an array strip[] that contains
    // points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;

    // Find the closest points in strip.
    // Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}

// The main function that finds the smallest distance
// This method mainly uses closestUtil()
float closest(Point P[], int n)
{
    qsort(P, n, sizeof(Point), compareX);

    // Use recursive function closestUtil()
    // to find the smallest distance
    return (closestUtil(P, n)*closestUtil(P, n));
}

void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int ps[n];
    ps[0] = a[0];
    for(int i=1; i<n; i++) ps[i] = ps[i-1] + a[i];
    Point P[n];
    for(int i=0; i<n; i++){
        P[i] = {i+1, ps[i]};
    }
    float x = closest(P, n);
    print(round(x));

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
//

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end()

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

class Point
{
    public:
    int x, y;
};

/* Following two functions are needed for library function qsort().
Refer: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */

// Needed to sort array of points
// according to X coordinate
int compareX(const void* a, const void* b)
{
    Point *p1 = (Point *)a, *p2 = (Point *)b;
    return (p1->x - p2->x);
}

// Needed to sort array of points according to Y coordinate
int compareY(const void* a, const void* b)
{
    Point *p1 = (Point *)a, *p2 = (Point *)b;
    return (p1->y - p2->y);
}

// A utility function to find the
// distance between two points
float dist(Point p1, Point p2)
{
    return sqrt( (p1.x - p2.x)*(p1.x - p2.x) +
                (p1.y - p2.y)*(p1.y - p2.y)
            );
}

// A Brute Force method to return the
// smallest distance between two points
// in P[] of size n
float bruteForce(Point P[], int n)
{
    float min = FLT_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
            if (dist(P[i], P[j]) < min)
                min = dist(P[i], P[j]);
    return min;
}

// A utility function to find
// minimum of two float values
float min(float x, float y)
{
    return (x < y)? x : y;
}

// A utility function to find the
// distance beween the closest points of
// strip of given size. All points in
// strip[] are sorted accordint to
// y coordinate. They all have an upper
// bound on minimum distance as d.
// Note that this method seems to be
// a O(n^2) method, but it's a O(n)
// method as the inner loop runs at most 6 times
float stripClosest(Point strip[], int size, float d)
{
    float min = d; // Initialize the minimum distance as d

    qsort(strip, size, sizeof(Point), compareY);

    // Pick all points one by one and try the next points till the difference
    // between y coordinates is smaller than d.
    // This is a proven fact that this loop runs at most 6 times
    for (int i = 0; i < size; ++i)
        for (int j = i+1; j < size && (strip[j].y - strip[i].y) < min; ++j)
            if (dist(strip[i],strip[j]) < min)
                min = dist(strip[i], strip[j]);

    return min;
}

// A recursive function to find the
// smallest distance. The array P contains
// all points sorted according to x coordinate
float closestUtil(Point P[], int n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);

    // Find the middle point
    int mid = n/2;
    Point midPoint = P[mid];

    // Consider the vertical line passing
    // through the middle point calculate
    // the smallest distance dl on left
    // of middle point and dr on right side
    float dl = closestUtil(P, mid);
    float dr = closestUtil(P + mid, n - mid);

    // Find the smaller of two distances
    float d = min(dl, dr);

    // Build an array strip[] that contains
    // points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;

    // Find the closest points in strip.
    // Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}

// The main function that finds the smallest distance
// This method mainly uses closestUtil()
float closest(Point P[], int n)
{
    qsort(P, n, sizeof(Point), compareX);

    // Use recursive function closestUtil()
    // to find the smallest distance
    return (closestUtil(P, n)*closestUtil(P, n));
}

void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int ps[n];
    ps[0] = a[0];
    for(int i=1; i<n; i++) ps[i] = ps[i-1] + a[i];
    Point P[n];
    for(int i=0; i<n; i++){
        P[i] = {i+1, ps[i]};
    }
    float x = closest(P, n);
    print((int)round(x));

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
//

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end()

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

class Point
{
    public:
    int x, y;
};

/* Following two functions are needed for library function qsort().
Refer: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */

// Needed to sort array of points
// according to X coordinate
int compareX(const void* a, const void* b)
{
    Point *p1 = (Point *)a, *p2 = (Point *)b;
    return (p1->x - p2->x);
}

// Needed to sort array of points according to Y coordinate
int compareY(const void* a, const void* b)
{
    Point *p1 = (Point *)a, *p2 = (Point *)b;
    return (p1->y - p2->y);
}

// A utility function to find the
// distance between two points
float dist(Point p1, Point p2)
{
    return sqrt( (p1.x - p2.x)*(p1.x - p2.x) +
                (p1.y - p2.y)*(p1.y - p2.y)
            );
}

// A Brute Force method to return the
// smallest distance between two points
// in P[] of size n
float bruteForce(Point P[], int n)
{
    float min = FLT_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
            if (dist(P[i], P[j]) < min)
                min = dist(P[i], P[j]);
    return min;
}

// A utility function to find
// minimum of two float values
float min(float x, float y)
{
    return (x < y)? x : y;
}

// A utility function to find the
// distance beween the closest points of
// strip of given size. All points in
// strip[] are sorted accordint to
// y coordinate. They all have an upper
// bound on minimum distance as d.
// Note that this method seems to be
// a O(n^2) method, but it's a O(n)
// method as the inner loop runs at most 6 times
float stripClosest(Point strip[], int size, float d)
{
    float min = d; // Initialize the minimum distance as d

    qsort(strip, size, sizeof(Point), compareY);

    // Pick all points one by one and try the next points till the difference
    // between y coordinates is smaller than d.
    // This is a proven fact that this loop runs at most 6 times
    for (int i = 0; i < size; ++i)
        for (int j = i+1; j < size && (strip[j].y - strip[i].y) < min; ++j)
            if (dist(strip[i],strip[j]) < min)
                min = dist(strip[i], strip[j]);

    return min;
}

// A recursive function to find the
// smallest distance. The array P contains
// all points sorted according to x coordinate
float closestUtil(Point P[], int n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);

    // Find the middle point
    int mid = n/2;
    Point midPoint = P[mid];

    // Consider the vertical line passing
    // through the middle point calculate
    // the smallest distance dl on left
    // of middle point and dr on right side
    float dl = closestUtil(P, mid);
    float dr = closestUtil(P + mid, n - mid);

    // Find the smaller of two distances
    float d = min(dl, dr);

    // Build an array strip[] that contains
    // points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;

    // Find the closest points in strip.
    // Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}

// The main function that finds the smallest distance
// This method mainly uses closestUtil()
float closest(Point P[], int n)
{
    qsort(P, n, sizeof(Point), compareX);

    // Use recursive function closestUtil()
    // to find the smallest distance
    return closestUtil(P, n);
}

void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int ps[n];
    ps[0] = a[0];
    for(int i=1; i<n; i++) ps[i] = ps[i-1] + a[i];
    Point P[n];
    for(int i=0; i<n; i++){
        P[i] = {i+1, ps[i]};
    }
    ld x = closest(P, n);
    // trace(x);
    // trace(x*x);
    int y = x*x;
    print(x*x);

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

// A structure to represent a Point in 2D plane
struct Point
{
    int x, y;
};

/* Following two functions are needed for library function qsort().
   Refer: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */

// Needed to sort array of points according to X coordinate
int compareX(const void* a, const void* b)
{
    Point *p1 = (Point *)a,  *p2 = (Point *)b;
    return (p1->x - p2->x);
}
// Needed to sort array of points according to Y coordinate
int compareY(const void* a, const void* b)
{
    Point *p1 = (Point *)a,   *p2 = (Point *)b;
    return (p1->y - p2->y);
}

// A utility function to find the distance between two points
ll dist(Point p1, Point p2)
{
    return ( (p1.x - p2.x)*(p1.x - p2.x) +
                 (p1.y - p2.y)*(p1.y - p2.y)
               );
}

// A Brute Force method to return the smallest distance between two points
// in P[] of size n
ll bruteForce(Point P[], int n)
{
    ll min = INFLL;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
            if (dist(P[i], P[j]) < min)
                min = dist(P[i], P[j]);
    return min;
}

// A utility function to find minimum of two ll values
ll min(ll x, ll y)
{
    return (x < y)? x : y;
}

// A utility function to find the distance beween the closest points of
// strip of given size. All points in strip[] are sorted accordint to
// y coordinate. They all have an upper bound on minimum distance as d.
// Note that this method seems to be a O(n^2) method, but it's a O(n)
// method as the inner loop runs at most 6 times
ll stripClosest(Point strip[], int size, ll d)
{
    ll min = d;  // Initialize the minimum distance as d

    qsort(strip, size, sizeof(Point), compareY);

    // Pick all points one by one and try the next points till the difference
    // between y coordinates is smaller than d.
    // This is a proven fact that this loop runs at most 6 times
    for (int i = 0; i < size; ++i)
        for (int j = i+1; j < size && (strip[j].y - strip[i].y) < min; ++j)
            if (dist(strip[i],strip[j]) < min)
                min = dist(strip[i], strip[j]);

    return min;
}

// A recursive function to find the smallest distance. The array P contains
// all points sorted according to x coordinate
ll closestUtil(Point P[], int n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);

    // Find the middle point
    int mid = n/2;
    Point midPoint = P[mid];

    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    ll dl = closestUtil(P, mid);
    ll dr = closestUtil(P + mid, n-mid);

    // Find the smaller of two distances
    ll d = min(dl, dr);

    // Build an array strip[] that contains points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;

    // Find the closest points in strip.  Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}

// The main functin that finds the smallest distance
// This method mainly uses closestUtil()
ll closest(Point P[], int n)
{
    qsort(P, n, sizeof(Point), compareX);

    // Use recursive function closestUtil() to find the smallest distance
    return closestUtil(P, n);
}

int main() {
	ll i,j,k;
	ll n;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	Point P[n];
	fo(i,0,n) {
		P[i].x = i;
		P[i].y = v[i];
	}
	cout << closest(P,n) << endl;
	// ll i1 = result1.x;
	// ll i2 = result2.x;
	// cout << ((i1-i2)*(i1-i2) + (v[i1]-v[i2])*(v[i1]-v[i2])) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

// A structure to represent a Point in 2D plane
struct Point
{
    int x, y;
};

/* Following two functions are needed for library function qsort().
   Refer: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */

// Needed to sort array of points according to X coordinate
int compareX(const void* a, const void* b)
{
    Point *p1 = (Point *)a,  *p2 = (Point *)b;
    return (p1->x - p2->x);
}
// Needed to sort array of points according to Y coordinate
int compareY(const void* a, const void* b)
{
    Point *p1 = (Point *)a,   *p2 = (Point *)b;
    return (p1->y - p2->y);
}

// A utility function to find the distance between two points
float dist(Point p1, Point p2)
{
    return ( (p1.x - p2.x)*(p1.x - p2.x) +
                 (p1.y - p2.y)*(p1.y - p2.y)
               );
}

// A Brute Force method to return the smallest distance between two points
// in P[] of size n
float bruteForce(Point P[], int n)
{
    float min = FLT_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
            if (dist(P[i], P[j]) < min)
                min = dist(P[i], P[j]);
    return min;
}

// A utility function to find minimum of two float values
float min(float x, float y)
{
    return (x < y)? x : y;
}

// A utility function to find the distance beween the closest points of
// strip of given size. All points in strip[] are sorted accordint to
// y coordinate. They all have an upper bound on minimum distance as d.
// Note that this method seems to be a O(n^2) method, but it's a O(n)
// method as the inner loop runs at most 6 times
float stripClosest(Point strip[], int size, float d)
{
    float min = d;  // Initialize the minimum distance as d

    qsort(strip, size, sizeof(Point), compareY);

    // Pick all points one by one and try the next points till the difference
    // between y coordinates is smaller than d.
    // This is a proven fact that this loop runs at most 6 times
    for (int i = 0; i < size; ++i)
        for (int j = i+1; j < size && (strip[j].y - strip[i].y) < min; ++j)
            if (dist(strip[i],strip[j]) < min)
                min = dist(strip[i], strip[j]);

    return min;
}

// A recursive function to find the smallest distance. The array P contains
// all points sorted according to x coordinate
float closestUtil(Point P[], int n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);

    // Find the middle point
    int mid = n/2;
    Point midPoint = P[mid];

    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    float dl = closestUtil(P, mid);
    float dr = closestUtil(P + mid, n-mid);

    // Find the smaller of two distances
    float d = min(dl, dr);

    // Build an array strip[] that contains points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;

    // Find the closest points in strip.  Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}

// The main functin that finds the smallest distance
// This method mainly uses closestUtil()
float closest(Point P[], int n)
{
    qsort(P, n, sizeof(Point), compareX);

    // Use recursive function closestUtil() to find the smallest distance
    return closestUtil(P, n);
}

int main() {
	ll i,j,k;
	ll n;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	Point P[n];
	fo(i,0,n) {
		P[i].x = i;
		P[i].y = v[i];
	}
	cout << closest(P,n) << endl;
	// ll i1 = result1.x;
	// ll i2 = result2.x;
	// cout << ((i1-i2)*(i1-i2) + (v[i1]-v[i2])*(v[i1]-v[i2])) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};
#define int long long
typedef long long ll;

const int inf = 1e18;

int dist(const pair<int, int> &a, const pair<int, int> &b) {
    return (a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second);
}

bool cmpY(const pair<int, int> &a, const pair<int, int> &b) {
    return a.second < b.second;
}

int closestPair(vector<pair<int, int>> &points, int l, int r) {//inclusive
    if(r-l+1 <= 3) {
        int least = inf;
        for(int i = l; i <= r; ++i) {
            for(int j = i+1; j <= r; ++j) {
                least = min(least, dist(points[i], points[j]));
            }
        }
        return least;
    }
    int mid = (l+r)/2;
    int least = closestPair(points, l, mid);
    least = min(least, closestPair(points, mid+1, r));
    vector<pair<int, int>> strip;
    for(int i = l; i <= r; ++i) {
        int distToStrip = (points[i].first-points[mid].first)*(points[i].first-points[mid].first);
        if(distToStrip <= least) {
            strip.push_back(points[i]);
        }
    }
    sort(strip.begin(), strip.end(), cmpY);
    for(int i = 0; i < strip.size(); ++i) {
        for(int j = i+1; j < strip.size(); ++j) {
            int currDist = dist(strip[i], strip[j]);
            if(currDist > least) break;
            least = min(least, currDist);
        }
    }
    return least;
}

signed main() {
	ll i,j,k;
	ll n;
// 	n = 1000000;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	vector<pair<int,int>> pnts(n);
	fo(i,0,n) {
		pnts[i].F = i;
		pnts[i].S = v[i];
	}
	cout << closestPair(pnts,0,n-1) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

// A structure to represent a Point in 2D plane
struct Point
{
    ll x, y;
};

/* Following two functions are needed for library function qsort().
   Refer: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */

// Needed to sort array of points according to X coordinate
int compareX(const void* a, const void* b)
{
    Point *p1 = (Point *)a,  *p2 = (Point *)b;
    return (p1->x - p2->x);
}
// Needed to sort array of points according to Y coordinate
int compareY(const void* a, const void* b)
{
    Point *p1 = (Point *)a,   *p2 = (Point *)b;
    return (p1->y - p2->y);
}

// A utility function to find the distance between two points
ll dist(Point p1, Point p2)
{
    return ( (p1.x - p2.x)*(p1.x - p2.x) +
                 (p1.y - p2.y)*(p1.y - p2.y)
               );
}

// A Brute Force method to return the smallest distance between two points
// in P[] of size n
ll bruteForce(Point P[], ll n)
{
    ll min = INFLL;
    for (ll i = 0; i < n; ++i)
        for (ll j = i+1; j < n; ++j)
            if (dist(P[i], P[j]) < min)
                min = dist(P[i], P[j]);
    return min;
}

// A utility function to find minimum of two ll values
ll min(ll x, ll y)
{
    return (x < y)? x : y;
}

// A utility function to find the distance beween the closest points of
// strip of given size. All points in strip[] are sorted accordint to
// y coordinate. They all have an upper bound on minimum distance as d.
// Note that this method seems to be a O(n^2) method, but it's a O(n)
// method as the inner loop runs at most 6 times
ll stripClosest(Point strip[], int size, ll d)
{
    ll min = d;  // Initialize the minimum distance as d

    qsort(strip, size, sizeof(Point), compareY);

    // Pick all points one by one and try the next points till the difference
    // between y coordinates is smaller than d.
    // This is a proven fact that this loop runs at most 6 times
    for (ll i = 0; i < size; ++i)
        for (ll j = i+1; j < size && (strip[j].y - strip[i].y)*(strip[j].y - strip[i].y) < min; ++j)
            if (dist(strip[i],strip[j]) < min)
                min = dist(strip[i], strip[j]);

    return min;
}

// A recursive function to find the smallest distance. The array P contains
// all points sorted according to x coordinate
ll closestUtil(Point P[], ll n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);

    // Find the middle point
    ll mid = n/2;
    Point midPoint = P[mid];

    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    ll dl = closestUtil(P, mid);
    ll dr = closestUtil(P + mid, n-mid);

    // Find the smaller of two distances
    ll d = min(dl, dr);

    // Build an array strip[] that contains points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    ll j = 0;
    for (ll i = 0; i < n; i++)
        if ((P[i].x - midPoint.x)*(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;

    // Find the closest points in strip.  Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}

// The main functin that finds the smallest distance
// This method mainly uses closestUtil()
ll closest(Point P[], ll n)
{
    qsort(P, n, sizeof(Point), compareX);

    // Use recursive function closestUtil() to find the smallest distance
    return closestUtil(P, n);
}

int main() {
	ll i,j,k;
	ll n;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	Point P[n];
	fo(i,0,n) {
		P[i].x = i;
		P[i].y = v[i];
	}
	cout << closest(P,n) << endl;
	// ll i1 = result1.x;
	// ll i2 = result2.x;
	// cout << ((i1-i2)*(i1-i2) + (v[i1]-v[i2])*(v[i1]-v[i2])) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

// A structure to represent a Point in 2D plane
struct Point
{
    ll x, y;
};

/* Following two functions are needed for library function qsort().
   Refer: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */

// Needed to sort array of points according to X coordinate
int compareX(const void* a, const void* b)
{
    Point *p1 = (Point *)a,  *p2 = (Point *)b;
    return (p1->x - p2->x);
}
// Needed to sort array of points according to Y coordinate
int compareY(const void* a, const void* b)
{
    Point *p1 = (Point *)a,   *p2 = (Point *)b;
    return (p1->y - p2->y);
}

// A utility function to find the distance between two points
ll dist(Point p1, Point p2)
{
    return ( (p1.x - p2.x)*(p1.x - p2.x) +
                 (p1.y - p2.y)*(p1.y - p2.y)
               );
}

// A Brute Force method to return the smallest distance between two points
// in P[] of size n
ll bruteForce(Point P[], ll n)
{
    ll min = INFLL;
    for (ll i = 0; i < n; ++i)
        for (ll j = i+1; j < n; ++j)
            if (dist(P[i], P[j]) < min)
                min = dist(P[i], P[j]);
    return min;
}

// A utility function to find minimum of two ll values
ll min(ll x, ll y)
{
    return (x < y)? x : y;
}

// A utility function to find the distance beween the closest points of
// strip of given size. All points in strip[] are sorted accordint to
// y coordinate. They all have an upper bound on minimum distance as d.
// Note that this method seems to be a O(n^2) method, but it's a O(n)
// method as the inner loop runs at most 6 times
ll stripClosest(Point strip[], int size, ll d)
{
    ll min = d;  // Initialize the minimum distance as d

    qsort(strip, size, sizeof(Point), compareY);

    // Pick all points one by one and try the next points till the difference
    // between y coordinates is smaller than d.
    // This is a proven fact that this loop runs at most 6 times
    for (ll i = 0; i < size; ++i)
        for (ll j = i+1; j < size && (strip[j].y - strip[i].y) < min; ++j)
            if (dist(strip[i],strip[j]) < min)
                min = dist(strip[i], strip[j]);

    return min;
}

// A recursive function to find the smallest distance. The array P contains
// all points sorted according to x coordinate
ll closestUtil(Point P[], ll n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);

    // Find the middle point
    ll mid = n/2;
    Point midPoint = P[mid];

    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    ll dl = closestUtil(P, mid);
    ll dr = closestUtil(P + mid, n-mid);

    // Find the smaller of two distances
    ll d = min(dl, dr);

    // Build an array strip[] that contains points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    ll j = 0;
    for (ll i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;

    // Find the closest points in strip.  Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}

// The main functin that finds the smallest distance
// This method mainly uses closestUtil()
ll closest(Point P[], ll n)
{
    qsort(P, n, sizeof(Point), compareX);

    // Use recursive function closestUtil() to find the smallest distance
    return closestUtil(P, n);
}

int main() {
	ll i,j,k;
	ll n;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	Point P[n];
	fo(i,0,n) {
		P[i].x = i;
		P[i].y = v[i];
	}
	cout << closest(P,n) << endl;
	// ll i1 = result1.x;
	// ll i2 = result2.x;
	// cout << ((i1-i2)*(i1-i2) + (v[i1]-v[i2])*(v[i1]-v[i2])) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

struct point {
	ll x;
	ll y;
};

bool compX(point a, point b) {
	return a.x < b.x;
}

bool compY(point a, point b) {
	if(a.y < b.y)
		return true;
	if(a.y > b.y)
		return false;
	return a.x < b.x;
}

point result1, result2;
double minDist = DBL_MAX;

double euclideanDistance(point a, point b) {
	return (pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

double bruteMin(vector<point> &pointsByX, ll low, ll high) {
	ll i,j;
	double dist,bestDistance = DBL_MAX;
	for(i=low; i<=high; i++) {
		for(j=i+1; j<=high; j++) {
			dist = euclideanDistance(pointsByX[i], pointsByX[j]);
			if(dist < bestDistance) {
				bestDistance = dist;
				if(bestDistance < minDist) {
					minDist = bestDistance;
					result1 = pointsByX[i];
					result2 = pointsByX[j];
				}
			}
		}
	}
	return bestDistance;
}

double closestPair(vector<point> &pointsByX, vector<point> &pointsByY, ll low, ll high) {
	ll i,j,n = high - low + 1;
	if (n <= 3)	{
		return bruteMin(pointsByX, low, high);
	}

	ll mid = low + (high - low)/2;

	double distLeft = closestPair(pointsByX, pointsByY, low, mid);
	double distRight = closestPair(pointsByX, pointsByY, mid+1, high);

	double bestDistance = min(distLeft, distRight);

	vector<point> pointsInStrip;
	for(i=0; i<n; i++) {
        if(abs(pointsByY[i].x - pointsByX[mid].x) < bestDistance)
		    pointsInStrip.push_back(pointsByY[i]);
	}

	for(i=0; i<pointsInStrip.size(); i++) {
		for(j=i+1; j<pointsInStrip.size() && abs(pointsInStrip[i].y - pointsInStrip[j].y) < bestDistance; j++) {
			double dist = euclideanDistance(pointsInStrip[i], pointsInStrip[j]);
			if(dist < bestDistance) {
				bestDistance = dist;
                minDist = dist;
				result1 = pointsInStrip[i];
				result2 = pointsInStrip[j];
			}
		}
	}

	return bestDistance;
}

int main() {
	ll i,j,k;
	ll n;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	vector<point> pointsByX(n), pointsByY(n);
	fo(i,0,n) {
		pointsByX[i].x = i;
		pointsByX[i].y = v[i];
		pointsByY[i].x = i;
		pointsByY[i].y = v[i];
	}
	sort(all(pointsByX),compX);
	sort(all(pointsByY),compY);
	cout << closestPair(pointsByX,pointsByY,0,n-1) << endl;
	// ll i1 = result1.x;
	// ll i2 = result2.x;
	// cout << ((i1-i2)*(i1-i2) + (v[i1]-v[i2])*(v[i1]-v[i2])) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

struct point {
	ll x;
	ll y;
};

bool compX(point a, point b) {
	return a.x < b.x;
}

bool compY(point a, point b) {
	if(a.y < b.y)
		return true;
	if(a.y > b.y)
		return false;
	return a.x < b.x;
}

point result1, result2;
double minDist = DBL_MAX;

double euclideanDistance(point a, point b) {
	return (pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

double bruteMin(vector<point> &pointsByX, ll low, ll high) {
	ll i,j;
	double dist,bestDistance = DBL_MAX;
	for(i=low; i<=high; i++) {
		for(j=i+1; j<=high; j++) {
			dist = euclideanDistance(pointsByX[i], pointsByX[j]);
			if(dist < bestDistance) {
				bestDistance = dist;
				if(bestDistance < minDist) {
					minDist = bestDistance;
					result1 = pointsByX[i];
					result2 = pointsByX[j];
				}
			}
		}
	}
	return bestDistance;
}

double closestPair(vector<point> &pointsByX, vector<point> &pointsByY, ll low, ll high) {
	ll i,j,n = high - low + 1;
	if (n <= 3)	{
		return bruteMin(pointsByX, low, high);
	}

	ll mid = low + (high - low)/2;

	double distLeft = closestPair(pointsByX, pointsByY, low, mid);
	double distRight = closestPair(pointsByX, pointsByY, mid+1, high);

	double bestDistance = min(distLeft, distRight);

	vector<point> pointsInStrip;
	for(i=0; i<n; i++) {
        if(abs(pointsByY[i].x - pointsByX[mid].x) < bestDistance)
		    pointsInStrip.push_back(pointsByY[i]);
	}

	for(i=0; i<pointsInStrip.size(); i++) {
		for(j=i+1; j<pointsInStrip.size() && abs(pointsInStrip[i].y - pointsInStrip[j].y) < bestDistance; j++) {
			double dist = euclideanDistance(pointsInStrip[i], pointsInStrip[j]);
			if(dist < bestDistance) {
				bestDistance = dist;
                minDist = dist;
				result1 = pointsInStrip[i];
				result2 = pointsInStrip[j];
			}
		}
	}

	return bestDistance;
}

int main() {
	ll i,j,k;
	ll n;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	vector<point> pointsByX(n), pointsByY(n);
	fo(i,0,n) {
		pointsByX[i].x = i;
		pointsByX[i].y = v[i];
		pointsByY[i].x = i;
		pointsByY[i].y = v[i];
	}
	sort(all(pointsByX),compX);
	sort(all(pointsByY),compY);
	cout << closestPair(pointsByX,pointsByY,0,n-1) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

struct point {
	ll x;
	ll y;
};

bool compX(point a, point b) {
	return a.x < b.x;
}

bool compY(point a, point b) {
	if(a.y < b.y)
		return true;
	if(a.y > b.y)
		return false;
	return a.x < b.x;
}

point result1, result2;
double minDist = DBL_MAX;

double euclideanDistance(point a, point b) {
	return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

double bruteMin(vector<point> &pointsByX, ll low, ll high) {
	ll i,j;
	double dist,bestDistance = DBL_MAX;
	for(i=low; i<=high; i++) {
		for(j=i+1; j<=high; j++) {
			dist = euclideanDistance(pointsByX[i], pointsByX[j]);
			if(dist < bestDistance) {
				bestDistance = dist;
				if(bestDistance < minDist) {
					minDist = bestDistance;
					result1 = pointsByX[i];
					result2 = pointsByX[j];
				}
			}
		}
	}
	return bestDistance;
}

double closestPair(vector<point> &pointsByX, vector<point> &pointsByY, ll low, ll high) {
	ll i,j,n = high - low + 1;
	if (n <= 3)	{
		return bruteMin(pointsByX, low, high);
	}

	ll mid = low + (high - low)/2;

	double distLeft = closestPair(pointsByX, pointsByY, low, mid);
	double distRight = closestPair(pointsByX, pointsByY, mid+1, high);

	double bestDistance = min(distLeft, distRight);

	vector<point> pointsInStrip;
	for(i=0; i<n; i++) {
        if(abs(pointsByY[i].x - pointsByX[mid].x) < bestDistance)
		    pointsInStrip.push_back(pointsByY[i]);
	}

	for(i=0; i<pointsInStrip.size(); i++) {
		for(j=i+1; j<pointsInStrip.size() && abs(pointsInStrip[i].y - pointsInStrip[j].y) < bestDistance; j++) {
			double dist = euclideanDistance(pointsInStrip[i], pointsInStrip[j]);
			if(dist < bestDistance) {
				bestDistance = dist;
                minDist = dist;
				result1 = pointsInStrip[i];
				result2 = pointsInStrip[j];
			}
		}
	}

	return bestDistance;
}

int main() {
	ll i,j,k;
	ll n;
	cin>>n;
	vll v(n);
	fo(i,0,n) cin>>v[i];
	fo(i,1,n) v[i] += v[i-1];
	vector<point> pointsByX(n), pointsByY(n);
	fo(i,0,n) {
		pointsByX[i].x = i;
		pointsByX[i].y = v[i];
		pointsByY[i].x = i;
		pointsByY[i].y = v[i];
	}
	sort(all(pointsByX),compX);
	sort(all(pointsByY),compY);
	closestPair(pointsByX,pointsByY,0,n-1);
	ll i1 = result1.x;
	ll i2 = result2.x;
	cout << ((i1-i2)*(i1-i2) + (v[i1]-v[i2])*(v[i1]-v[i2])) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

const int N = 2e5 + 5;
const ll inf = 2e18;

ll n, a[N], s[N];
pii pt[N];

bool cmp(pii x, pii y) {
	if(x.first == y.first)
		return x.second < y.second;
	return x.first < y.first;
}

ll solve(int l, int r) {
	if(r - l <= 5) {
		ll ans = inf;
		for (int i = l; i < r; i++)
			for (int j = i + 1; j < r; j++) {
				ll nx = pt[i].first - pt[j].first;
				ll ny = pt[i].second - pt[j].second;
				ans = min(ans, 1LL * nx * nx + 1LL * ny * ny);
			}
		return ans;
	}
	int mid = (l + r) >> 1;
	ll d1 = solve(l, mid), d2 = solve(mid, r);
	ll ans = min(d1, d2);
	int i = lower_bound(pt + l, pt + mid, make_pair(pt[mid].first - ans, 0), cmp) - pt;
	int j = upper_bound(pt + mid, pt + r, make_pair(pt[mid].first + ans, 0), cmp) - pt;
	vector <pii> vec;
	for (; i < j; i++)
		vec.push_back({pt[i].second, pt[i].first});
	sort(vec.begin(), vec.end());
	int m = vec.size();
	for (int i = 0; i < m; i++) {
		for (int j = 1; j <= 5 && i + j < m; j++) {
			pii aval = vec[i], dovom = vec[i + j];
			ll nx = aval.first - dovom.first, ny = aval.second - dovom.second;
			ans = min(ans, nx * nx + ny * ny);
		}
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
		pt[i].second = i + 1, pt[i].first = s[i + 1];
	}
	sort(pt, pt + n);
	cout << solve(0, n) << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 5;
const ll inf = 1e18;

int n, a[N], s[N];
pii pt[N];

ll solve() {
	sort(pt, pt + n);
	set <pii> s;
	int j = 0;
	ll ans = inf;
	for (int i = 0; i < n; i++) {
		ll d = ceil(sqrt(ans));
		while(pt[i].first - pt[j].first >= ans) {
			s.erase({pt[j].second, pt[j].first});
			j++;
		}
		auto it1 = s.lower_bound({pt[i].second - d, pt[i].first});
		auto it2 = s.upper_bound({pt[i].second + d, pt[i].first});
		for (auto it = it1; it != it2; it++) {
			pii p = (*it);
			ll nx = p.first - pt[i].first, ny = p.second - pt[i].second;
			ans = min(ans, nx * nx + ny * ny);
		}
		s.insert({pt[i].second, pt[i].first});
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
		pt[i].first = i + 1, pt[i].second = s[i + 1];
	}
	cout << solve() << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const int N = 2e5 + 5;
const ll inf = 2e18;

ll n, a[N], s[N];
pii pt[N];

ll solve() {
	sort(pt, pt + n);
	set <pii> s;
	int j = 0;
	ll ans = inf;
	for (int i = 0; i < n; i++) {
		ll d = ceil(sqrt(ans));
		while(j < n && pt[i].first - pt[j].first >= ans) {
			s.erase({pt[j].second, pt[j].first});
			j++;
		}
		auto it1 = s.lower_bound({pt[i].second - d, pt[i].first});
		auto it2 = s.upper_bound({pt[i].second + d, pt[i].first});
		for (auto it = it1; it != it2; it++) {
			pii p = (*it);
			ll nx = p.first - pt[i].first, ny = p.second - pt[i].second;
			ans = min(ans, nx * nx + ny * ny);
		}
		s.insert({pt[i].second, pt[i].first});
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
		pt[i].second = i + 1, pt[i].first = s[i + 1];
	}
	cout << solve() << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

const int N = 2e5 + 5;
const ll inf = 2e18;

ll n, a[N], s[N];
pii pt[N];

ll solve() {
	sort(pt, pt + n);
	set <pii> s;
	int j = 0;
	ll ans = inf;
	for (int i = 0; i < n; i++) {
		ll d = ceil(sqrt(ans));
		while(pt[i].first - pt[j].first >= ans) {
			s.erase({pt[j].second, pt[j].first});
			j++;
		}
		auto it1 = s.lower_bound({pt[i].second - d, pt[i].first});
		auto it2 = s.upper_bound({pt[i].second + d, pt[i].first});
		for (auto it = it1; it != it2; it++) {
			pii p = (*it);
			ll nx = p.first - pt[i].first, ny = p.second - pt[i].second;
			ans = min(ans, nx * nx + ny * ny);
		}
		s.insert({pt[i].second, pt[i].first});
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
		pt[i].second = i + 1, pt[i].first = s[i + 1];
	}
	cout << solve() << "\n";
}


#include <bits/stdc++.h>
#define BABY ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#define localin freopen("in.txt","r",stdin);
#define localout freopen("out.txt","w",stdout);
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ll long long

#define pp pair<int,int>
#define ppp pair<int,pp>
const ll INF=1e17;
int N;

vector<pp> arr;
bool comp(pp a,pp b){
	return a.ss< b.ss;
}

ll closest_pair(){
	// return square of closest pair of point

	ll best=INF;
	set<pp> box;
	box.insert(arr[1]);
	int left=1;
	for(int i=2;i<=N;++i){
		while(left<i && arr[i].ss- arr[left].ss > sqrt(best)){
			box.erase(arr[left++]);
		}
		int cnt=0;
		for(auto it= box.lower_bound({arr[i].ff-sqrt(best),0}); it!=box.end() && arr[i].ff+sqrt(best) >= it->ff;it++){
			ll cy=arr[i].ff- it->ff;
			ll cx= arr[i].ss- it->ss;
			ll d= 1LL*cx*cx + 1LL*cy*cy;
			best=min(best,d);
		}
		box.insert(arr[i]);

	}
	return best;
}

int32_t main()
{
	BABY;

	cin>>N;

	int x;
	arr.resize(N+1);
	pp p;
	p.ff=0; // y cordinate
	p.ss=0; // x cordinate

	for(int i=1;i<=N;++i){
		cin>>x;
		arr[i].ff=arr[i-1].ff+x; // ff => y cordinate
		arr[i].ss=i;
	}

	// sort according to x cordinate
	//sort(arr.begin()+1,arr.end(),comp);

	cout<<closest_pair()<<"\n";

return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define endl "\n"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef pair<ll,pair<ll,ll> > ppp;

const ll N   = 1e6+5;
const ll INF = 1e18;
const ll mod = 1e9+7;

ll sqr(ll x){
    return 1LL*x*x;
}
ll dist(pp p1,pp p2){
    return sqr(p1.first-p2.first) + sqr(p1.second-p2.second);
}

bool by_x(pp &p1,pp &p2){
    return p1.first < p2.first;
}
bool by_y(pp &p1,pp &p2){
    return p1.second < p2.second;
}

ll a[N],pre[N];
pp pt[N];

ll solve(int l,int r){
    if(l==r)
        return INF;
    int mid = (l+r)/2;
    ll best = min(solve(l,mid),solve(mid+1,r));

    int midx = pt[(l+r+1)/2].first;

    vector<pp> v;

    for(int i=l;i<=r;i++){
        if(dist({pt[i].first,0LL},{midx,0LL}) < best){
            v.push_back(pt[i]);
        }
    }
    sort(all(v),by_y);

    for(int i=0;i<v.size();i++){
        for(int j = i+1;j<v.size();j++){
            if(dist({0LL,v[i].second},{0,v[j].second}) > best)
                break;
            best = min(best,dist(v[i],v[j]));
        }
    }
    return best;
}

int main(){
    ll n;
    cin>>n;
    pre[0] = 0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i] = pre[i-1]+a[i];
        pt[i].first = i;
        pt[i].second = pre[i];
    }
    sort(pt+1,pt+n+1,by_x);

    ll ans = solve(1,n);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define endl "\n"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef pair<ll,pair<ll,ll> > ppp;

const ll N   = 1e6+5;
const ll INF = 1e18;
const ll mod = 1e9+7;

ll sqr(ll x){
    return 1LL*x*x;
}
ll dist(pp p1,pp p2){
    return sqr(p1.first-p2.first) + sqr(p1.second-p2.second);
}

bool by_x(pp &p1,pp &p2){
    return p1.first < p2.first;
}
bool by_y(pp &p1,pp &p2){
    return p1.second < p2.second;
}

ll a[N],pre[N];
pp pt[N];

ll solve(int l,int r){
    if(l==r)
        return INF;
    int mid = (l+r)/2;
    ll best = min(solve(l,mid),solve(mid+1,r));

    int midx = pt[(l+r+1)/2].first;

    vector<pp> v;

    for(int i=l;i<=r;i++){
        if(dist({pt[i].first,0LL},{midx,0LL}) < sqrt(best)){
            v.push_back(pt[i]);
        }
    }
    sort(all(v),by_y);

    for(int i=0;i<v.size();i++){
        for(int j = i+1;j<v.size();j++){
            if(dist({0LL,v[i].second},{0,v[j].second}) > best)
                break;
            best = min(best,dist(v[i],v[j]));
        }
    }
    return best;
}

int main(){
    ll n;
    cin>>n;
    pre[0] = 0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i] = pre[i-1]+a[i];
        pt[i].first = i;
        pt[i].second = pre[i];
    }
    sort(pt+1,pt+n+1,by_x);
    ll ans = solve(1,n);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define endl "\n"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef pair<ll,pair<ll,ll> > ppp;

const ll N   = 1e6+5;
const ll INF = 1e18;
const ll mod = 1e9+7;

ll sqr(ll x){
    return 1LL*x*x;
}
ll dist(pp p1,pp p2){
    return sqr(p1.first-p2.first) + sqr(p1.second-p2.second);
}

bool by_x(pp &p1,pp &p2){
    return p1.first < p2.first;
}
bool by_y(pp &p1,pp &p2){
    return p1.second < p2.second;
}

ll a[N],pre[N];
pp pt[N];

ll solve(int l,int r){
    if(l==r)
        return INF;
    int mid = (l+r)/2;
    sort(pt+l,pt+r+1,by_x);
    ll best = min(solve(l,mid),solve(mid+1,r));

    int midx = pt[(l+r+1)/2].first;

    vector<pp> v;

    for(int i=l;i<=r;i++){
        if(dist({pt[i].first,0LL},{midx,0LL}) < best){
            v.push_back(pt[i]);
        }
    }
    sort(all(v),by_y);

    for(int i=0;i<v.size();i++){
        for(int j = i+1;j<v.size();j++){
            if(dist({0LL,v[i].second},{0,v[j].second}) > best)
                break;
            best = min(best,dist(v[i],v[j]));
        }
    }
    return best;
}

int main(){
    ll n;
    cin>>n;
    pre[0] = 0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i] = pre[i-1]+a[i];
        pt[i].first = i;
        pt[i].second = pre[i];
    }
    ll ans = solve(1,n);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define endl "\n"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef pair<ll,pair<ll,ll> > ppp;

const ll N   = 1e6+5;
const ll INF = 1e18;
const ll mod = 1e9+7;

ll sqr(ll x){
    return 1LL*x*x;
}
ll dist(pp p1,pp p2){
    return sqr(p1.first-p2.first) + sqr(p1.second-p2.second);
}

bool by_x(pp &p1,pp &p2){
    return p1.first < p2.first;
}
bool by_y(pp &p1,pp &p2){
    return p1.second < p2.second;
}

ll a[N],pre[N];
pp pt[N];

ll solve(int l,int r){
    if(l==r)
        return INF;
    int mid = (l+r)/2;
    ll best = min(solve(l,mid),solve(mid+1,r));

    int midx = pt[(l+r+1)/2].first;

    vector<pp> v;

    for(int i=l;i<=r;i++){
        if(dist({pt[i].first,0LL},{midx,0LL}) < sqrt(best)){
            v.push_back(pt[i]);
        }
    }
    sort(all(v),by_y);
    for(int i=0;i<v.size();i++){
        for(int j = i+1;j<v.size();j++){
            if(dist({0LL,v[i].second},{0,v[j].second}) > sqrt(best))
                break;
            best = min(best,dist(v[i],v[j]));
        }
    }
    return best;
}

int main(){
    ll n;
    cin>>n;
    pre[0] = 0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i] = pre[i-1]+a[i];
        pt[i].first = i;
        pt[i].second = pre[i];
    }
    sort(pt+1,pt+n+1,by_x);
    ll ans = solve(1,n);
    cout<<ans<<endl;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
typedef long long ll;
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18
#define mp make_pair
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()

const int N = 1e5 + 5;
set<pii> s;
ll a[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    // n = 100000;
    fr(i ,1, n) {
        cin >> a[i];
        // a[i] = -10000;
        a[i] += a[i - 1];
    }
    int pt = 1;
    ll best = 1e9;
    fr(i, 1, n) {
        while(pt < i && (i - pt) * 1LL * (i - pt) > best) {
            s.erase({a[pt], pt});
            pt++;
        }
        auto it = s.lower_bound({a[i] - sqrtl(best), -1e9});
        while(it != s.end() && (it -> fi < a[i] || (it -> fi - a[i]) * 1LL * (it -> fi - a[i]) <= best)){
            best = min(best, (it -> fi - a[i]) * 1LL * (it -> fi - a[i]) + (it -> se - i) * 1LL * (it -> se - i));
            it++;
        }
        s.insert({a[i], i});
    }
    cout << best;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define pii pair<int,int>
#define f80 double
#define LOCAL 1

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 100005;
const int inf = 1e12;

inline bool cmpy(const pii &a, const pii &b){
    return a.se < b.se;
}
vi<pii> b;
pii a[N];
int dist(pii a, pii b){
    return (a.fi - b.fi) * (a.fi - b.fi) + (a.se - b.se) * (a.se - b.se);
}
int solve_strip(vi<pii> &strip, int n,int dd){
    forn(i, 0, n - 1){
        forn(j, i + 1, n - 1){
            int val = (strip[j].se - strip[i].se) * (strip[j].se - strip[i].se);
            if(val > dd)
                break;
            else
                dd = min(dd, dist(strip[i], strip[j]));
        }
    }
    return dd;
}
int solve(pii a[],vi<pii> b,int n){
    if(n <= 3){
        int d = 2e18;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                d = min(d, dist(b[i], b[j]));
            }
        }
        return d;
    }
    vi<pii> c, d;
    pii mid = a[n / 2];
    forn(i, 0, n - 1){
        if(b[i].fi < mid.fi)
            c.pb(b[i]);
        else
            d.pb(b[i]);
    }
    int dd = min(solve(a, c, c.size()), solve(a + n / 2 + 1, d, d.size()));
    vi<pii> strip;
    forn(i, 0, n - 1){
        int val = (b[i].fi - mid.fi) * (b[i].fi - mid.fi);
        if(val <= dd)
            strip.pb(b[i]);
    }
    return min(dd, solve_strip(strip, strip.size(), dd));
}
signed main(){
    IO;
    //freopen("inp.txt", "r", stdin);
    int n;
    cin >> n;
    int s = 0;
    forn(i, 0, n - 1)
    {
        int x;
        cin >> x;
        s += x;
        pii y = {i + 1, s};
        a[i] = y;
        b.pb(y);
    }
    sort(a, a + n);
    sort(all(b), cmpy);
    cout << solve(a, b, n);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define pii pair<int,int>
#define f80 double
#define LOCAL 1

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 300005;
const int inf = 1e12;

inline bool cmpy(const pii &a, const pii &b){
    return a.se < b.se;
}
vi<pii> a, b;
int dist(pii a, pii b){
    return (a.fi - b.fi) * (a.fi - b.fi) + (a.se - b.se) * (a.se - b.se);
}
int solve_strip(vi<pii> &strip, int n,int dd){
    forn(i, 0, n - 1){
        forn(j, i + 1, n - 1){
            int val = (strip[j].se - strip[i].se) * (strip[j].se - strip[i].se);
            if(val > dd)
                break;
            else
                dd = min(dd, dist(strip[i], strip[j]));
        }
    }
    return dd;
}
int solve(vi<pii> &a,vi<pii> b,int n){
    if(n <= 3){
        int d = 2e18;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                d = min(d, dist(b[i], b[j]));
            }
        }
        return d;
    }
    vi<pii> c, d;
    pii mid = a[n / 2];
    forn(i, 0, n - 1){
        if(b[i].fi < mid.fi)
            c.pb(b[i]);
        else
            d.pb(b[i]);
    }
    int dd = min(solve(a, c, c.size()), solve(a, d, d.size()));
    vi<pii> strip;
    forn(i, 0, n - 1){
        int val = (b[i].fi - mid.fi) * (b[i].fi - mid.fi);
        if(val <= dd)
            strip.pb(b[i]);
    }
    return min(dd, solve_strip(strip, strip.size(), dd));
}
signed main(){
    IO;
   // freopen("inp.txt", "r", stdin);
    int n;
    cin >> n;
    int s = 0;
    forn(i, 0, n - 1)
    {
        int x;
        cin >> x;
        s += x;
        pii y = {i + 1, s};
        a.pb(y);
        b.pb(y);
    }
    sort(all(a));
    sort(all(b), cmpy);
    cout << solve(a, b, n);
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
typedef long long ll;
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18
#define mp make_pair
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()

const int N = 1e5 + 5;
set<pii> s;
ll a[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    fr(i ,1, n) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    int pt = 1;
    ll best = 1e9;
    fr(i, 1, n) {
        while(pt < i && (i - pt) * 1LL * (i - pt) > best * best) {
            s.erase({a[pt], pt});
            pt++;
        }
        auto it = s.lower_bound({a[i] - sqrtl(best), -1e9});
        while(it != s.end() && (it -> fi < a[i] || (it -> fi - a[i]) * 1LL * (it -> fi - a[i]) <= best * best)){
            best = min(best, (it -> fi - a[i]) * 1LL * (it -> fi - a[i]) + (it -> se - i) * 1LL * (it -> se - i));
            it++;
        }
        s.insert({a[i], i});
    }
    cout << best;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define pii pair<int,int>
#define f80 double
#define LOCAL 1

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 300005;
const int inf = 1e12;

inline bool cmpy(const pii &a, const pii &b){
    return a.se < b.se;
}
vi<pii> a, b;
int dist(pii a, pii b){
    return (a.fi - b.fi) * (a.fi - b.fi) + (a.se - b.se) * (a.se - b.se);
}
int solve_strip(vi<pii> &strip, int n,int dd){
    forn(i, 0, n - 1){
        forn(j, i + 1, n - 1){
            int val = (strip[j].se - strip[i].se) * (strip[j].se - strip[i].se);
            if(val > dd)
                break;
            else
                dd = min(dd, dist(strip[i], strip[j]));
        }
    }
    return dd;
}
int solve(vi<pii> &a,vi<pii> b,int n){
    if(n <= 3){
        int d = 2e18;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                d = min(d, dist(b[i], b[j]));
            }
        }
        return d;
    }
    vi<pii> c, d;
    pii mid = a[n / 2];
    forn(i, 0, n - 1){
        if(b[i].fi <= mid.fi)
            c.pb(b[i]);
        else
            d.pb(b[i]);
    }
    int dd = min(solve(a, c, c.size()), solve(a, d, d.size()));
    vi<pii> strip;
    forn(i, 0, n - 1){
        int val = (b[i].fi - mid.fi) * (b[i].fi - mid.fi);
        if(val <= dd)
            strip.pb(b[i]);
    }
    return min(dd, solve_strip(strip, strip.size(), dd));
}
signed main(){
    IO;
    //freopen("inp.txt", "r", stdin);
    int n;
    cin >> n;
    int s = 0;
    forn(i, 0, n - 1)
    {
        int x;
        cin >> x;
        s += x;
        pii y = {i + 1, s};
        a.pb(y);
        b.pb(y);
    }
    sort(all(a));
    sort(all(b), cmpy);
    cout << solve(a, b, n);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define pii pair<int,int>
#define f80 double
#define LOCAL 1

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 300005;
const int inf = 1e12;

inline bool cmpy(const pii &a, const pii &b){
    return a.se < b.se;
}
pii a[N], b[N];
int dist(pii a, pii b){
    return (a.fi - b.fi) * (a.fi - b.fi) + (a.se - b.se) * (a.se - b.se);
}
int solve_strip(pii strip[], int n,int dd){
    forn(i, 0, n - 1){
        forn(j, i + 1, n - 1){
            int val = (strip[j].se - strip[i].se) * (strip[j].se - strip[i].se);
            if(val > dd)
                break;
            else
                dd = min(dd, dist(strip[i], strip[j]));
        }
    }
    return dd;
}
int solve(pii a[],pii b[],int n){
    if(n <= 3){
        int d = 2e18;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                d = min(d, dist(b[i], b[j]));
            }
        }
        return d;
    }
    pii c[n + 2], d[n + 2];
    pii mid = a[n / 2];
    int j = 0, k = 0;
    forn(i, 0, n - 1){
        if(b[i].fi < mid.fi)
            c[j++] = b[i];
        else
            d[k++] = b[i];
    }
    int dd = min(solve(a, c, j), solve(a, d, k));
    pii strip[n + 2];
    j = 0;
    forn(i, 0, n - 1){
        int val = (b[i].fi - mid.fi) * (b[i].fi - mid.fi);
        if(val <= dd)
            strip[j++] = b[i];
    }
    return min(dd, solve_strip(strip, j, dd));
}
signed main(){
    IO;
   // freopen("inp.txt", "r", stdin);
    int n;
    cin >> n;
    forn(i, 0, n - 1)
    {
        int x;
        cin >> x;
        a[i].se = a[i - 1].se + x;
        a[i].fi = i + 1;
        b[i] = a[i];
    }
    sort(a, a + n);
    sort(b, b + n, cmpy);
    cout << solve(a, b, n);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sq(x) ((x) * (x))
typedef long long int ll;
typedef long double ld;
typedef pair<long long, long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long, long long>> vpl;

double closest_pair(const vpl &pt, int n) {
    // Code copied from AnimeshSinha1309:
    // https://codeforces.com/contest/429/submission/65955176

    double minDistSq = FLT_MAX;
    set<pll> box;
    box.insert(pt[0]);

    int left = 0;

    for (int idx = 1; idx < n; ++idx) {
        double minDist = sqrt(minDistSq);

        // while (left < idx && pt[idx].second - pt[left].second > minDist) {
        //     box.erase(pt[left]);
        //     left++;
        // }

        ll cnt = 0;

        auto it = box.lower_bound(
            {pt[idx].first - minDist, pt[idx].second - minDist});

        while (it != box.end() &&
               pt[idx].first + sqrt(minDistSq) >= it->first) {
            cnt++;

            double distSq =
                sq(pt[idx].first - it->first) + sq(pt[idx].second - it->second);
            minDistSq = min(minDistSq, distSq);

            it++;
        }

        box.insert(pt[idx]);
    }

    return minDistSq;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vll prefSum(n);

    for (int i = 0; i < n; i++)
        cin >> prefSum[i];

    for (int i = 1; i < n; i++)
        prefSum[i] += prefSum[i - 1];

    vpl points(n);
    for (int i = 0; i < n; i++)
        points[i] = {prefSum[i], i};

    cout << ((ll)closest_pair(points, n)) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sq(x) ((x) * (x))
typedef long long int ll;
typedef long double ld;
typedef pair<long long, long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long, long long>> vpl;

ll closest_pair(const vpl &pt, int n) {
    // Code copied from AnimeshSinha1309:
    // https://codeforces.com/contest/429/submission/65955176

    ll minDistSq = LLONG_MAX;
    set<pll> box;
    box.insert(pt[0]);

    int left = 0;

    for (int idx = 1; idx < n; ++idx) {
        while (left < idx && sq(pt[idx].second - pt[left].second) > minDistSq and pt[idx].second > pt[left].second) {
            box.erase(pt[left]);
            left++;
        }

        ll cnt = 0;

        auto it = box.lower_bound(
            {pt[idx].first - sqrt(minDistSq), pt[idx].second - sqrt(minDistSq)});

        while (it != box.end() &&
               pt[idx].first + sqrt(minDistSq) >= it->first) {
            cnt++;

            ll distSq =
                sq(pt[idx].first - it->first) + sq(pt[idx].second - it->second);
            minDistSq = min(minDistSq, distSq);

            it++;
        }

        box.insert(pt[idx]);
    }

    return minDistSq;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vll prefSum(n);

    for (int i = 0; i < n; i++)
        cin >> prefSum[i];

    for (int i = 1; i < n; i++)
        prefSum[i] += prefSum[i - 1];

    vpl points(n);
    for (int i = 0; i < n; i++)
        points[i] = {prefSum[i], i};

    cout << ((ll)closest_pair(points, n)) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sq(x) ((x) * (x))
typedef long long int ll;
typedef long double ld;
typedef pair<long long, long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long, long long>> vpl;

double closest_pair(const vpl &pt, int n) {
    // Code copied from AnimeshSinha1309:
    // https://codeforces.com/contest/429/submission/65955176

    double minDistSq = FLT_MAX;
    set<pll> box;
    box.insert(pt[0]);

    int left = 0;

    for (int idx = 1; idx < n; ++idx) {
        double minDist = sqrt(minDistSq);

        while (left < idx && pt[idx].first - pt[left].first > minDist) {
            box.erase(pt[left]);
            left++;
        }

        ll cnt = 0;

        auto it = box.lower_bound(
            {pt[idx].first - minDist, pt[idx].second - minDist});

        while (it != box.end() &&
               pt[idx].first + sqrt(minDistSq) >= it->first) {
            cnt++;

            double distSq =
                sq(pt[idx].first - it->first) + sq(pt[idx].second - it->second);
            minDistSq = min(minDistSq, distSq);

            it++;
        }

        box.insert(pt[idx]);
    }

    return minDistSq;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vll prefSum(n);

    for (int i = 0; i < n; i++)
        cin >> prefSum[i];

    for (int i = 1; i < n; i++)
        prefSum[i] += prefSum[i - 1];

    vpl points(n);
    for (int i = 0; i < n; i++)
        points[i] = {prefSum[i], i};

    cout << ((ll)closest_pair(points, n)) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<long long, long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long, long long>> vpl;

double closest_pair(const vpl &pt, int n) {
    // Code copied from AnimeshSinha1309:
    // https://codeforces.com/contest/429/submission/65955176

    double best = FLT_MAX;
    set<pll> box;
    box.insert(pt[0]);

    int left = 0;

    for (int i = 1; i < n; ++i) {
        double lim = sqrt(best);

        while (left < i && pt[i].second - pt[left].second > lim) {
            box.erase(pt[left]);
            left++;
        }

        ll cnt = 0;

        auto it = box.lower_bound(
            {pt[i].first - sqrt(best), pt[i].second - sqrt(best)});

        for (; it != box.end() /*&& pt[i].first + sqrt(best) >= it->first*/;
             it++) {
            cnt++;
            double distSq = (pow(pt[i].first - it->first, 2.0) +
                             pow(pt[i].second - it->second, 2.0));
            best = min(best, distSq);
        }

        box.insert(pt[i]);
    }
    return best;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vll prefSum(n);

    for (int i = 0; i < n; i++)
        cin >> prefSum[i];

    for (int i = 1; i < n; i++)
        prefSum[i] += prefSum[i - 1];

    vpl points(n);
    for (int i = 0; i < n; i++)
        points[i] = {prefSum[i], i};

    cout << ((ll)closest_pair(points, n)) << endl;
    return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

int main()
{
    long  ans=1000000000,x,n,a[100005],sq[100005],i,j,k,pre[100005]={0};
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(i=0;i<=10000;i++)
        sq[i]=i*i;
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(sq[j-i]>ans)
                break;
            if(abs(pre[j]-pre[i])<10000&&sq[abs(pre[j]-pre[i])]<ans){
                x=sq[j-i]+sq[abs(pre[j]-pre[i])];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%lld",ans);
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
long long id1,id2,ans=1e9,x,n,a[100005],sq[100005],k,pre[100005];
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(int i=0;i<=11000;i++){
        sq[i]=i*i;

    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n&&j<=i+10010;j++){
            id1=j-i;
            id2=abs(pre[j]-pre[i]);
            if(sq[id1]>ans)
                break;
            if(id2<10100){
                x=sq[id1]+sq[id2];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%lld",ans);
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

int main()
{
    long long ans=1000000000,x,n,a[100005],sq[100005],i,j,k,pre[100005]={0};
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(i=0;i<=11000;i++){
        sq[i]=i*i;

    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(sq[j-i]>ans)
                break;
            if(abs(pre[j]-pre[i])<11000){
                x=sq[j-i]+sq[abs(pre[j]-pre[i])];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%lld",ans);
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

int main()
{
    long  ans=1000000000,x,n,a[100005],sq[100005],i,j,k,pre[100005]={0};
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(i=0;i<=10000;i++){
        sq[i]=i*i;

    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(sq[j-i]>ans)
                break;
            if(abs(pre[j]-pre[i])<10000){
                x=sq[j-i]+sq[abs(pre[j]-pre[i])];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%lld",ans);
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
long id1,id2,ans=1e9,x,n,a[100005],sq[100005],k,pre[100005];
int main()
{
    scanf("%ld",&n);
    for(int i=1;i<=n;i++){
        scanf("%ld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(int i=0;i<=11000;i++){
        sq[i]=i*i;

    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n&&j<=i+10010;j++){
            id1=j-i;
            id2=abs(pre[j]-pre[i]);
            if(sq[id1]>ans)
                break;
            if(id2<10100){
                x=sq[id1]+sq[id2];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%ld",ans);
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

int main()
{
    long long ans=1000000000,x,n,a[100005],sq[100005],i,j,k,pre[100005]={0};
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(i=0;i<=10000;i++){
        sq[i]=i*i;

    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(sq[j-i]>ans)
                break;
            if(abs(pre[j]-pre[i])<10000){
                x=sq[j-i]+sq[abs(pre[j]-pre[i])];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%lld",ans);
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

int main()
{
    long long id1,id2,ans=1000000000,x,n,a[100005],sq[100005],k,pre[100005]={0};
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(int i=0;i<=11000;i++){
        sq[i]=i*i;

    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n&&j<=i+11000;j++){
            id1=j-i;
            id2=abs(pre[j]-pre[i]);
            if(sq[id1]>ans)
                break;
            if(id2<11000){
                x=sq[id1]+sq[id2];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%lld",ans);
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
using namespace std;
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
long id1,id2,ans=1e9,x,n,a[100005],sq[100005],k,pre[100005];
int main()
{
    scanf("%ld",&n);
    for(int i=1;i<=n;i++){
        scanf("%ld",&a[i]);
        pre[i]=a[i]+pre[i-1];

    }
    for(int i=0;i<=11000;i++){
        sq[i]=i*i;

    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n&&j<=i+10010;j++){
            id1=j-i;
            id2=abs(pre[j]-pre[i]);
            if(sq[id1]>ans)
                break;
            if(id2<10100){
                x=sq[id1]+sq[id2];

                if(x<ans)
                    ans=x;
            }
        }
    }
    printf("%ld",ans);
}