#include <bits/stdc++.h>
using namespace std;
typedef double db;
#define fir first
#define sec second
const db PI = atan2(0, -1);
const db EPS = 1e-8;
db sqr(db x) {
	return x * x;
}
int sgn(db x) {
	return x < -EPS ? -1 : EPS < x;
}

struct Poi {
	db x, y;
	Poi() {}
	Poi(db x, db y):x(x), y(y) {}
	db cross(const Poi&rhs) {
		return x * rhs.y - y * rhs.x;
	}
	db dot(const Poi&rhs) {
		return x * rhs.x + y * rhs.y;
	}
	db len2() {
		return dot(*this);
	}
	Poi operator + (const Poi&rhs) {
		return Poi(x + rhs.x, y + rhs.y);
	}
	Poi operator - (const Poi&rhs) {
		return Poi(x - rhs.x, y - rhs.y);
	}
	Poi operator * (db p) {
		return Poi(x * p, y * p);
	}
	Poi operator / (db p) {
		return Poi(x / p, y / p);
	}
	bool operator == (const Poi&rhs) {
		return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0;
	}
	Poi norm() {
		return Poi(-y, x);
	}
	db ang() {
		db a = atan2(y, x);
		if (a < 0) a += PI * 2;
		return a;
	}
};

db len2(Poi a) {
	return a.len2();
}

struct Cir:Poi {
	db r;
	Cir() {}
	Cir(db _x, db _y, db r):r(r) {
		x = _x, y = _y;
	}
	Poi getPoi(db ang) {
		return Poi(x + cos(ang) * r, y + sin(ang) * r);
	}
};

int getTangents(Cir A, Cir B, Poi*a, Poi*b) {
	int cnt = 0;
	if (A.r < B.r) { swap(A, B), swap(a, b); }
	db d2 = (A - B).len2();
	db rdiff = A.r - B.r;
	db rsum = A.r + B.r;
	if (d2 < rdiff * rdiff) return 0;

	db base = (B - A).ang();
	if (sgn(d2) == 0 && sgn(A.r - B.r) == 0) return -1;

	if (sgn(d2 - rdiff * rdiff) == 0) {
		a[cnt] = A.getPoi(base); b[cnt] = B.getPoi(base); ++cnt;
		return 1;
	}

	db ang = acos((A.r - B.r) / sqrt(d2));
	a[cnt] = A.getPoi(base + ang); b[cnt] = B.getPoi(base + ang); ++cnt;
	a[cnt] = A.getPoi(base - ang); b[cnt] = B.getPoi(base - ang); ++cnt;
	if (sgn(d2 - rsum * rsum) == 0) {
		a[cnt] = A.getPoi(base); b[cnt] = B.getPoi(PI + base); ++cnt;
	} else if (sgn(d2 - rsum * rsum) > 0) {
		ang = acos((A.r + B.r) / sqrt(d2));
		a[cnt] = A.getPoi(base + ang); b[cnt] = B.getPoi(PI + base + ang); ++cnt;
		a[cnt] = A.getPoi(base - ang); b[cnt] = B.getPoi(PI + base - ang); ++cnt;
	}

	for (int i = 0; i < cnt; ++i)
		if (a[i] == b[i])
			b[i] = a[i] + (a[i] - A).norm();

	return cnt;
}

bool inTriangle(Poi x, Poi a, Poi b, Poi c) {
	int s0, s1, s2;
	s0 = sgn((a - x).cross(b - x));
	s1 = sgn((b - x).cross(c - x));
	s2 = sgn((c - x).cross(a - x));
	return s0 == s1 && s1 == s2;
}

int getLineInter(Poi a, Poi b, Poi c, Poi d, Poi&i) {
	b = b - a, d = d - c;
	Poi u = a - c;
	db e = b.cross(d);
	if (sgn(e) == 0) return 0;
	db t = d.cross(u) / e;
	i = a + b * t;
	return 1;
}

db disToLine(Poi p, Poi a, Poi b) {
	Poi v1 = b - a, v2 = p - a;
	return fabs(v1.cross(v2)) / sqrt(v1.len2());
}

Poi getProj(Poi p, Poi a, Poi b) {
	return a + (b - a) / sqrt(len2(b - a)) * (p - a).cross(b - a);
}

db disToSeg(Poi p, Poi a, Poi b) {
	if (sgn(len2(a - b)) == 0) return sqrt(len2(p - a));
	if (sgn((b - a).dot(p - a)) < 0) return sqrt(len2(a - p));
	if (sgn((a - b).dot(p - b)) < 0) return sqrt(len2(b - p));
	return fabs((b - a).cross(p - a)) / sqrt(len2(b - a));
}

bool isInteger(db x) {
	return sgn(x - floor(x)) == 0 || sgn(x - ceil(x)) == 0;
}
int toInt(db x) {
	if (fabs(x - floor(x)) < fabs(x - ceil(x)))
		return floor(x);
	return ceil(x);
}

const int N = 1e5 + 100;
bool cmp(const Poi&a, const Poi&b) {
	return sgn(a.x - b.x) < 0 || (sgn(a.x - b.x) == 0 && sgn(a.y - b.y) < 0);
}

bool operator == (const Poi&a, const Poi&b) {
	return a.x == b.x && a.y == b.y;
}

struct NearestPair {
	Poi p[N], t[N];
	db md = 1e20;
	void upd(Poi a, Poi b) {
		if (a == b) return ;
		db tmp = len2(a - b);
	//	cout << tmp << endl;
		md = tmp < md ? tmp : md;
	}

	void solve(int l, int r) {
		if (r - l <= 3) {
			for (int i = l; i <= r; ++i)
				for (int j = i + 1; j <= r; ++j)
					upd(p[i], p[j]);
			sort(p + l, p + r + 1, cmp);
		} else {
			int m = (l + r) >> 1;
			db x = p[m].x;
			solve(l, m), solve(m + 1, r);
			merge(p + 1, p + m + 1, p + m + 1, p + r + 1, t, cmp);
			copy(t, t + r - l + 1, p + l);
			int siz = 0;
			for (int i = l; i <= r; ++i)
				if (sqr(p[i].x - x) < md) {
					for (int j = siz - 1; j >= 0 && sqr(p[i].y - t[j].y) < md; --j)
						upd(p[i], t[j]);
					t[siz++] = p[i];
				}
		}
	}
};

Poi p[N];

int n, a[N];

