func_code_string: #include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int N = 200010;   const bool QUERY_MAX = true;   const double INF = 1e30;   struct Line {     long long a, b, val;     double xLeft;     bool is_query;     Line() {}     Line(long long _a, long long _b) {       a = _a;       b = _b;       val = 0;       xLeft = -INF;       is_query = false;     }     long long value(long long x) { return a * x + b; }     bool operator<(const Line l) const {       if (l.is_query) {         return QUERY_MAX ? (xLeft < l.val) : (l.val < xLeft);       }       return a < l.a;     }     bool areParallel(const Line l) const { return a == l.a; }     double intersect(const Line l) const {       if (!areParallel(l)) return (l.b - b) / (1.0 * (a - l.a));       return INF;     }     void printLine() const { printf( a = %lld  t b = %lld n , a, b); }   };   set<Line> hull;   bool has_prev(set<Line>::iterator it) { return it != hull.begin(); }   bool has_next(set<Line>::iterator it) {     return (it != hull.end()) and (++it != hull.end());   }   bool irrelevant(set<Line>::iterator it) {     if (!has_prev(it) or !has_next(it)) {       return false;     }     set<Line>::iterator prev = it, next = it;     prev--;     next++;     return QUERY_MAX ? prev->intersect(*next) <= prev->intersect(*it)                      : next->intersect(*prev) <= next->intersect(*it);   }   set<Line>::iterator update_left_border(set<Line>::iterator it) {     if ((QUERY_MAX and !has_prev(it)) or (!QUERY_MAX and !has_next(it)))       return it;     set<Line>::iterator it2 = it;     double val = it->intersect(QUERY_MAX ? *--it2 : *++it2);     Line l(*it);     l.xLeft = val;     hull.erase(it++);     return hull.insert(it, l);   }   void addLine(long long a, long long b) {     Line l(a, b);     set<Line>::iterator it = hull.lower_bound(l);     if (it != hull.end() and it->areParallel(l)) {       if ((QUERY_MAX and it->b < b) or (!QUERY_MAX and it->b > b))         hull.erase(it++);       else         return;     }     it = hull.insert(it, l);     if (irrelevant(it)) {       hull.erase(it);       return;     }     while (has_prev(it) and irrelevant(--it)) hull.erase(it++);     while (has_next(it) and irrelevant(++it)) hull.erase(it--);     it = update_left_border(it);     if (has_prev(it)) {       update_left_border(--it);     }     if (has_next(++it)) {       update_left_border(++it);     }   }   long long best(long long x) {     Line q(0, 0);     q.val = x;     q.is_query = true;     set<Line>::iterator it = hull.lower_bound(q);     if (QUERY_MAX) --it;     return it->a * x + it->b;   }   long long v[N], sum[N], resp;   int main(void) {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , v + i);       sum[i + 1] = sum[i] + v[i];       resp += v[i] * (i + 1);     }     long long ans = resp;     addLine(n, -sum[n]);     for (int i = n - 1; i >= 1; i--) {       long long x = v[i - 1];       long long value = best(x) + resp + sum[i] - v[i - 1] * i;       addLine(i, -sum[i]);       ans = max(ans, value);     }     hull.clear();     addLine(1, 0);     for (int i = 2; i <= n; i++) {       long long x = v[i - 1];       long long value = best(x) + resp + sum[i - 1] - v[i - 1] * i;       addLine(i, -sum[i - 1]);       ans = max(ans, value);     }     cout << ans << endl;     return 0;   }   