#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
  if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
          ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,
          ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
void fre() {
  freopen("/Users/luras/Desktop/in.txt", "r", stdin);
  freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;
struct point {
  long long x, y;
  int o;
} p[N], tmpp[N];
int n;
long long K(long long x) { return x * x; }
struct Ans {
  int x, y;
  long long dis;
  Ans(int x = -1, int y = -1, long long dis = 1e18) : x(x), y(y), dis(dis) {}
  void update(Ans b) {
    if (b.dis < dis) {
      x = b.x;
      y = b.y;
      dis = b.dis;
    }
  }
};
Ans getDistance(point &a, point &b) {
  long long dis = K(a.x - b.x) + K(a.y - b.y);
  return Ans(a.o, b.o, dis);
}
bool cmpxy(const point &a, const point &b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
bool cmpy(const point &a, const point &b) { return a.y < b.y; }
Ans res;
void Closest_Pair(int l, int r) {
  if (l + 1 == r) {
    res.update(getDistance(p[l], p[r]));
  } else if (l + 2 == r) {
    res.update(getDistance(p[l], p[l + 1]));
    res.update(getDistance(p[l + 1], p[r]));
    res.update(getDistance(p[l], p[r]));
  } else {
    int mid = (l + r) >> 1;
    Closest_Pair(l, mid);
    Closest_Pair(mid + 1, r);
    int g = 0;
    for (int i = l; i <= r; i++) {
      if (K(p[i].x - p[mid].x) < res.dis) tmpp[g++] = p[i];
    }
    sort(tmpp, tmpp + g, cmpy);
    for (int i = 0; i < g; i++) {
      for (int j = i + 1; j < g && K(tmpp[j].y - tmpp[i].y) < res.dis; j++) {
        res.update(getDistance(tmpp[j], tmpp[i]));
      }
    }
  }
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%lld", &p[i].x);
    }
    p[0].y = p[0].x;
    p[0].x = 0;
    for (int i = 1; i < n; i++) {
      p[i].y = p[i].x + p[i - 1].y;
      p[i].x = i;
    }
    sort(p, p + n, cmpxy);
    for (int i = 0; i < n; i++) p[i].o = i;
    res = Ans();
    Closest_Pair(0, n - 1);
    long long ans = res.dis;
    printf("%lld\n", ans);
  }
  return 0;
}