int main() {
#ifdef lol
	freopen("f.in", "r", stdin);
	freopen("f.out", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		a[i] += a[i - 1];
	}
	for (int i = 1; i <= n; ++i)
		p[i] = Poi(i, a[i]);
	NearestPair*solver = new NearestPair();
	copy(p + 1, p + n + 1, solver->p + 1);
	solver->solve(1, n);
	printf("%d\n", toInt(solver->md));

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef double db;
#define fir first
#define sec second
const db PI = atan2(0, -1);
const db EPS = 1e-8;
db sqr(db x) {
	return x * x;
}
int sgn(db x) {
	return x < -EPS ? -1 : EPS < x;
}

struct Poi {
	db x, y;
	Poi() {}
	Poi(db x, db y):x(x), y(y) {}
	db cross(const Poi&rhs) {
		return x * rhs.y - y * rhs.x;
	}
	db dot(const Poi&rhs) {
		return x * rhs.x + y * rhs.y;
	}
	db len2() {
		return dot(*this);
	}
	Poi operator + (const Poi&rhs) {
		return Poi(x + rhs.x, y + rhs.y);
	}
	Poi operator - (const Poi&rhs) {
		return Poi(x - rhs.x, y - rhs.y);
	}
	Poi operator * (db p) {
		return Poi(x * p, y * p);
	}
	Poi operator / (db p) {
		return Poi(x / p, y / p);
	}
	bool operator == (const Poi&rhs) {
		return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0;
	}
	Poi norm() {
		return Poi(-y, x);
	}
	db ang() {
		db a = atan2(y, x);
		if (a < 0) a += PI * 2;
		return a;
	}
};

db len2(Poi a) {
	return a.len2();
}

struct Cir:Poi {
	db r;
	Cir() {}
	Cir(db _x, db _y, db r):r(r) {
		x = _x, y = _y;
	}
	Poi getPoi(db ang) {
		return Poi(x + cos(ang) * r, y + sin(ang) * r);
	}
};

int getTangents(Cir A, Cir B, Poi*a, Poi*b) {
	int cnt = 0;
	if (A.r < B.r) { swap(A, B), swap(a, b); }
	db d2 = (A - B).len2();
	db rdiff = A.r - B.r;
	db rsum = A.r + B.r;
	if (d2 < rdiff * rdiff) return 0;

	db base = (B - A).ang();
	if (sgn(d2) == 0 && sgn(A.r - B.r) == 0) return -1;

	if (sgn(d2 - rdiff * rdiff) == 0) {
		a[cnt] = A.getPoi(base); b[cnt] = B.getPoi(base); ++cnt;
		return 1;
	}

	db ang = acos((A.r - B.r) / sqrt(d2));
	a[cnt] = A.getPoi(base + ang); b[cnt] = B.getPoi(base + ang); ++cnt;
	a[cnt] = A.getPoi(base - ang); b[cnt] = B.getPoi(base - ang); ++cnt;
	if (sgn(d2 - rsum * rsum) == 0) {
		a[cnt] = A.getPoi(base); b[cnt] = B.getPoi(PI + base); ++cnt;
	} else if (sgn(d2 - rsum * rsum) > 0) {
		ang = acos((A.r + B.r) / sqrt(d2));
		a[cnt] = A.getPoi(base + ang); b[cnt] = B.getPoi(PI + base + ang); ++cnt;
		a[cnt] = A.getPoi(base - ang); b[cnt] = B.getPoi(PI + base - ang); ++cnt;
	}

	for (int i = 0; i < cnt; ++i)
		if (a[i] == b[i])
			b[i] = a[i] + (a[i] - A).norm();

	return cnt;
}

bool inTriangle(Poi x, Poi a, Poi b, Poi c) {
	int s0, s1, s2;
	s0 = sgn((a - x).cross(b - x));
	s1 = sgn((b - x).cross(c - x));
	s2 = sgn((c - x).cross(a - x));
	return s0 == s1 && s1 == s2;
}

int getLineInter(Poi a, Poi b, Poi c, Poi d, Poi&i) {
	b = b - a, d = d - c;
	Poi u = a - c;
	db e = b.cross(d);
	if (sgn(e) == 0) return 0;
	db t = d.cross(u) / e;
	i = a + b * t;
	return 1;
}

db disToLine(Poi p, Poi a, Poi b) {
	Poi v1 = b - a, v2 = p - a;
	return fabs(v1.cross(v2)) / sqrt(v1.len2());
}

Poi getProj(Poi p, Poi a, Poi b) {
	return a + (b - a) / sqrt(len2(b - a)) * (p - a).cross(b - a);
}

db disToSeg(Poi p, Poi a, Poi b) {
	if (sgn(len2(a - b)) == 0) return sqrt(len2(p - a));
	if (sgn((b - a).dot(p - a)) < 0) return sqrt(len2(a - p));
	if (sgn((a - b).dot(p - b)) < 0) return sqrt(len2(b - p));
	return fabs((b - a).cross(p - a)) / sqrt(len2(b - a));
}

bool isInteger(db x) {
	return sgn(x - floor(x)) == 0 || sgn(x - ceil(x)) == 0;
}
int toInt(db x) {
	if (fabs(x - floor(x)) < fabs(x - ceil(x)))
		return floor(x);
	return ceil(x);
}

const int N = 1e5 + 100;
bool cmp(const Poi&a, const Poi&b) {
	return a.y < b.y;
}

bool operator == (const Poi&a, const Poi&b) {
	return a.x == b.x && a.y == b.y;
}

Poi p[N];
db md = 1e20;
void upd(Poi a, Poi b) {
	db tmp = len2(a - b);
	md = tmp < md ? tmp : md;
}

void solve(int l, int r) {
	if (r - l <= 3) {
		for (int i = l; i <= r; ++i)
			for (int j = i + 1; j <= r; ++j)
				upd(p[i], p[j]);
		sort(p + l, p + r + 1, cmp);
	} else {
		int m = (l + r) >> 1;
		db x = p[m].x;
		solve(l, m), solve(m + 1, r);
		int siz = 0;
		static Poi t[N];
		merge(p + l, p + m + 1, p + m + 1, p + r + 1, t, cmp);
		copy(t, t + r - l + 1, p + l);
		for (int i = l; i <= r; ++i)
			if (sqr(p[i].x - x) < md) {
				for (int j = siz - 1; j >= 0 && sqr(p[i].y - t[j].y) < md; --j)
					upd(p[i], t[j]);
				t[siz++] = p[i];
			}
	}
}

int n;
long long a[N];

int main() {
#ifdef lol
	freopen("f.in", "r", stdin);
	freopen("f.out", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		a[i] += a[i - 1];
	}
	for (int i = 1; i <= n; ++i)
		p[i] = Poi(i, a[i]);
	solve(1, n);
	printf("%d\n", toInt(md));

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef double db;
#define fir first
#define sec second
const db PI = atan2(0, -1);
const db EPS = 1e-8;
db sqr(db x) {
	return x * x;
}
int sgn(db x) {
	return x < -EPS ? -1 : EPS < x;
}

struct Poi {
	db x, y;
	Poi() {}
	Poi(db x, db y):x(x), y(y) {}
	db cross(const Poi&rhs) {
		return x * rhs.y - y * rhs.x;
	}
	db dot(const Poi&rhs) {
		return x * rhs.x + y * rhs.y;
	}
	db len2() {
		return dot(*this);
	}
	Poi operator + (const Poi&rhs) {
		return Poi(x + rhs.x, y + rhs.y);
	}
	Poi operator - (const Poi&rhs) {
		return Poi(x - rhs.x, y - rhs.y);
	}
	Poi operator * (db p) {
		return Poi(x * p, y * p);
	}
	Poi operator / (db p) {
		return Poi(x / p, y / p);
	}
	bool operator == (const Poi&rhs) {
		return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0;
	}
	Poi norm() {
		return Poi(-y, x);
	}
	db ang() {
		db a = atan2(y, x);
		if (a < 0) a += PI * 2;
		return a;
	}
};

db len2(Poi a) {
	return a.len2();
}

struct Cir:Poi {
	db r;
	Cir() {}
	Cir(db _x, db _y, db r):r(r) {
		x = _x, y = _y;
	}
	Poi getPoi(db ang) {
		return Poi(x + cos(ang) * r, y + sin(ang) * r);
	}
};

int getTangents(Cir A, Cir B, Poi*a, Poi*b) {
	int cnt = 0;
	if (A.r < B.r) { swap(A, B), swap(a, b); }
	db d2 = (A - B).len2();
	db rdiff = A.r - B.r;
	db rsum = A.r + B.r;
	if (d2 < rdiff * rdiff) return 0;

	db base = (B - A).ang();
	if (sgn(d2) == 0 && sgn(A.r - B.r) == 0) return -1;

	if (sgn(d2 - rdiff * rdiff) == 0) {
		a[cnt] = A.getPoi(base); b[cnt] = B.getPoi(base); ++cnt;
		return 1;
	}

	db ang = acos((A.r - B.r) / sqrt(d2));
	a[cnt] = A.getPoi(base + ang); b[cnt] = B.getPoi(base + ang); ++cnt;
	a[cnt] = A.getPoi(base - ang); b[cnt] = B.getPoi(base - ang); ++cnt;
	if (sgn(d2 - rsum * rsum) == 0) {
		a[cnt] = A.getPoi(base); b[cnt] = B.getPoi(PI + base); ++cnt;
	} else if (sgn(d2 - rsum * rsum) > 0) {
		ang = acos((A.r + B.r) / sqrt(d2));
		a[cnt] = A.getPoi(base + ang); b[cnt] = B.getPoi(PI + base + ang); ++cnt;
		a[cnt] = A.getPoi(base - ang); b[cnt] = B.getPoi(PI + base - ang); ++cnt;
	}

	for (int i = 0; i < cnt; ++i)
		if (a[i] == b[i])
			b[i] = a[i] + (a[i] - A).norm();

	return cnt;
}

bool inTriangle(Poi x, Poi a, Poi b, Poi c) {
	int s0, s1, s2;
	s0 = sgn((a - x).cross(b - x));
	s1 = sgn((b - x).cross(c - x));
	s2 = sgn((c - x).cross(a - x));
	return s0 == s1 && s1 == s2;
}

int getLineInter(Poi a, Poi b, Poi c, Poi d, Poi&i) {
	b = b - a, d = d - c;
	Poi u = a - c;
	db e = b.cross(d);
	if (sgn(e) == 0) return 0;
	db t = d.cross(u) / e;
	i = a + b * t;
	return 1;
}

db disToLine(Poi p, Poi a, Poi b) {
	Poi v1 = b - a, v2 = p - a;
	return fabs(v1.cross(v2)) / sqrt(v1.len2());
}

Poi getProj(Poi p, Poi a, Poi b) {
	return a + (b - a) / sqrt(len2(b - a)) * (p - a).cross(b - a);
}

db disToSeg(Poi p, Poi a, Poi b) {
	if (sgn(len2(a - b)) == 0) return sqrt(len2(p - a));
	if (sgn((b - a).dot(p - a)) < 0) return sqrt(len2(a - p));
	if (sgn((a - b).dot(p - b)) < 0) return sqrt(len2(b - p));
	return fabs((b - a).cross(p - a)) / sqrt(len2(b - a));
}

bool isInteger(db x) {
	return sgn(x - floor(x)) == 0 || sgn(x - ceil(x)) == 0;
}
int toInt(db x) {
	if (fabs(x - floor(x)) < fabs(x - ceil(x)))
		return floor(x);
	return ceil(x);
}

const int N = 1e5 + 100;
bool cmp(const Poi&a, const Poi&b) {
	return sgn(a.x - b.x) < 0 || (sgn(a.x - b.x) == 0 && sgn(a.y - b.y) < 0);
}
struct NearestPair {
	Poi p[N], t[N];
	db md = 1e20;
	void upd(Poi a, Poi b) {
		db tmp = len2(a - b);
		md = tmp < md ? tmp : md;
	}

	void solve(int l, int r) {
		if (r - l <= 3) {
			for (int i = l; i <= r; ++i)
				for (int j = i + 1; j <= r; ++j)
					upd(p[i], p[j]);
			sort(p + l, p + r + 1, cmp);
		} else {
			int m = (l + r) >> 1;
			db x = p[m].x;
			solve(l, m), solve(m + 1, r);
			merge(p + 1, p + m + 1, p + m + 1, p + r + 1, t, cmp);
			copy(t, t + r - l + 1, p + l);
			int siz = 0;
			for (int i = l; i <= r; ++i)
				if (sqr(p[i].x - x) < md) {
					for (int j = siz - 1; j >= 0 && sqr(p[i].y - t[j].y) < md; --j)
						upd(p[i], p[j]);
					t[siz] = p[i];
					++siz;
				}
		}
	}
};

Poi p[N];

int n, a[N];

int main() {
#ifdef lol
	freopen("429D.in", "r", stdin);
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		a[i] += a[i - 1];
	}
	for (int i = 1; i <= n; ++i)
		p[i] = Poi(i, a[i]);
	sort(p + 1, p + n + 1, [](const auto&a, const auto&b) {
			return sgn(a.x - b.x) < 0 || (sgn(a.x - b.x) == 0 && sgn(a.y - b.y) < 0);
			});
	NearestPair*solver = new NearestPair();
	copy(p + 1, p + n + 1, solver->p + 1);
	solver->solve(1, n);
	printf("%d\n", toInt(solver->md));

	return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N];
int n;
inline bool cmp(pii &a,pii &b){return a.se<b.se;}
ll solve(pii *a,int n)
{
    if(n<=1)return INF;
    int m=n/2,x=a[m].fi;
    ll d=min(solve(a,m),solve(a+m,n-m));
    inplace_merge(a,a+m,a+n,cmp);
    vector<pii>b;
    for(int i=0;i<n;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        for(int j=0;j<b.size();j++)
        {
            ll dx=a[i].fi-b[b.size()-j-1].fi;
            ll dy=a[i].se-b[b.size()-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b.pb(a[i]);
    }
    return d;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i].fi);
        if(i)a[i].fi+=a[i-1].fi;
        a[i].se=i;
    }
    sort(a,a+n);
    printf("%lld\n",solve(a,n));
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N],b[N];
int n;
ll solve(int l,int r)
{
    if(l>=r)return INF;
    int m=(l+r)>>1,x=a[m].fi;
    ll d=min(solve(l,m),solve(m+1,r));
    int cnt=l;
    for(int i=l,j=m+1;;)
    {
        if(i==m+1&&j==r+1)break;
        else if(i==m+1&&j!=r+1)b[cnt++]=a[j++];
        else if(i!=m+1&&j==r+1)b[cnt++]=a[i++];
        else
        {
            if(a[i].se<a[j].se)b[cnt++]=a[i++];
            else b[cnt++]=a[j++];
        }
    }
    for(int i=l;i<=r;i++)a[i]=b[i];
    cnt=0;
    for(int i=l;i<=r;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        for(int j=0;j<cnt;j++)
        {
            ll dx=a[i].fi-b[cnt-j-1].fi;
            ll dy=a[i].se-b[cnt-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b[cnt++]=a[i];
    }
    return d;
}
int main()
{
//    fin;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].fi),a[i].fi+=a[i-1].fi,a[i].se=i;
    sort(a+1,a+1+n);
    printf("%lld\n",solve(1,n));
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N];
int n;
bool cmp(pii a,pii b){return a.se<b.se;}
ll solve(int l,int r)
{
    if(l>=r)return INF;
    int m=(l+r)>>1,x=a[m].fi;
    ll d=min(solve(l,m),solve(m+1,r));
    inplace_merge(a+l,a+1+m,a+1+r,cmp);
    vector<pii>b;
    for(int i=l;i<=r;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        for(int j=0;j<min(10,b.size());j++)
        {
            ll dx=a[i].fi-b[b.size()-j-1].fi;
            ll dy=a[i].se-b[b.size()-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b.pb(a[i]);
    }
    return d;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].fi),a[i].fi+=a[i-1].fi,a[i].se=i;
    sort(a+1,a+1+n);
    printf("%lld\n",solve(1,n));
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N];
int n;
bool cmp(pii a,pii b){return a.se<b.se;}
ll solve(pii *a,int n)
{
    if(n<=1)return INF;
    int m=n/2,x=a[m].fi;
    ll d=min(solve(a,m),solve(a+m,n-m));
    inplace_merge(a,a+m,a+n,cmp);
    vector<pii>b;
    for(int i=0;i<n;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        for(int j=0;j<b.size();j++)
        {
            ll dx=a[i].fi-b[b.size()-j-1].fi;
            ll dy=a[i].se-b[b.size()-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b.pb(a[i]);
    }
    return d;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i].fi);
        if(i)a[i].fi+=a[i-1].fi;
        a[i].se=i;
    }
    sort(a,a+n);
    printf("%lld\n",solve(a,n));
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

struct FastIO {
    static const int S = 1e7;
    int wpos;
    char wbuf[S];
    FastIO() : wpos(0) {}
    inline int xchar() {
        static char buf[S];
        static int len = 0, pos = 0;
        if (pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if (pos == len) exit(0);
        return buf[pos++];
    }
    inline int xuint() {
        int c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x;
    }
    inline int xint()
    {
        int s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == '-') s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x * s;
    }
    inline void xstring(char *s)
    {
        int c = xchar();
        while (c <= 32) c = xchar();
        for (; c > 32; c = xchar()) * s++ = c;
        *s = 0;
    }
    inline void wchar(int x)
    {
        if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos++] = x;
    }
    inline void wint(ll x)
    {
        if (x < 0) wchar('-'), x = -x;
        char s[24];
        int n = 0;
        while (x || !n) s[n++] = '0' + x % 10, x /= 10;
        while (n--) wchar(s[n]);
        wchar('\n');
    }
    inline void wstring(const char *s)
    {
        while (*s) wchar(*s++);
    }
    ~FastIO()
    {
        if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;
int n,k,idx;
struct node{
    int f[2];
    bool operator <(const node&rhs)const{
        return f[idx]<rhs.f[idx];
    }
}a[N];
priority_queue<pair<ll,node> >q;
struct kdtree{
    bool vis[N<<2];
    node date[N<<2];
    void build(int l,int r,int rt,int dep)
    {
        if(l>r)return ;
        vis[rt]=1;
        vis[rt<<1]=vis[rt<<1|1]=0;
        idx=dep%k;
        int m=(l+r)>>1;
        nth_element(a+l,a+m,a+r+1);
        date[rt]=a[m];
        build(l,m-1,rt<<1,dep+1);
        build(m+1,r,rt<<1|1,dep+1);
    }
    void query(node p,int m,int rt,int dep)
    {
        if(!vis[rt])return ;
//        printf("%d \n",rt);
        pair<ll,node>cur(0,date[rt]);
        for(int i=0;i<k;i++)
            cur.fi+=1ll*(cur.se.f[i]-p.f[i])*(cur.se.f[i]-p.f[i]);
        int dim=dep%k;
        bool fg=0;
        int x=rt<<1,y=rt<<1|1;
        if(p.f[dim]>=date[rt].f[dim])swap(x,y);
        if(vis[x])query(p,m,x,dep+1);
        if(q.size()<m)q.push(cur),fg=1;
        else
        {
            if(cur.fi<q.top().fi)
            {
                q.pop();q.push(cur);
            }
            if(1ll*(p.f[dim]-date[rt].f[dim])*(p.f[dim]-date[rt].f[dim])<q.top().fi)fg=1;
        }
        if(vis[y]&&fg)query(p,m,y,dep+1);
    }
}kd;
int b[N];
int main()
{
    k=2;
    n=io.xint();
    for(int i=0;i<n;i++)
    {
        b[i]=io.xint();
        if(i)b[i]+=b[i-1];
        a[i].f[0]=b[i],a[i].f[1]=i;
    }
    kd.build(0,n-1,1,0);
    ll ans=INF;
    for(int i=0;i<n;i++)
    {
        kd.query(a[i],2,1,0);
        ans=min(ans,q.top().fi);
        q.pop();q.pop();
    }
    io.wint(ans);
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N],b[N];
int n;
ll solve(int l,int r)
{
    if(l>=r)return INF;
    int m=(l+r)>>1,x=a[m].fi;
    ll d=min(solve(l,m),solve(m+1,r));
    int cnt=l;
    for(int i=l,j=m+1;;)
    {
        if(i==m+1&&j==r+1)break;
        else if(i==m+1&&j!=r+1)b[cnt++]=a[j++];
        else if(i!=m+1&&j==r+1)b[cnt++]=a[i++];
        else
        {
            if(a[i].se<a[j].se)b[cnt++]=a[i++];
            else b[cnt++]=a[j++];
        }
    }
    for(int i=l;i<=r;i++)a[i]=b[i];
    cnt=0;
    for(int i=l;i<=r;i++)if(abs(a[i].fi-x)<=d)b[cnt++]=a[i];
    for(int i=0;i<cnt;i++)
        for(int j=max(0,i-6);j<i;j++)
            d=min(d,1ll*(a[i].fi-a[j].fi)*(a[i].fi-a[j].fi)+1ll*(a[i].se-a[j].se)*(a[i].se-a[j].se));
    return d;
}
int main()
{
//    fin;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].fi),a[i].fi+=a[i-1].fi,a[i].se=i;
    sort(a+1,a+1+n);
    printf("%lld\n",solve(1,n));
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N],b[N];
int n;
bool cmp(pii a,pii b){return a.se<b.se;}
ll solve(pii *a,int n)
{
    if(n<=1)return INF;
    int m=n/2,x=a[m].fi;
    ll d=min(solve(a,m),solve(a+m,n-m));
    inplace_merge(a,a+m,a+n,cmp);
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        for(int j=0;j<cnt;j++)
        {
            ll dx=a[i].fi-b[cnt-j-1].fi;
            ll dy=a[i].se-b[cnt-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b[cnt++]=a[i];
    }
    return d;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i].fi);
        if(i)a[i].fi+=a[i-1].fi;
        a[i].se=i;
    }
    sort(a,a+n);
    printf("%lld\n",solve(a,n));
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N],b[N];
int n;
ll solve(int l,int r)
{
    if(l>=r)return INF;
    int m=(l+r)>>1,x=a[m].fi;
    ll d=min(solve(l,m),solve(m+1,r));
    int cnt=l;
    for(int i=l,j=m+1;;)
    {
        if(i==m+1&&j==r+1)break;
        else if(i==m+1&&j!=r+1)b[cnt++]=a[j++];
        else if(i!=m+1&&j==r+1)b[cnt++]=a[i++];
        else
        {
            if(a[i].se<a[j].se)b[cnt++]=a[i++];
            else b[cnt++]=a[j++];
        }
    }
    for(int i=l;i<=r;i++)a[i]=b[i];
    cnt=0;
    for(int i=l;i<=r;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        int num=0;
        for(int j=0;j<min(10,cnt);j++)
        {
            num++;
            ll dx=a[i].fi-b[cnt-j-1].fi;
            ll dy=a[i].se-b[cnt-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
//        assert(num<=100);
        b[cnt++]=a[i];
    }
    return d;
}
int main()
{
//    fin;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].fi),a[i].fi+=a[i-1].fi,a[i].se=i;
    sort(a+1,a+1+n);
    printf("%lld\n",solve(1,n));
    return 0;
}
/********************

********************/


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

int n,k,idx;
struct node{
    int f[2];
    bool operator <(const node&rhs)const{
        return f[idx]<rhs.f[idx];
    }
}a[N];
priority_queue<pair<ll,node> >q;
struct kdtree{
    bool vis[N<<2];
    node date[N<<2];
    void build(int l,int r,int rt,int dep)
    {
        if(l>r)return ;
        vis[rt]=1;
        vis[rt<<1]=vis[rt<<1|1]=0;
        idx=dep%k;
        int m=(l+r)>>1;
        nth_element(a+l,a+m,a+r+1);
        date[rt]=a[m];
        build(l,m-1,rt<<1,dep+1);
        build(m+1,r,rt<<1|1,dep+1);
    }
    void query(node p,int m,int rt,int dep)
    {
        if(!vis[rt])return ;
//        printf("%d \n",rt);
        pair<ll,node>cur(0,date[rt]);
        for(int i=0;i<k;i++)
            cur.fi+=1ll*(cur.se.f[i]-p.f[i])*(cur.se.f[i]-p.f[i]);
        int dim=dep%k;
        bool fg=0;
        int x=rt<<1,y=rt<<1|1;
        if(p.f[dim]>=date[rt].f[dim])swap(x,y);
        if(vis[x])query(p,m,x,dep+1);
        if(q.size()<m)q.push(cur),fg=1;
        else
        {
            if(cur.fi<q.top().fi)
            {
                q.pop();q.push(cur);
            }
            if(1ll*(p.f[dim]-date[rt].f[dim])*(p.f[dim]-date[rt].f[dim])<q.top().fi)fg=1;
        }
        if(vis[y]&&fg)query(p,m,y,dep+1);
    }
}kd;
int b[N];
int main()
{
    k=2;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
        if(i)b[i]+=b[i-1];
        a[i].f[0]=b[i],a[i].f[1]=i;
    }
    kd.build(0,n-1,1,0);
    ll ans=INF;
    for(int i=0;i<n;i++)
    {
        assert(q.size()==0);
        kd.query(a[i],2,1,0);
        ans=min(ans,q.top().fi);
        q.pop();q.pop();
    }
    printf("%lld\n",ans);
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N];
int n;
bool cmp(pii a,pii b){return a.se<b.se;}
ll solve(int l,int r)
{
    if(l>=r)return INF;
    int m=(l+r)>>1,x=a[m].fi;
    ll d=min(solve(l,m),solve(m+1,r));
    inplace_merge(a+l,a+1+m,a+1+r,cmp);
    vector<pii>b;
    for(int i=l;i<=r;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        for(int j=0;j<b.size();j++)
        {
            ll dx=a[i].fi-b[b.size()-j-1].fi;
            ll dy=a[i].se-b[b.size()-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b.pb(a[i]);
    }
    return d;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].fi),a[i].fi+=a[i-1].fi,a[i].se=i;
    sort(a+1,a+1+n);
    printf("%lld\n",solve(1,n));
    return 0;
}
/********************

********************/


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

int n,k,idx;
struct node{
    int f[2];
    bool operator <(const node&rhs)const{
        return f[idx]<rhs.f[idx];
    }
}a[N];
priority_queue<pair<ll,node> >q;
struct kdtree{
    bool vis[N<<2];
    node date[N<<2];
    void build(int l,int r,int rt,int dep)
    {
        if(l>r)return ;
        vis[rt]=1;
        vis[rt<<1]=vis[rt<<1|1]=0;
        idx=dep%k;
        int m=(l+r)>>1;
        nth_element(a+l,a+m,a+r+1);
        date[rt]=a[m];
        build(l,m-1,rt<<1,dep+1);
        build(m+1,r,rt<<1|1,dep+1);
    }
    void query(node p,int m,int rt,int dep)
    {
        if(!vis[rt])return ;
//        printf("%d \n",rt);
        pair<ll,node>cur(0,date[rt]);
        for(int i=0;i<k;i++)
            cur.fi-=1ll*(cur.se.f[i]-p.f[i])*(cur.se.f[i]-p.f[i]);
        int dim=dep%k;
        bool fg=0;
        int x=rt<<1,y=rt<<1|1;
        if(p.f[dim]>=date[rt].f[dim])swap(x,y);
        if(vis[x])query(p,m,x,dep+1);
        if(q.size()<m)q.push(cur),fg=1;
        else
        {
            if(cur.fi<q.top().fi)
            {
                q.pop();q.push(cur);
            }
            if(1ll*(p.f[dim]-date[rt].f[dim])*(p.f[dim]-date[rt].f[dim])<q.top().fi)fg=1;
        }
        if(vis[y]&&fg)query(p,m,y,dep+1);
    }
}kd;
int b[N];
int main()
{
    k=2;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
        if(i)b[i]+=b[i-1];
        a[i].f[0]=b[i],a[i].f[1]=i;
    }
    kd.build(0,n-1,1,0);
    ll ans=INF;
    for(int i=0;i<n;i++)
    {
        kd.query(a[i],2,1,0);
//        printf("---%lld %d %d\n",-q.top().fi,q.top().se.f[0],q.top().se.f[1]);
        q.pop();
//        printf("+++%lld %d %d\n",-q.top().fi,q.top().se.f[0],q.top().se.f[1]);
        ans=min(ans,-q.top().fi);q.pop();
    }
    printf("%lld\n",ans);
    return 0;
}
/********************

********************/


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;

pii a[N];
int n;
bool cmp(pii a,pii b){return a.se<b.se;}
ll solve(int l,int r)
{
    if(l>=r)return INF;
    int m=(l+r)>>1,x=a[m].fi;
    ll d=min(solve(l,m),solve(m+1,r));
    inplace_merge(a+l,a+1+m,a+1+r,cmp);
    vector<pii>b;
    for(int i=l;i<=r;i++)
    {
        if(abs(a[i].fi-x)>=d)continue;
        for(int j=0;j<min(10,(int)b.size());j++)
        {
            ll dx=a[i].fi-b[b.size()-j-1].fi;
            ll dy=a[i].se-b[b.size()-j-1].se;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b.pb(a[i]);
    }
    return d;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].fi),a[i].fi+=a[i-1].fi,a[i].se=i;
    sort(a+1,a+1+n);
    printf("%lld\n",solve(1,n));
    return 0;
}
/********************

********************/


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    ll x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.y;
}

