#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const double PI = 3.1415926535897932384626433832795;
inline int get_int() {
  int res, t = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-') t = -1;
  for (res = c - '0'; isdigit(c = getchar());) res = res * 10 + c - '0';
  return res * t;
}
const int MAXN = 100000;
int n;
int A[MAXN + 10], S[MAXN + 10];
pair<int, int> a[MAXN + 10];
long long len(pair<int, int> &a, pair<int, int> &b) {
  return (1LL * (a.first - b.first) * (a.first - b.first)) +
         (1LL * (a.second - b.second) * (a.second - b.second));
}
bool cmpy(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
long long Find(int l, int r) {
  if (l == r) return LONG_LONG_MAX;
  if (l + 1 == r) return len(a[l], a[r]);
  int mid = l + r >> 1;
  long long d1 = Find(l, mid);
  long long d2 = Find(mid + 1, r);
  long long s = min(d1, d2);
  static pair<int, int> tmp[MAXN + 10];
  int tot = 0;
  for (int i = l; i <= r; i++) {
    if (abs(a[i].first - a[mid].first) < s) tmp[tot++] = a[i];
  }
  sort(tmp, tmp + tot, cmpy);
  for (int i = 0; i < (int)(tot); i++) {
    for (int j = min(tot, i + 8) - 1; j > i; j--)
      s = min(s, len(tmp[i], tmp[j]));
  }
  return s;
}
int main() {
  n = get_int();
  for (int i = 1; i <= n; i++) S[i] = S[i - 1] + (A[i] = get_int());
  for (int i = 1; i <= n; i++) a[i] = pair<int, int>(i, S[i]);
  sort(a + 1, a + 1 + n);
  cout << Find(1, n) << endl;
  return 0;
}
