#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const long long int inf = LLONG_MAX / 4;
int n;
long long int aa, ps[MAXN];
inline long long int dist(pair<int, int> a, pair<int, int> b) {
  long long int xa = a.first, ya = a.second, xb = b.first, yb = b.second;
  return (((xa - xb) * (xa - xb)) + ((ya - yb) * (ya - yb)));
}
long long int slv(vector<pair<int, int>> x, vector<pair<int, int>> y) {
  if ((int)x.size() <= 1) return inf;
  int mid = (x[0].first + x.back().first) / 2;
  vector<pair<int, int>> x1, x2, y1, y2, d1, d2;
  for (auto u : x) {
    if (u.first <= mid)
      x1.push_back(u);
    else
      x2.push_back(u);
  }
  for (auto u : y) {
    if (u.second <= mid)
      y1.push_back(u);
    else
      y2.push_back(u);
  }
  long long int d = min(slv(x1, y1), slv(x2, y2));
  for (auto u : y1)
    if (u.second >= mid - d) d1.push_back(u);
  for (auto u : y2)
    if (u.second <= mid + d) d2.push_back(u);
  int pt = 0;
  for (auto u : d1) {
    while (pt + 1 < (int)d2.size() && d2[pt + 1].first <= u.first) pt++;
    for (int j = -4; j <= 4; j++)
      if (pt + j >= 0 && pt + j < (int)d2.size())
        d = min(d, dist(u, d2[pt + j]));
  }
  return d;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<pair<int, int>> x, y;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> aa;
    ps[i] = aa + (i == 0 ? 0ll : ps[i - 1]);
    x.push_back({i, ps[i]});
    y.push_back({ps[i], i});
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  cout << slv(x, y) << '\n';
  return 0;
}