// A utility function to find the distance between two points
inline 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
inline ll bruteForce(Point P[], int n)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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
inline ll stripClosest(Point strip[], int sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    // 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
    int cnt=0;
    for (int i = 0; i < sizee; ++i)
    {
        cnt = 0;
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
        {
            mini = min(dist(strip[i], strip[j]), mini);
            cnt++;
            if(cnt>=15) break;
        }

        //assert(cnt<=10);

       // cout<<"cnt "<<cnt<< " "<<sizee<<endl;

    }
   //
    //

    return mini;
}

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

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

    // Divide points in y sorted array around the vertical line.
    // Assumption: All x coordinates are distinct.
    Point Pyl[mid+1];   // y sorted points on left of vertical line
    Point Pyr[n-mid-1];  // y sorted points on right of vertical line
    int li = 0, ri = 0;  // indexes of left and right subarrays
    for (int i = 0; i < n; i++)
    {
      if (Py[i].x <= midPoint.x)
         Pyl[li++] = Py[i];
      else
         Pyr[ri++] = Py[i];
    }
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    long long dl = closestUtil(Px, Pyl, mid);
    long long dr = closestUtil(Px+mid, Pyr, 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 (Py[i].x - midPoint.x < d)
        {
            strip[j] = Py[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) );
}

