#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int maxn = 1e5 + 5;
const long long inf = 1e18 + 10;
int n;
pair<long long, long long> A[maxn];
bool compare_y(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second < b.second;
}
long long closest_pair(pair<long long, long long>* a, int n) {
  if (n <= 1) return inf;
  int m = n / 2;
  long long x = a[m].first;
  long long d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare_y);
  vector<pair<long long, long long> > b;
  for (int i = 0; i < n; i++) {
    if ((a[i].first - x) * (a[i].first - x) >= d) continue;
    for (int j = 0; j < b.size(); j++) {
      long long dx = a[i].first - b[b.size() - j - 1].first;
      long long dy = a[i].second - b[b.size() - j - 1].second;
      if (dy * dy >= d) break;
      d = min(d, dx * dx + dy * dy);
    }
    b.push_back(a[i]);
  }
  return d;
}
int main() {
  int n;
  scanf("%d", &n);
  long long sum = 0;
  long long a;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a);
    sum += a;
    A[i] = {i, sum};
  }
  long long res = closest_pair(A, n);
  cout << res << endl;
}
