#include <bits/stdc++.h>
using namespace std;
pair<int, int> closestPair(vector<pair<long long, long long>> &pts) {
  int n = pts.size();
  sort(pts.begin(), pts.end());
  set<pair<pair<long long, long long>, int>> s;
  long long best_dist = 1e18;
  int j = 0;
  pair<int, int> pos;
  for (int i = 0; i < n; ++i) {
    long long d = ceil(sqrt(best_dist));
    while (pts[i].first - pts[j].first > best_dist) {
      s.erase({{pts[j].second, pts[j].first}, j});
      j += 1;
    }
    auto it1 = s.lower_bound({{pts[i].second - d, pts[i].first}, -1});
    auto it2 = s.upper_bound({{pts[i].second + d, pts[i].first}, i});
    for (auto it = it1; it != it2; ++it) {
      long long dx = pts[i].first - it->first.second;
      long long dy = pts[i].second - it->first.first;
      long long dist = dx * dx + dy * dy;
      if (best_dist > dist) {
        best_dist = dist;
        pos.first = it->second;
        pos.second = i;
      }
    }
    s.insert({{pts[i].second, pts[i].first}, i});
  }
  return pos;
}
long long getdist(pair<long long, long long> pt1,
                  pair<long long, long long> pt2) {
  long long dx = pt1.first - pt2.first;
  long long dy = pt1.second - pt2.second;
  return dx * dx + dy * dy;
}
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> pts;
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    long long t;
    cin >> t;
    sum += t;
    pts.push_back({i, sum});
  }
  pair<int, int> ans = closestPair(pts);
  pair<long long, long long> pt1 = pts[ans.first];
  pair<long long, long long> pt2 = pts[ans.second];
  cout << getdist(pt1, pt2) << endl;
}
