#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 100000000;
inline int fastMin(int x, int y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;
}
inline int fastMax(int x, int y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;
}
inline long long fastMin(long long x, long long y) {
  return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x;
}
inline long long fastMax(long long x, long long y) {
  return (((y - x) >> (64 - 1)) & (x ^ y)) ^ y;
}
inline int fastAbs(int x) { return ((x >> (32 - 1)) & (x ^ (-x))) ^ x; }
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int n;
int a[((int)1e5)];
int sm[((int)1e5) + 1];
int main() {
  scanf("%d", &n);
  {
    int tmp;
    scanf("%d", &tmp);
  }
  n--;
  for (int i = 0; i < (n); i++) scanf("%d", a + i);
  for (int i = 0; i < (n); i++) sm[i + 1] = sm[i] + a[i];
  int mn = 10000 * 10000 + 1;
  const int diff_max = min(10020, n);
  for (int diff = 1; diff <= diff_max; diff++) {
    if (mn <= diff * diff) break;
    int t = abs(sm[diff]);
    const int i_max = n - diff;
    for (int i = 1; i <= i_max; i++) {
      int val = sm[i + diff] - sm[i];
      t = min(t, abs(val));
    }
    if (t > 10000) continue;
    mn = min(mn, diff * diff + t * t);
  }
  cout << mn << endl;
  return 0;
}
