#include <bits/stdc++.h>
long long min(long long a, long long b) { return a < b ? a : b; }
int aa[100000], ii[100000], jj[100000];
void merge(int l, int m, int r) {
  int o, p, q, i;
  o = l, p = l, q = m;
  while (p < m && q < r)
    if (aa[jj[p]] <= aa[jj[q]])
      ii[o++] = jj[p++];
    else
      ii[o++] = jj[q++];
  while (p < m) ii[o++] = jj[p++];
  while (q < r) ii[o++] = jj[q++];
  for (i = l; i < r; i++) jj[i] = ii[i];
}
long long solve(int l, int r) {
  int m, n, h, h_, i, j;
  long long d0, d1, d, x, y;
  if (r - l == 1) {
    jj[l] = l;
    return 0x3f3f3f3f3f3f3f3fLL;
  }
  m = (l + r) / 2;
  d0 = solve(l, m);
  d1 = solve(m, r);
  d = min(d0, d1);
  merge(l, m, r);
  n = 0;
  for (i = l; i < r; i++) {
    j = jj[i];
    x = j - m;
    if (x * x <= d) ii[n++] = j;
  }
  for (h = 0; h < n; h++) {
    i = ii[h];
    for (h_ = h + 1; h_ < n; h_++) {
      j = ii[h_];
      y = aa[j] - aa[i];
      if (y * y >= d) break;
      x = j - i;
      d = min(d, x * x + y * y);
    }
  }
  return d;
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &aa[i]);
  for (i = 1; i < n; i++) aa[i] += aa[i - 1];
  printf("%lld\n", solve(0, n));
  return 0;
}
