#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point(int x = 0, int y = 0) : x(x), y(y) {}
  int in() { return scanf("%d%d", &x, &y); }
} p[110000];
int n, id[110000];
vector<int> v[2 * 110000];
double dist(Point &a, Point &b) { return hypot(a.x - b.x, a.y - b.y); }
bool cmpx(int a, int b) {
  if (p[a].x != p[b].x) return p[a].x < p[b].x;
  return p[a].y < p[b].y;
}
bool cmpy(int a, int b) {
  if (p[a].y != p[b].y) return p[a].y < p[b].y;
  return p[a].x < p[b].x;
}
void build(int st, int en, int id) {
  v[id].clear();
  for (int i = st; i <= en; i++) v[id].push_back(::id[i]);
  if (en - st + 1 <= 3) {
    return;
  }
  int mid = st + en >> 1;
  build(st, mid, (2 * (id)));
  build(mid + 1, en, (2 * (id) + 1));
}
void merge(vector<int> &v1, vector<int> &v2, vector<int> &v) {
  int i(0), k(0);
  while (i < v1.size() || k < v2.size()) {
    if (k == v2.size() || (i < v1.size() && p[v1[i]].y <= p[v2[k]].y))
      v.push_back(v1[i++]);
    else
      v.push_back(v2[k++]);
  }
}
double solve(int id, vector<int> &Y) {
  int i, k, cnt(v[id].size());
  double ans = 1e12;
  if (cnt <= 3) {
    for (i = 0; i < cnt; i++) Y.push_back(v[id][i]);
    for (i = 0; i < v[id].size(); i++)
      for (k = i + 1; k < v[id].size(); k++)
        ans = min(ans, dist(p[v[id][i]], p[v[id][k]]));
    sort(Y.begin(), Y.end(), cmpy);
    return ans;
  }
  int mid = (v[id].size() - 1) / 2;
  double l = p[v[id][mid]].x, d(1e12);
  vector<int> y1, y2, YY;
  d = min(d, solve((2 * (id)), y1));
  d = min(d, solve((2 * (id) + 1), y2));
  Y.clear();
  merge(y1, y2, Y);
  for (i = 0; i < Y.size(); i++) {
    if ((double)p[Y[i]].x < l - d + 1e-8) continue;
    if ((double)p[Y[i]].x > l + d - 1e-8) continue;
    YY.push_back(Y[i]);
  }
  ans = min(ans, d);
  for (i = 0; i < YY.size(); i++)
    for (k = i - 1; k >= max(0, i - 7); k--)
      ans = min(ans, dist(p[YY[i]], p[YY[k]]));
  return ans;
}
int a[110000], s[110000];
int main() {
  cin >> n;
  int i;
  for (i = 0; i < n; i++) scanf("%d", a + i);
  for (s[0] = a[0], i = 1; i < n; i++) s[i] = s[i - 1] + a[i];
  for (i = 0; i < n; i++) p[i].x = i, p[i].y = s[i];
  for (i = 0; i < n; i++) id[i] = i;
  sort(id, id + n, cmpx);
  build(0, n - 1, 1);
  vector<int> Y;
  double r = solve(1, Y);
  int rlt = int(round(r * r));
  cout << rlt << endl;
}
