#include <bits/stdc++.h>
using namespace std;
const int MAXN = 202020;
const int INF = 1000000000;
struct point2D {
  int x, y;
} p[MAXN], tp[MAXN];
bool pointCmp(point2D a, point2D b) {
  return (a.x < b.x || (a.x == b.x && a.y < b.y));
}
bool pointCmpy(point2D a, point2D b) { return (a.y < b.y); }
int n;
int dis(point2D a, point2D b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int solve(int l, int r) {
  if (l == r) return INF;
  if (l + 1 == r) return dis(p[l], p[r]);
  int mid = (l + r) / 2;
  int d1 = solve(l, mid), d2 = solve(mid + 1, r);
  int k = 0, d = min(d1, d2);
  for (int i = mid; i >= l; i--)
    if ((p[i].x - p[mid].x) * (p[i].x - p[mid].x) <= d) {
      tp[++k] = p[i];
    } else
      break;
  for (int i = mid + 1; i <= r; i++)
    if ((p[i].x - p[mid].x) * (p[i].x - p[mid].x) <= d) {
      tp[++k] = p[i];
    } else
      break;
  sort(tp + 1, tp + 1 + k, pointCmpy);
  for (int i = 1; i < k; i++)
    for (int j = i + 1;
         j <= k && (tp[j].y - tp[i].y) * (tp[j].y - tp[i].y) <= d; j++) {
      d = min(d, dis(tp[i], tp[j]));
    }
  return d;
}
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int tmp;
    scanf("%d", &tmp);
    sum += tmp;
    p[i].x = i;
    p[i].y = sum;
  }
  sort(p + 1, p + 1 + n, pointCmp);
  printf("%d\n", solve(1, n));
  return 0;
}
