#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
int a[MaxN];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  long long best = -1;
  for (int k = 1; k <= min(n - 1, 4000); k++) {
    int sum = 0;
    for (int j = 1; j <= k; j++) sum += a[j];
    int tmp = -1;
    for (int j = k + 1; j <= n; j++) {
      sum += a[j] - a[j - k];
      if (tmp == -1 || tmp > abs(sum)) tmp = abs(sum);
    }
    long long TMP = (long long)k * k + (long long)tmp * tmp;
    if (best == -1 || best > TMP) best = TMP;
  }
  printf("%I64d\n", best);
  return 0;
}