ll cum[100005];

int main()
{
    int n, a[100005];
    scanf("%d",&n);
    rept(i,0,n) scanf("%d",&a[i]);
    int i = 0, j = 0, curmin = 0;
    ll mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point px[100005],py[100005];
    for(int i=0;i<n;i++)
    {
        px[i] = Point(i,cum[i]);
        py[i] = Point(i,cum[i]);
    }
    sort(px,px+n,compareX);
    sort(py,py+n,compareY);
    printf("%lld\n",closestUtil(px,py,n));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    ll x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.y;
}

// A utility function to find the distance between two points
inline 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
inline ll bruteForce(Point P[], int n)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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
inline ll stripClosest(Point strip[], int sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    // 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
    int cnt=0;
    for (int i = 0; i < sizee; ++i)
    {
        cnt = 0;
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
        {
            mini = min(dist(strip[i], strip[j]), mini);
            cnt++;
        }
        assert(cnt<=10);

       // cout<<"cnt "<<cnt<< " "<<sizee<<endl;

    }
   //
    //

    return mini;
}

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

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

    // Divide points in y sorted array around the vertical line.
    // Assumption: All x coordinates are distinct.
    Point Pyl[mid+1];   // y sorted points on left of vertical line
    Point Pyr[n-mid-1];  // y sorted points on right of vertical line
    int li = 0, ri = 0;  // indexes of left and right subarrays
    for (int i = 0; i < n; i++)
    {
      if (Py[i].x <= midPoint.x)
         Pyl[li++] = Py[i];
      else
         Pyr[ri++] = Py[i];
    }
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    long long dl = closestUtil(Px, Pyl, mid);
    long long dr = closestUtil(Px+mid, Pyr, 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 (Py[i].x - midPoint.x < d)
        {
            strip[j] = Py[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) );
}

