#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
int n;
long long a[N], sum[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  long long ans = INF;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n && j < i + 1100; j++) {
      ans = min(ans, 1ll * (j - i) * (j - i) +
                         1ll * (sum[j] - sum[i]) * (sum[j] - sum[i]));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
