#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll modInv(ll a) { return binpow(a, MOD - 2); }
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
ll arr[mxN];
ll psum[mxN];
pair<ll, ll> all[mxN];
pair<ll, ll> temp[mxN];
ll ans = INFLL;
int n;
bool cmpy(pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; }
void upd_ans(pair<ll, ll> a, pair<ll, ll> b) {
  ll dist = (a.first - b.first) * (a.first - b.first) +
            (a.second - b.second) * (a.second - b.second);
  ans = min(ans, dist);
}
void recurse(int l, int r) {
  if (r - l <= 3) {
    for (int i = (l); i < (r); ++i) {
      for (int j = (i + 1); j < (r); ++j) {
        upd_ans(all[i], all[j]);
      }
    }
    sort(all + l, all + r, cmpy);
    return;
  }
  int m = (l + r) >> 1;
  recurse(l, m);
  recurse(m, r);
  int sz = 0;
  int pl = l;
  int pr = m;
  while (pl < m || pr < r) {
    if (pl == m) {
      temp[sz++] = all[pr++];
    } else if (pr == r) {
      temp[sz++] = all[pl++];
    } else {
      temp[sz++] = (all[pl].second < all[pr].second ? all[pl++] : all[pr++]);
    }
  }
  for (int i = (l); i < (r); ++i) {
    all[i] = temp[i - l];
  }
  for (int i = (l); i < (r); ++i) {
    for (int k = 1; i + k < r && k < 4; ++k) {
      upd_ans(all[i], all[i + k]);
    }
  }
}
int main() {
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (int i = (1); i < (n + 1); ++i) {
    cin >> arr[i];
  }
  for (int i = (1); i < (n + 1); ++i) {
    psum[i] = psum[i - 1] + arr[i];
    all[i - 1] = {i, psum[i]};
  }
  recurse(0, n);
  cout << ans << "\n";
  return 0;
}