ll cum[100005];

int main()
{
    int n, a[100005];
    scanf("%d",&n);
    rept(i,0,n) scanf("%d",&a[i]);
    int i = 0, j = 0, curmin = 0;
    ll mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point px[100005],py[100005];
    for(int i=0;i<n;i++)
    {
        px[i] = Point(i,cum[i]);
        py[i] = Point(i,cum[i]);
    }
    sort(px,px+n,compareX);
    sort(py,py+n,compareY);
    printf("%lld\n",closestUtil(px,py,n));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    int x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.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)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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 sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    sort(strip, strip+sizee, 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 < sizee; ++i)
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
                mini = min(dist(strip[i], strip[j]), mini);

    return mini;
}

// 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
    long long dl = closestUtil(P, mid);
    long long 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) );
}

int cum[100005];

int main()
{
    int n, a[100005];
    cin>>n;
    rept(i,0,n) cin>>a[i];
    int i = 0, j = 0, curmin = 0, mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point p[100005];
    for(int i=0;i<n;i++)
    {
        p[i] = Point(i,cum[i]);
    }
    cout<<closestUtil(p,n)<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    ll x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.y;
}

// A utility function to find the distance between two points
inline 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
inline ll bruteForce(Point P[], int n)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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
inline ll stripClosest(Point strip[], int sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    // 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 < sizee; ++i)
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
                mini = min(dist(strip[i], strip[j]), mini);

    return mini;
}

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

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

    // Divide points in y sorted array around the vertical line.
    // Assumption: All x coordinates are distinct.
    Point Pyl[mid+1];   // y sorted points on left of vertical line
    Point Pyr[n-mid-1];  // y sorted points on right of vertical line
    int li = 0, ri = 0;  // indexes of left and right subarrays
    for (int i = 0; i < n; i++)
    {
      if (Py[i].x <= midPoint.x)
         Pyl[li++] = Py[i];
      else
         Pyr[ri++] = Py[i];
    }
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    long long dl = closestUtil(Px, Pyl, mid);
    long long dr = closestUtil(Px+mid, Pyr, 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 (Py[i].x - midPoint.x < d)
        {
            strip[j] = Py[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) );
}

