#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 123;
int n;
int a[maxn];
long long psum[maxn];
int idx[maxn];
int temps[maxn];
int tot;
long long dis(int i, int j) {
  return (long long)(i - j) * (i - j) +
         (long long)(psum[i] - psum[j]) * (psum[i] - psum[j]);
}
inline long long qmin(long long a, long long b) { return (a > b) ? (b) : (a); }
inline long long qabs(long long a) { return (a > 0) ? a : (-a); }
bool cmp(int i, int j) { return psum[i] < psum[j]; }
long long nearestP(int l, int r) {
  if (l == r) return LLONG_MAX;
  int mid = (l + r) >> 1;
  long long res = qmin(nearestP(l, mid), nearestP(mid + 1, r));
  int midi = idx[mid];
  inplace_merge(idx + l, idx + mid + 1, idx + r + 1, cmp);
  tot = 0;
  long long mind = res;
  for (int i = l; i <= r; ++i)
    if ((long long)(idx[i] - midi) * (idx[i] - midi) <= mind) {
      for (int j = tot - 1; j >= 0 && (psum[idx[i]] - psum[temps[j]]) *
                                              (psum[idx[i]] - psum[temps[j]]) <=
                                          mind;
           --j)
        res = qmin(res, dis(temps[j], idx[i]));
      temps[tot++] = idx[i];
    }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    idx[i] = i;
  }
  psum[0] = a[0];
  for (int i = 1; i < n; ++i) psum[i] = psum[i - 1] + a[i];
  cout << nearestP(0, n - 1) << endl;
  return 0;
}
