#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<long long, long long> > a;
set<pair<long long, long long> > S;
long long vzd(long long x1, long long y1, long long x2, long long y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int main() {
  cin >> n;
  a.assign(n + 1, {0, 0});
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = a[i - 1].second + a[i].first;
    a[i].first = i;
  }
  long long naj = vzd(a[1].first, a[1].second, a[2].first, a[2].second);
  S.insert({a[1].second, a[1].first});
  S.insert({a[2].second, a[2].first});
  for (int i = 3; i <= n; i++) {
    auto zac = S.lower_bound({a[i].second - floor(sqrt(naj)), -99999999LL});
    while (!S.empty() && zac == S.begin() &&
           (a[i].first - (zac->second)) * (a[i].first - (zac->second)) > naj) {
      S.erase(S.begin());
      zac = S.begin();
    }
    if (S.empty() || zac == S.end()) {
      S.insert({a[i].second, a[i].first});
      continue;
    }
    for (auto it = zac; it != S.end(); it++) {
      pair<long long, long long> mozno = *it;
      if ((a[i].first - mozno.second) * (a[i].first - mozno.second) > naj) {
        it--;
        S.erase(mozno);
        if (S.empty() || it == S.end()) break;
        continue;
      }
      if ((mozno.first - a[i].second) * (mozno.first - a[i].second) > naj)
        break;
      naj = min(naj, vzd(mozno.second, mozno.first, a[i].first, a[i].second));
    }
    S.insert({a[i].second, a[i].first});
  }
  cout << naj << endl;
  return 0;
}
