#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
pair<long long int, long long int> a[N];
pair<long long int, long long int> Y[N];
int x1, y3, x2, y2;
long long int x = 1000 * 1000 * 1000;
long long int halal(long long int l, long long int r) {
  if (r - l <= 1) {
    return 1000 * 1000 * 1000;
  }
  if (r - l == 2) {
    r--;
    if ((a[r].first - a[l].first) * (a[r].first - a[l].first) +
            (a[r].second - a[l].second) * (a[r].second - a[l].second) <
        x) {
      x = (a[r].first - a[l].first) * (a[r].first - a[l].first) +
          (a[r].second - a[l].second) * (a[r].second - a[l].second);
      x1 = a[r].first;
      x2 = a[l].first;
      y3 = a[r].second;
      y2 = a[l].second;
    }
    setprecision(6);
    return (a[r].first - a[l].first) * (a[r].first - a[l].first) +
           (a[r].second - a[l].second) * (a[r].second - a[l].second);
  }
  long long int mid = (r + l) / 2;
  x = min(x, min(halal(l, mid), halal(mid, r)));
  vector<pair<long long int, long long int> > v;
  vector<pair<long long int, long long int> > u;
  long long int p4 = 0, p5 = 0;
  for (long long int i = l; i < r; i++) {
    if (i >= mid) {
      if (a[i].first - a[mid].first < x) {
        u.push_back(make_pair(a[i].second, a[i].first));
      }
    } else {
      if (a[mid].first - a[i].first < x) {
        v.push_back(make_pair(a[i].second, a[i].first));
      }
    }
  }
  if (v.size() > 0) {
    sort(v.begin(), v.end());
  }
  if (u.size() > 0) {
    sort(u.begin(), u.end());
  }
  long long int k = v.size();
  long long int s = u.size(), p2 = 0;
  long long int p1;
  for (long long int i = 0; i < k; i++) {
    while (p2 < s && (p2 - 7 < 0 || u[p2 - 7].first < v[i].first)) {
      p2++;
    }
    p2 = max((long long)0, p2 - 14);
    for (long long int j = p2; j < min(s, p2 + 15); j++) {
      setprecision(6);
      p1 = (v[i].first - u[j].first) * (v[i].first - u[j].first) +
           (v[i].second - u[j].second) * (v[i].second - u[j].second);
      if (p1 < x) {
        y3 = v[i].first;
        y2 = u[j].first;
        x1 = v[i].second;
        x2 = u[j].second;
        x = p1;
      }
    }
  }
  return x;
}
int main() {
  long long int n, d, q = 0;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> d;
    q += d;
    a[i] = make_pair(i, q);
    Y[i] = make_pair(i, q);
  }
  sort(a, a + n);
  long long int jh = halal(0, n);
  long long int p1 = 0, p2 = 0;
  for (long long int i = 0; i < n; i++) {
    if (x1 == Y[i].first && y3 == Y[i].second) {
      p1 = i;
    }
    if (x2 == Y[i].first && y2 == Y[i].second) {
      p2 = i;
    }
  }
  cout << jh;
}
