#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vc = vector<T>;
using pii = pair<long long, long long>;
void xmax(long long& a, long long b) { a = max(a, b); }
void xmin(long long& a, long long b) { a = min(a, b); }
void print(vc<long long>& a, string second) {
  cerr << second << " : ";
  for (long long i = 0; i < a.size(); i++) {
    cerr << a[i] << " ";
  }
  cerr << endl;
}
long long dist(pii a, pii b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}
long long find_min(vc<pii> p) {
  if (p.size() == 1) return 1e18;
  if (p.size() == 2) {
    return dist(p[0], p[1]);
  }
  long long n = p.size();
  long long mid = (p[0].first + p[n - 1].first) / 2;
  vc<pii> ri;
  vc<pii> le;
  for (long long i = 0; i < n; i++) {
    if (p[i].first <= mid)
      le.push_back(p[i]);
    else
      ri.push_back(p[i]);
  }
  long long mini = 1e18;
  xmin(mini, find_min(le));
  xmin(mini, find_min(ri));
  vc<pii> cut;
  long double delta = sqrt(mini) + 1;
  for (long long i = 0; i < le.size(); i++) {
    if (abs(mid - le[i].first) <= delta)
      cut.push_back({le[i].second, le[i].first});
  }
  for (long long i = 0; i < ri.size(); i++) {
    if (abs(mid - ri[i].first) <= delta)
      cut.push_back({ri[i].second, ri[i].first});
  }
  sort(cut.begin(), cut.end());
  for (long long i = 0; i < cut.size(); i++) {
    for (long long j = 1; j < 20 && i + j < cut.size(); j++) {
      xmin(mini, dist(cut[i], cut[i + j]));
    }
  }
  return mini;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vc<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  vc<long long> p(n);
  for (long long i = 1; i < n; i++) {
    p[i] = p[i - 1] + a[i];
  }
  vc<pair<long long, long long> > st(n);
  for (long long i = 0; i < n; i++) {
    st[i] = {i, p[i]};
  }
  long long res = find_min(st);
  cout << res << "\n";
}
