#include <bits/stdc++.h>
using namespace std;
template <class Num>
inline void read(Num &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
}
template <class Num>
inline void write(Num x) {
  if (x < 0) putchar('-'), x = -x;
  static char s[20];
  int sl = 0;
  while (x) s[sl++] = x % 10 + '0', x /= 10;
  if (!sl) {
    putchar('0');
    return;
  }
  while (sl) putchar(s[--sl]);
}
template <typename T>
bool chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int MAXN = 100000 + 100;
long long sum[MAXN], A[MAXN];
int N;
void init() {
  sum[0] = 0;
  for (int i = 1; i <= N; ++i)
    scanf("%I64d", &A[i]), sum[i] = sum[i - 1] + A[i];
}
void solve() {
  long long ans = A[2] * A[2] + 1, tmp;
  for (int i = 1; i <= N; ++i) {
    if ((long long)i * i >= ans) break;
    tmp = ans;
    for (int j = i + 1; j <= N; ++j) {
      chkmin(tmp, (sum[j] - sum[j - i]) * (sum[j] - sum[j - i]));
    }
    chkmin(ans, tmp + i * i);
  }
  printf("%I64d\n", ans);
}
int main() {
  while (scanf("%d", &N) == 1) {
    init();
    solve();
  }
  return 0;
}
