#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
const int N = 100007;
const int Q = 500;
int n;
long long a[N], s[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    a[i] = x;
    s[i] = a[i] + s[i - 1];
  }
  long long ans = 1LL << 58;
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j < i + 1 + Q && j <= n; ++j)
      ans = min(ans, (j - i) * (j - i) + (s[j] - s[i]) * (s[j] - s[i]));
  printf("%I64d\n", ans);
  return 0;
}
