#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
void solve() {
  int n;
  cin >> n;
  vector<array<long long, 2>> arr(n);
  long long sum = 0, temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    sum += temp;
    arr[i] = {i, sum};
  }
  sort(arr.begin(), arr.end());
  function<long long(int, int)> cal = [&](int l, int r) {
    if (l == r) return inf;
    int mid = (l + r) / 2;
    long long d = min(cal(l, mid), cal(mid + 1, r));
    long long mx = arr[mid][0];
    vector<array<long long, 2>> tmp;
    for (int i = l; i <= r; i++) {
      long long dx = arr[i][0] - mx;
      if (dx * dx < d) tmp.push_back({arr[i][1], arr[i][0]});
    }
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < tmp.size(); i++) {
      for (int j = i + 1; j < tmp.size(); j++) {
        long long dx = tmp[i][1] - tmp[j][1], dy = tmp[i][0] - tmp[j][0];
        if (dy * dy >= d) break;
        d = min(dx * dx + dy * dy, d);
      }
    }
    return d;
  };
  cout << cal(0, n - 1) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cout << fixed << setprecision(20);
  ;
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
