#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18;
long long csqrt(long long x) {
  long long r = sqrt(x);
  while (r * r < x) r++;
  while (r * r > x) r--;
  return r;
}
long long sq(long long x) { return x * x; }
long long closestPoints(vector<complex<long long> > points) {
  int n = points.size();
  vector<pair<long long, long long> > ps(n);
  for (int i = 0; i < n; i++) {
    ps[i] = {points[i].real(), points[i].imag()};
  }
  sort(ps.begin(), ps.end());
  int i2 = 0;
  long long d = inf;
  set<pair<long long, long long> > pss;
  for (int i = 0; i < n; i++) {
    while (i2 < i && sq(ps[i].first - ps[i2].first) > d) {
      pss.erase({ps[i2].second, ps[i2].first});
      i2++;
    }
    auto it = pss.lower_bound({ps[i].second - csqrt(d), -inf});
    for (; it != pss.end(); it++) {
      if (sq(it->first - ps[i].second) > d) break;
      d = min(d, sq(it->first - ps[i].second) + sq(it->second - ps[i].first));
    }
    pss.insert({ps[i].second, ps[i].first});
  }
  return d;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<complex<long long> > ps(n);
  long long s = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    s += x;
    ps[i] = {s, i};
  }
  cout << closestPoints(ps) << endl;
}
