#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1LL;
struct point {
  long long x, y;
  int i;
  point(long long X, long long Y, int I) {
    x = X;
    y = Y;
    i = I;
  }
};
bool compX(const point a, const point b) { return a.x < b.x; }
bool compY(const point a, const point b) {
  if (a.y == b.y) return compX(a, b);
  return a.y < b.y;
}
struct plane {
  vector<point> points_X;
  vector<point> points_Y;
  int cnt = 0;
  vector<int> wh;
  void add(long long x, long long y) {
    points_X.push_back(point(x, y, cnt));
    points_Y.push_back(point(x, y, cnt));
    ++cnt;
  }
  long long get_dist(point a, point b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
  }
  long long get_min(point a) {
    int I = wh[a.i];
    long long ans = INF;
    for (int i = I + 1; i < min(cnt, I + 10); ++i)
      ans = min(ans, get_dist(a, points_Y[i]));
    return ans;
  }
  long long find(int l, int r) {
    if (l + 2 == r) return get_dist(points_X[l], points_X[l + 1]);
    if (l + 3 == r) {
      point a = points_X[l];
      point b = points_X[l + 1];
      point c = points_X[l + 2];
      long long ans = min(get_dist(a, b), get_dist(b, c));
      ans = min(ans, get_dist(a, c));
      return ans;
    }
    int mid = (l + r) / 2;
    long long distLR = min(find(l, mid), find(mid, r));
    for (int i = l; i < r; ++i) distLR = min(distLR, get_min(points_X[i]));
    return distLR;
  }
  long long sol() {
    wh.resize(cnt);
    sort(points_X.begin(), points_X.end(), compX);
    sort(points_Y.begin(), points_Y.end(), compY);
    for (int i = 0; i < cnt; ++i) wh[points_Y[i].i] = i;
    return find(0, cnt);
  }
};
void solve() {
  int n;
  cin >> n;
  long long sm = 0;
  plane my_plane;
  for (int i = 1; i <= n; ++i) {
    long long nw;
    cin >> nw;
    sm += nw;
    my_plane.add(i, sm);
  }
  cout << my_plane.sol();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