ll cum[100005];

int main()
{
    int n, a[100005];
    scanf("%d",&n);
    rept(i,0,n) scanf("%d",&a[i]);
    int i = 0, j = 0, curmin = 0;
    ll mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point px[100005],py[100005];
    for(int i=0;i<n;i++)
    {
        px[i] = Point(i,cum[i]);
        py[i] = Point(i,cum[i]);
    }
    sort(px,px+n,compareX);
    sort(py,py+n,compareY);
    printf("%lld\n",closestUtil(px,py,n));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    ll x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.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)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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 sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    // 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 < sizee; ++i)
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
                mini = min(dist(strip[i], strip[j]), mini);

    return mini;
}

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

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

    // Divide points in y sorted array around the vertical line.
    // Assumption: All x coordinates are distinct.
    Point Pyl[mid+1];   // y sorted points on left of vertical line
    Point Pyr[n-mid-1];  // y sorted points on right of vertical line
    int li = 0, ri = 0;  // indexes of left and right subarrays
    for (int i = 0; i < n; i++)
    {
      if (Py[i].x <= midPoint.x)
         Pyl[li++] = Py[i];
      else
         Pyr[ri++] = Py[i];
    }
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    long long dl = closestUtil(Px, Pyl, mid);
    long long dr = closestUtil(Px+mid, Pyr, 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 (Py[i].x - midPoint.x < d)
        {
            strip[j] = Py[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) );
}

