#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
bool cmpx(const pll& a, const pll& b) { return a.first < b.first; }
bool cmpy(const pll& a, const pll& b) { return a.second < b.second; }
ll sq(const ll& first) { return first * first; }
ll dis(const pll& a, const pll& b) {
  return sq(a.first - b.first) + sq(a.second - b.second);
}
vector<pll> px, py;
ll closest_pair(int l, int r) {
  if (r - l <= 1) return 1e18;
  int m = (l + r) / 2;
  ll d = min(closest_pair(l, m), closest_pair(m, r));
  inplace_merge(py.begin() + l, py.begin() + m, py.begin() + r, cmpy);
  vector<pll> strip;
  for (int i = l; i < r; i++)
    if (sq(py[i].first - px[m].first) < d) strip.push_back(py[i]);
  for (int i = 0; i < strip.size(); i++)
    for (int j = i + 1;
         j < strip.size() && sq(strip[j].second - strip[i].second) < d; j++)
      d = min(d, dis(strip[i], strip[j]));
  return d;
}
void solve() {
  int n;
  cin >> n;
  ll cur = 0, first;
  for (int i = 0; i < n; i++) {
    cin >> first;
    cur += first;
    px.emplace_back(i, cur);
  }
  sort(px.begin(), px.end(), cmpx);
  py = px;
  cout << closest_pair(0, n) << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int owo = 1;
  while (owo--) solve();
}
