#include <bits/stdc++.h>
using namespace std;
long long S[100000];
pair<long long, long long> ps[100000];
pair<long long, long long> tmp[100000];
int n;
long long D(pair<long long, long long> a, pair<long long, long long> b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}
long long h(int p, int q) {
  long long ret = 1LL << 60;
  if (q - p <= 2) {
    for (int i = p; i < q; i++) {
      for (int j = i + 1; j <= q; j++) {
        ret = min(ret, (j - i) * (j - i) + (S[j] - S[i]) * (S[j] - S[i]));
      }
    }
    sort(ps + p, ps + q + 1);
    return ret;
  }
  int m = (p + q) / 2;
  ret = min(h(p, m), h(m + 1, q));
  int h0 = p;
  int h1 = m + 1;
  int t = 0;
  while (h0 <= m && h1 <= q) {
    if (ps[h0].first <= ps[h1].first) {
      tmp[t++] = ps[h0++];
    } else {
      tmp[t++] = ps[h1++];
    }
  }
  while (h0 <= m) tmp[t++] = ps[h0++];
  while (h1 <= q) tmp[t++] = ps[h1++];
  int tt = 0;
  long long sq = sqrt(ret);
  for (int i = 0; i < t; i++) {
    ps[p + i] = tmp[i];
    if (m - sq <= tmp[i].second && tmp[i].second <= m + sq) {
      tmp[tt++] = tmp[i];
    }
  }
  for (int i = 0; i < tt; i++) {
    for (int j = i + 1; j <= i + 7 && j < tt; j++) {
      ret = min(ret, D(tmp[i], tmp[j]));
    }
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  int s = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    S[i] = s = s + a;
    ps[i] = pair<long long, long long>(s, i);
  }
  long long ret = h(0, n - 1);
  cout << ret << endl;
}
