#include <bits/stdc++.h>
using std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::copy;
using std::cout;
using std::deque;
using std::endl;
using std::fill;
using std::fixed;
using std::greater;
using std::istream;
using std::lower_bound;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multiset;
using std::next_permutation;
using std::nth_element;
using std::ostream;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse;
using std::rotate;
using std::set;
using std::sort;
using std::string;
using std::swap;
using std::tie;
using std::tuple;
using std::unique;
using std::unordered_map;
using std::unordered_set;
using std::upper_bound;
using std::vector;
int const INF = (int)1e9;
long long const INFL = (long long)1e18;
long double const PI = 3.1415926535897932384626433832795028;
struct Point {
  long long x, y;
  Point() {}
  Point(long long x, long long y) : x(x), y(y) {}
};
bool compx(Point const& a, Point const& b) {
  return a.x < b.x || (a.x == b.x && a.y < b.y);
}
bool compy(Point const& a, Point const& b) {
  return a.y < b.y || (a.y == b.y && a.x < b.x);
}
long long dist2(Point const& a, Point const& b) {
  long long dx = a.x - b.x;
  long long dy = a.y - b.y;
  return dx * dx + dy * dy;
}
struct Node {
  int type;
  int x1, y1;
  int x2, y2;
  vector<Point> p;
  Node *L, *R;
};
int const MAX_IN_LEAF = 333;
bool inside(long long p, long long begin, long long end) {
  return begin <= p && p <= end;
}
long long dist2(long long p, long long begin, long long end) {
  if (inside(p, begin, end)) {
    return 0;
  }
  long long dist = min(abs(p - begin), abs(p - end));
  return dist * dist;
}
long long dist2(Point const& a, Node* v) {
  if (!v) {
    return INFL;
  }
  if (v->type == 2) {
    long long ret = INFL;
    for (auto p : v->p) {
      long long now = dist2(a, p);
      if (now > 0) {
        ret = min(ret, now);
      }
    }
    return ret;
  } else {
    if (inside(a.x, v->x1, v->x2)) {
      return dist2(a.y, v->y1, v->y2);
    } else if (inside(a.y, v->y1, v->y2)) {
      return dist2(a.x, v->x1, v->x2);
    } else {
      return min({dist2(a, Point(v->x1, v->y1)), dist2(a, Point(v->x1, v->y2)),
                  dist2(a, Point(v->x2, v->y1)),
                  dist2(a, Point(v->x2, v->y2))});
    }
  }
}
template <typename RAI>
Node* build(RAI a, RAI b, int type) {
  int n = b - a;
  Node* ret = new Node();
  ret->x1 = min_element(a, b, compx)->x;
  ret->y1 = min_element(a, b, compy)->y;
  ret->x2 = max_element(a, b, compx)->x;
  ret->y2 = max_element(a, b, compy)->y;
  if (n <= MAX_IN_LEAF) {
    ret->type = 2;
    ret->p = vector<Point>(a, b);
    ret->L = NULL;
    ret->R = NULL;
    return ret;
  }
  int ln = n / 2;
  nth_element(a, a + ln, a + n, type == 0 ? compx : compy);
  ret->type = type;
  ret->p = {a[ln]};
  ret->L = build(a, a + ln, !type);
  ret->R = build(a + ln, b, !type);
  return ret;
}
long long closest(Node* tree, Point const& p) {
  long long res = INFL;
  set<pair<long long, Node*>> q;
  q.emplace(dist2(p, tree), tree);
  while (!q.empty()) {
    long long cur = q.begin()->first;
    if (cur >= res) {
      break;
    }
    Node* v = q.begin()->second;
    q.erase(q.begin());
    if (v->type == 2) {
      res = cur;
    } else {
      q.emplace(dist2(p, v->L), v->L);
      q.emplace(dist2(p, v->R), v->R);
    }
  }
  return res;
}
void solve() {
  int n;
  scanf("%d", &n);
  vector<Point> a(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    long long y;
    scanf("%lld", &y);
    sum += y;
    a[i] = Point(i, sum);
  }
  Node* tree = build(a.begin(), a.end(), 0);
  long long ans = INFL;
  for (auto p : a) {
    ans = min(ans, closest(tree, p));
  }
  cout << ans << endl;
}
int main() {
  cout.precision(15);
  cout << fixed;
  cerr.precision(6);
  cerr << fixed;
  srand(1510);
  solve();
}
