#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
long long A[100005], sum[100005];
struct point {
  point() {}
  point(long long x, long long y) : x(x), y(y) {}
  long long x, y;
  bool operator<(const point &f) const { return x < f.x; }
};
vector<point> v;
long long Dist(point a, point b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
long long getClosestPair(int L, int R, point &a, point &b) {
  if (L >= R) return 3ll * 1e9 * 1e9;
  int m = (L + R) / 2;
  point Left0, Left1, Right0, Right1;
  long long LeftDistance = getClosestPair(L, m, Left0, Left1);
  long long RightDistance = getClosestPair(m + 1, R, Right0, Right1);
  long long dist = min(LeftDistance, RightDistance);
  long long LeftRightDistance = dist;
  point LeftRight0, LeftRight1;
  vector<point> nearestPoints;
  for (int i = L; i <= R; i++)
    if (abs(v[i].x - v[m].x) < dist)
      nearestPoints.push_back(point(v[i].y, v[i].x));
  sort(nearestPoints.begin(), nearestPoints.end());
  for (int i = 0; i < nearestPoints.size(); i++) {
    for (int j = i + 1; j < nearestPoints.size(); j++) {
      if ((nearestPoints[j].x - nearestPoints[i].x) *
              (nearestPoints[j].x - nearestPoints[i].x) >=
          LeftRightDistance)
        break;
      long long curD = Dist(nearestPoints[i], nearestPoints[j]);
      if (curD < LeftRightDistance) {
        LeftRightDistance = curD;
        LeftRight0 = nearestPoints[i];
        LeftRight1 = nearestPoints[j];
      }
    }
  }
  if (LeftDistance <= RightDistance && LeftDistance <= LeftRightDistance) {
    a = Left0, b = Left1;
    return LeftDistance;
  } else if (RightDistance <= LeftDistance &&
             RightDistance <= LeftRightDistance) {
    a = Right0, b = Right1;
    return RightDistance;
  } else {
    a = LeftRight0, b = LeftRight1;
    return LeftRightDistance;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (i - 1 >= 0) sum[i] += sum[i - 1];
    sum[i] += A[i];
  }
  for (int i = 0; i < n; i++) v.push_back(point(i, sum[i]));
  point a, b;
  getClosestPair(0, v.size() - 1, a, b);
  if (a.x > b.x) swap(a, b);
  cout << (b.x - a.x) * (b.x - a.x) + abs(b.y - a.y) * abs(b.y - a.y) << endl;
}
