#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
long long pu[100001], pd[100001], iu[100001], id[100001];
long long sum[100001], ar[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a = 0, b, c, d, e = 0, f = 0, g, h = 0, x, y, z;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    cin >> ar[i];
    sum[i] = sum[i - 1] + ar[i];
  }
  h = (20000 * 20000) + 1;
  for (int i = 1; i <= 500; i++) {
    for (int j = 1; j <= a - i; j++) {
      h = min(h, (sum[j + i] - sum[j]) * (sum[j + i] - sum[j]) +
                     (long long)(i) * (long long)(i));
    }
  }
  cout << h << endl;
}
