#include <bits/stdc++.h>
long long pref[100001];
std::pair<long long, long long> pts[100001];
bool cmpx(std::pair<long long, long long> A,
          std::pair<long long, long long> B) {
  return ((A.first < B.first) ||
          ((A.first == B.first) && (A.second < B.second)));
}
long long dist(std::pair<long long, long long> A,
               std::pair<long long, long long> B) {
  return ((A.first - B.first) * (A.first - B.first)) +
         ((A.second - B.second) * (A.second - B.second));
}
int main(void) {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> pref[i];
    pref[i] += pref[i - 1];
    pts[i] = std::make_pair(i, pref[i]);
  }
  std::sort(pts + 1, pts + n + 1, cmpx);
  long long ans = 1000000000000001;
  std::set<std::pair<long long, long long> > X;
  int j = 1;
  X.insert(std::make_pair(pref[1], 1));
  for (int i = 2; i <= n; i++) {
    while ((j < i) && (((i - j) * (i - j)) >= ans)) {
      X.erase(std::make_pair(pref[j], j));
      j++;
    }
    long long d = sqrt(double(ans));
    for (std::set<std::pair<long long, long long> >::iterator it =
             X.lower_bound(std::make_pair(pts[i].second - d, 0));
         it != X.end(); it++) {
      if (it->first <= pts[i].second + d)
        ans =
            std::min(ans, dist(std::make_pair(it->second, it->first), pts[i]));
      else
        break;
    }
    X.insert(std::make_pair(pref[i], i));
  }
  std::cout << ans << "\n";
  return 0;
}
