#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  return (a.second < b.second);
}
long long int compute_distance(pair<long long int, long long int> p1,
                               pair<long long int, long long int> p2) {
  return ((p1.first - p2.first) * (p1.first - p2.first) +
          (p1.second - p2.second) * (p1.second - p2.second));
}
long long int brute_force(pair<long long int, long long int> points[], int n) {
  long long int min_d = INT64_MAX;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      min_d = min(compute_distance(points[i], points[j]), min_d);
  return min_d;
}
long long int solve_candidates(pair<long long int, long long int> strip[],
                               int size, long long int d) {
  long long int min_d = d;
  sort(strip, strip + size, sortbysec);
  for (int i = 0; i < size; ++i) {
    int j = i + 1;
    while (j < size && (strip[j].second - strip[i].second) *
                               (strip[j].second - strip[i].second) <
                           min_d) {
      min_d = min(compute_distance(strip[i], strip[j++]), min_d);
    }
  }
  return min_d;
}
long long int solve(pair<long long int, long long int> points[], int n) {
  if (n <= 3) return brute_force(points, n);
  int mid = n / 2;
  pair<long long int, long long int> midPoint = points[mid];
  long long int dl = solve(points, mid);
  long long int dr = solve(points + mid, n - mid);
  long long int d = min(dl, dr);
  pair<long long int, long long int> candidates[n];
  int j = 0;
  for (int i = 0; i < n; i++)
    if ((points[i].first - midPoint.first) *
            (points[i].first - midPoint.first) <
        d)
      candidates[j] = points[i], j++;
  return solve_candidates(candidates, j, d);
}
int main() {
  int N;
  cin >> N;
  pair<long long int, long long int> points[N];
  long long int acc_sum = 0;
  long long int number;
  long long int tmp;
  for (size_t i = 0; i < N; i++) {
    cin >> number;
    acc_sum += number;
    points[i] = make_pair(i, acc_sum);
  }
  sort(points, points + N);
  cout << solve(points, N) << endl;
}