ll cum[100005];

int main()
{
    int n, a[100005];
    scanf("%d",&n);
    rept(i,0,n) scanf("%d",&a[i]);
    int i = 0, j = 0, curmin = 0;
    ll mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point px[100005],py[100005];
    for(int i=0;i<n;i++)
    {
        px[i] = Point(i,cum[i]);
        py[i] = Point(i,cum[i]);
    }
    sort(px,px+n,compareX);
    sort(py,py+n,compareY);
    printf("%lld\n",closestUtil(px,py,n));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    ll x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.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)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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 sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    sort(strip, strip+sizee, 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 < sizee; ++i)
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
                mini = min(dist(strip[i], strip[j]), mini);

    return mini;
}

// 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
    long long dl = closestUtil(P, mid);
    long long 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) );
}

ll cum[100005];

int main()
{
    int n, a[100005];
    cin>>n;
    rept(i,0,n) cin>>a[i];
    int i = 0, j = 0, curmin = 0, mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point p[100005];
    for(int i=0;i<n;i++)
    {
        p[i] = Point(i,cum[i]);
    }
    cout<<closestUtil(p,n)<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    ll x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.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)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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 sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    // 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 < sizee; ++i)
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
                mini = min(dist(strip[i], strip[j]), mini);

    return mini;
}

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

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

    // Divide points in y sorted array around the vertical line.
    // Assumption: All x coordinates are distinct.
    Point Pyl[mid+1];   // y sorted points on left of vertical line
    Point Pyr[n-mid-1];  // y sorted points on right of vertical line
    int li = 0, ri = 0;  // indexes of left and right subarrays
    for (int i = 0; i < n; i++)
    {
      if (Py[i].x <= midPoint.x)
         Pyl[li++] = Py[i];
      else
         Pyr[ri++] = Py[i];
    }
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    long long dl = closestUtil(Px, Pyl, mid);
    long long dr = closestUtil(Px+mid, Pyr, 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 (Py[i].x - midPoint.x < d)
        {
            strip[j] = Py[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) );
}

ll cum[100005];

int main()
{
    int n, a[100005];
    scanf("%d",&n);
    rept(i,0,n) scanf("%d",&a[i]);
    int i = 0, j = 0, curmin = 0, mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point px[100005],py[100005];
    for(int i=0;i<n;i++)
    {
        px[i] = Point(i,cum[i]);
        py[i] = Point(i,cum[i]);
    }
    sort(px,px+n,compareX);
    sort(py,py+n,compareY);
    printf("%lld\n",closestUtil(px,py,n));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs)
#define CASE(cs) printf("Case %d: ",cs)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second

typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

//bitmask//
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
////////////////////////////////////////////////////////

struct Point
{
    ll x, y;
    Point(){}
    Point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

// Needed to sort array of points according to X coordinate
bool compareX(Point a, Point b)
{
    return a.x<b.x;
}
// Needed to sort array of points according to Y coordinate
bool compareY(Point a, Point b)
{
    return a.y<b.y;
}

// A utility function to find the distance between two points
inline 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
inline ll bruteForce(Point P[], int n)
{
    long long mini = LONG_MAX;
    for (int i = 0; i < n; ++i)
        for (int j = i+1; j < n; ++j)
                mini = min(dist(P[i], P[j]), mini);
    return mini;
}

// 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
inline ll stripClosest(Point strip[], int sizee, ll d)
{
    long long mini = d;  // Initialize the minimum distance as d

    // 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
    int cnt=0;
    for (int i = 0; i < sizee; ++i)
    {
        for (int j = i+1; j < sizee && (strip[j].y - strip[i].y) < mini; ++j)
        {
            mini = min(dist(strip[i], strip[j]), mini);
            cnt++;
        }

    }
    assert(cnt<=10);

    return mini;
}

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

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

