#include <bits/stdc++.h>
using namespace std;
struct poll {
  long long x, y;
  poll(long long x1 = 0, long long y1 = 0) : x(x1), y(y1) {}
};
bool cmp(poll a, poll b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
bool cmp1(poll a, poll b) { return a.y < b.y || (a.y == b.y && a.x < b.x); }
long double dist(poll a, poll b) {
  return sqrt(((double)a.x - b.x) * (a.x - b.x) +
              ((double)a.y - b.y) * (a.y - b.y));
}
static poll v1, v2;
static vector<poll> vct;
static long double d;
void gt(vector<poll>& a) {
  if (a.size() <= 1) return;
  vector<poll> b(a.begin(), a.begin() + (a.end() - a.begin()) / 2),
      c(a.begin() + (a.end() - a.begin()) / 2, a.end());
  long long x = c[0].x;
  gt(b);
  gt(c);
  merge(b.begin(), b.end(), c.begin(), c.end(), a.begin(), cmp1);
  vct.clear();
  for (long long i = 0; i < (long long)a.size(); ++i)
    if (abs((long double)a[i].x - x) < d) {
      vct.push_back(a[i]);
    }
  for (long long i = 0; i < (long long)vct.size(); ++i)
    for (long long j = i + 1;
         j < (long long)vct.size() && vct[j].y - vct[i].y < d; ++j)
      if (d > dist(vct[i], vct[j])) {
        d = min(d, dist(vct[i], vct[j]));
        v1 = vct[i];
        v2 = vct[j];
      }
}
static long long res = (long long)1000000007;
void gt(long long n, long long k) {
  if (k > res) return;
  if (n == 0) {
    res = k;
    return;
  }
  long long a = 0, b = 0;
  while (a <= n) {
    a = a * 10 + 1;
    ++b;
  }
  --b;
  a /= 10;
  if (b > 16) return;
  gt(n % a, k + (n / a) * b);
  gt((a * 10 + 1) - n, k + b + 1);
};
int main() {
  ios_base::sync_with_stdio(0);
  vector<poll> vc;
  d = 2000000020000000000;
  long long n;
  cin >> n;
  vc.resize(n);
  long long a, b = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a;
    b += a;
    vc[i].x = i;
    vc[i].y = b;
  }
  sort(vc.begin(), vc.end(), cmp);
  gt(vc);
  cout << (long long)(d * d + 0.00001) << endl;
  return 0;
}
