#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > P;   int n;   bool compare_y(const pair<long long int, long long int>& p1,                  const pair<long long int, long long int>& p2) {     if (p1.second != p2.second) return p1.second < p2.second;     return p1.first < p2.first;   }   long long int d(pair<long long int, long long int> p1,                   pair<long long int, long long int> p2) {     return pow(p1.first - p2.first, 2) + pow(p1.second - p2.second, 2);   }   long long int func(int l, int h,                      vector<pair<long long int, long long int> > Y) {     if (h - l == 1) return d(P[l], P[h]);     if (h - l == 2)       return min(min(d(P[l], P[l + 1]), d(P[l + 1], P[h])), d(P[l], P[h]));     int mid = (l + h) / 2, sz = Y.size();     vector<pair<long long int, long long int> > left, right;     for (int i = 0; i < sz; ++i) {       if (Y[i].first <= P[mid].first)         left.push_back(Y[i]);       else         right.push_back(Y[i]);     }     long long int m = min(func(l, mid, left), func(mid + 1, h, right));     for (int i = 0; i < sz; ++i)       for (int j = i + 1; j < i + 10 && j < sz; ++j)         if (d(Y[i], Y[j]) < m) m = d(Y[i], Y[j]);     return m;   }   int main() {     cin >> n;     vector<pair<long long int, long long int> > Q;     for (int i = 0; i < n; ++i) {       long long int u;       cin >> u;       P.push_back(make_pair(i + 1, u));       Q.push_back(make_pair(i + 1, u));       if (i) P[i].second += P[i - 1].second;       if (i) Q[i].second += Q[i - 1].second;     }     sort(Q.begin(), Q.end(), compare_y);     cout << func(0, n - 1, Q) << endl;   }   