#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
pair<long long, long long> arr[N];
long long dist(pair<long long, long long> &i, pair<long long, long long> &j) {
  long long dx = i.first - j.first;
  long long dy = i.second - j.second;
  return (dx * dx + dy * dy);
}
long long solve(int s, int e) {
  if (s == e) return (long long)1e18;
  int mid = s + (e - s) / 2;
  long long mn = min(solve(s, mid), solve(mid + 1, e));
  vector<pair<long long, long long>> vec;
  double x = (arr[mid].first + arr[mid + 1].first) / 2.0;
  for (int i = s; i <= e; ++i) {
    if ((x - arr[i].first) * (x - arr[i].first) <= mn) {
      vec.push_back(arr[i]);
      swap(vec.back().first, vec.back().second);
    }
  }
  sort(vec.begin(), vec.end());
  for (int i = 1; i < vec.size(); ++i) {
    for (int j = i - 1; ~j && j > i - 6; --j) {
      mn = min(mn, dist(vec[i], vec[j]));
    }
  }
  return mn;
}
int main() {
  int n;
  scanf("%d", &n);
  long long s = 0, x;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &x);
    s += x;
    arr[i] = {i, s};
  }
  sort(arr, arr + n);
  printf("%lld", solve(1, n));
}