    // Divide points in y sorted array around the vertical line.
    // Assumption: All x coordinates are distinct.
    Point Pyl[mid+1];   // y sorted points on left of vertical line
    Point Pyr[n-mid-1];  // y sorted points on right of vertical line
    int li = 0, ri = 0;  // indexes of left and right subarrays
    for (int i = 0; i < n; i++)
    {
      if (Py[i].x <= midPoint.x)
         Pyl[li++] = Py[i];
      else
         Pyr[ri++] = Py[i];
    }
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    long long dl = closestUtil(Px, Pyl, mid);
    long long dr = closestUtil(Px+mid, Pyr, 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 (Py[i].x - midPoint.x < d)
        {
            strip[j] = Py[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) );
}

ll cum[100005];

int main()
{
    int n, a[100005];
    scanf("%d",&n);
    rept(i,0,n) scanf("%d",&a[i]);
    int i = 0, j = 0, curmin = 0;
    ll mini = LONG_MAX;

    cum[0] = a[i];
    for(int i=1;i<n;i++)
    {
        cum[i] = a[i] + cum[i-1];
    }
    Point px[100005],py[100005];
    for(int i=0;i<n;i++)
    {
        px[i] = Point(i,cum[i]);
        py[i] = Point(i,cum[i]);
    }
    sort(px,px+n,compareX);
    sort(py,py+n,compareY);
    printf("%lld\n",closestUtil(px,py,n));

    return 0;
}


#include <bits/stdc++.h>

#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define sz(s) (int)s.size()
#define all(x) x.bg, x.en
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rbg rbegin()
#define bg begin()
#define en end()
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 265;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 1e5 + 11, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

struct point {
	int x, y;
} b[N], c[N];

int n, a[N], ans = INF;

int dist (point a, point b) {
	return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

bool cmp (point a, point b) {
	return a.y < b.y;
}

void calc (int tl, int tr) {
	if (tr - tl <= 3) {
		forn (i, tl, tr)
			forn (j, i + 1, tr)
				ans = min(ans, dist(b[i], b[j]));
		sort(b + tl, b + tr + 1, cmp);
		return;
	}
	int tm = (tl + tr) >> 1, midx = b[tm].x;
	calc(tl, tm);
	calc(tm + 1, tr);
	//merge
	int j1 = tl, j2 = tm + 1, j3 = 0;
	while (1) {
		if (j1 == tm + 1 && j2 == tr + 1)
			break;
		if (j1 <= tm && (j2 == tr + 1 || b[j1].y < b[j2].y))
			c[++j3] = b[j1++];
		else
			c[++j3] = b[j2++];
	}

	//copy
	forn (i, 1, j3)
		b[i + tl - 1] = c[i];

	//the most important part
	j3 = 0;
	forn (i, tl, tr)
		if ((b[i].x - midx) * (b[i].x - midx) < ans) {
			forev (j, j3, 1)  {
				if ((b[i].y - c[j].y) * (b[i].y - c[j].y)  >= ans)
					break;
				ans = min(ans, dist(b[i], c[j]));
			}
			c[++j3] = b[i];
		}
}

main () {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	file("");
	cin >> n;
	forn (i, 1, n) {
		cin >> a[i];
		a[i] += a[i - 1];
		b[i].x = i, b[i].y = a[i];
	}
	calc(1, n);
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define sz(s) (int)s.size()
#define all(x) x.bg, x.en
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rbg rbegin()
#define bg begin()
#define en end()
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 265;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 1e5 + 11, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

struct point {
	int x, y;
} b[N], c[N];

int n, a[N], ans = INF;

int dist (point a, point b) {
	return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

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

bool cmpy (point a, point b) {
	return a.y < b.y;
}

void calc (int tl, int tr) {
	if (tr - tl <= 3) {
		forn (i, tl, tr)
			forn (j, i + 1, tr)
				ans = min(ans, dist(b[i], b[j]));
		sort(b + tl, b + tr - 1, cmpy);
		return;
	}
	int tm = (tl + tr) >> 1, midx = b[tm].x;
	calc(tl, tm);
	calc(tm + 1, tr);
	//merge
	int j1 = tl, j2 = tm + 1, j3 = 0;
	while (1) {
		if (j1 == tm + 1 && j2 == tr + 1)
			break;
		if (j1 <= tm && (j2 == tr + 1 || b[j1].y < b[j2].y))
			c[++j3] = b[j1++];
		else
			c[++j3] = b[j2++];
	}

	//copy
	forn (i, 1, tr - tl + 1)
		b[i + tl - 1] = c[i];

	//the most important part
	j3 = 0;
	forn (i, tl, tr)
		if ((b[i].x - midx) * (b[i].x - midx) < ans) {
			forn (j, j3, 1)  {
				if ((b[i].y - c[j].y) * (b[i].y - c[j].y)  >= ans)
					break;
				ans = min(ans, dist(b[i], c[j]));
			}
			c[++j3] = b[i];
		}
}

main () {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	forn (i, 1, n) {
		cin >> a[i];
		a[i] += a[i - 1];
		b[i].x = i, b[i].y = a[i];
	}
	calc(1, n);
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define sz(s) (int)s.size()
#define all(x) x.bg, x.en
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rbg rbegin()
#define bg begin()
#define en end()
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 265;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 1e5 + 11, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

struct point {
	int x, y;
} b[N], c[N];

int n, a[N], ans = INF;

int dist (point a, point b) {
	return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

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

bool cmpy (point a, point b) {
	return a.y < b.y;
}

void calc (int tl, int tr) {
	if (tr - tl <= 3) {
		forn (i, tl, tr)
			forn (j, i + 1, tr)
				ans = min(ans, dist(b[i], b[j]));
		sort(b + tl, b + tr - 1, cmpy);
		return;
	}
	int tm = (tl + tr) >> 1, midx = b[tm].x;
	calc(tl, tm);
	calc(tm + 1, tr);
	//merge
	int j1 = tl, j2 = tm + 1, j3 = 0;
	while (1) {
		if (j1 == tm + 1 && j2 == tr + 1)
			break;
		if (j1 <= tm && (j2 == tr || b[j1].y < b[j2].y))
			c[++j3] = b[j1++];
		else
			c[++j3] = b[j2++];
	}

	//copy
	forn (i, 1, tr - tl + 1)
		b[i + tl - 1] = c[i];

	//the most important part
	j3 = 0;
	forn (i, tl, tr)
		if ((b[i].x - midx) * (b[i].x - midx) < ans) {
			forn (j, j3, 1)
				ans = min(ans, dist(b[i], c[j]));
			c[++j3] = b[i];
		}
}

main () {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	forn (i, 1, n) {
		cin >> a[i];
		a[i] += a[i - 1];
		b[i].x = i, b[i].y = a[i];
	}
	calc(1, n);

	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define sz(s) (int)s.size()
#define all(x) x.bg, x.en
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rbg rbegin()
#define bg begin()
#define en end()
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 265;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 1e5 + 11, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

struct point {
	int x, y;
} b[N], c[N];

int n, a[N], ans = INF;

int dist (point a, point b) {
	return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

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

bool cmpy (point a, point b) {
	return a.y < b.y;
}

void calc (int tl, int tr) {
	if (tr - tl <= 3) {
		forn (i, tl, tr)
			forn (j, i + 1, tr)
				ans = min(ans, dist(b[i], b[j]));
		sort(b + tl, b + tr - 1, cmpy);
		return;
	}
	int tm = (tl + tr) >> 1, midx = b[tm].x;
	calc(tl, tm);
	calc(tm + 1, tr);
	//merge
	int j1 = tl, j2 = tm + 1, j3 = 0;
	while (1) {
		if (j1 == tm + 1 && j2 == tr + 1)
			break;
		if (j1 <= tm && (j2 == tr || b[j1].y < b[j2].y))
			c[++j3] = b[j1++];
		else
			c[++j3] = b[j2++];
	}

	//copy
	forn (i, 1, tr - tl + 1)
		b[i + tl - 1] = c[i];

	//the most important part
	j3 = 0;
	forn (i, tl, tr)
		if ((b[i].x - midx) * (b[i].x - midx) < ans) {
			forn (j, j3, 1)  {
				if ((b[i].y - c[j].y) * (b[i].y - c[j].y)  >= ans)
					break;
				ans = min(ans, dist(b[i], c[j]));
			}
			c[++j3] = b[i];
		}
}

main () {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	forn (i, 1, n) {
		cin >> a[i];
		a[i] += a[i - 1];
		b[i].x = i, b[i].y = a[i];
	}
	calc(1, n);
	cout << ans << endl;
	return 0;
}


#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].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){
    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 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].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){
    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(1ll * (i - mid) * (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,l,r)
        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,l,r) 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(a[i], 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);
*/