#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct pii {
  int x, y;
};
int A[MAXN], N, pre[MAXN];
long long sq(long long x) { return x * x; }
bool comp1(pii a, pii b) { return a.x < b.x; }
bool comp2(pii a, pii b) { return a.y < b.y; }
long long dist(pii a, pii b) { return sq(a.x - b.x) + sq(a.y - b.y); }
int brute(pii S[], int N) {
  long long cd = 10000000000000000LL;
  for (int i = 0; i < N; ++i)
    for (int j = i + 1; j < N; ++j) cd = min(cd, dist(S[i], S[j]));
  return cd;
}
int unite(pii S[], int size, long long cd) {
  for (int i = 0; i < size; ++i)
    for (int j = i + 1; j < min(size, i + 8); ++j)
      cd = min(cd, dist(S[i], S[j]));
  return cd;
}
int divide(pii Px[], pii Py[], int N) {
  if (N <= 3) return brute(Px, N);
  int mid = N / 2, l = 0, r = 0, j = 0;
  pii Pyl[mid + 1], Pyr[N - mid], mp = Px[mid];
  for (int i = 0; i < N; ++i) {
    if (Py[i].x <= mp.x)
      Pyl[l++] = Py[i];
    else
      Pyr[r++] = Py[i];
  }
  long long d = min(divide(Px, Pyl, mid), divide(Px + mid, Pyr, N - mid));
  pii S[N + 1];
  for (int i = 0; i < N; ++i)
    if (abs(Py[i].x - mp.x) < d) S[j++] = Py[i];
  return min(d, 1LL * unite(S, j, d));
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    pre[i] += pre[i - 1] + A[i];
  }
  pii Px[N + 1], Py[N + 1];
  for (int i = 0; i < N; ++i)
    Px[i] = (pii){i + 1, pre[i + 1]}, Py[i] = (pii){i + 1, pre[i + 1]};
  sort(Px, Px + N, comp1);
  sort(Py, Py + N, comp2);
  printf("%d\n", divide(Px, Py, N));
  return 0;
}
