#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)1e5 + 123;
const int inf = (int)1e9 + 7;
int n;
pair<int, int> a[MAX_N];
long long dist(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 cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
pair<int, int> shit[MAX_N];
long long solve(int l, int r) {
  if (l == r) return 1e18;
  int mid = (l + r) / 2;
  long long res = min(solve(l, mid), solve(mid + 1, r));
  for (int i = l, j = mid + 1; i <= mid; i++) {
    while (j <= r && a[j].second <= a[i].second) j++;
    for (int k = max(mid + 1, j - 10); k <= min(r, j + 10); k++)
      res = min(res, dist(a[i], a[k]));
  }
  merge(a + l, a + mid + 1, a + mid + 1, a + r + 1, shit, cmp);
  for (int i = l; i <= r; i++) a[i] = shit[i - l];
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].second);
    a[i].first = i;
  }
  for (int i = 1; i <= n; i++) a[i].second += a[i - 1].second;
  printf("%lld", solve(1, n));
  return 0;
}
