func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int Int() {     int x;     scanf( %d , &x);     return x;   }   inline long long Long() {     long long x;     scanf( %lld , &x);     return x;   }   void err(istream_iterator<string> it) { cout << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   const int N = (int)2e5 + 5;   const int maxN = (int)1e6 + 6;   const long long Mod = (long long)1e9 + 7;   const int inf = (int)2e9;   const long long Inf = (long long)1e18;   const int mod = (int)1e9 + 7;   inline int add(int a, int b) {     a += b;     return a >= mod ? a - mod : a;   }   inline int sub(int a, int b) {     a -= b;     return a < 0 ? a + mod : a;   }   inline int mul(int a, int b) { return (long long)a * b % mod; }   long long a[N], s[N], p[N];   struct CHT {     vector<long long> m, c;     bool bad(int f1, int f2, int f3, int tp) {       if (tp == 1)         return 1.0 * (c[f3] - c[f1]) * (m[f1] - m[f2]) >=                1.0 * (c[f2] - c[f1]) * (m[f1] - m[f3]);       else         return 1.0 * (c[f3] - c[f1]) * (m[f1] - m[f2]) <=                1.0 * (c[f2] - c[f1]) * (m[f1] - m[f3]);     }     void add(long long _m, long long _c, int tp) {       m.push_back(_m), c.push_back(_c);       int second = (int)m.size();       while (second >= 3 and bad(second - 3, second - 2, second - 1, tp)) {         m.erase(m.end() - 2);         c.erase(c.end() - 2);         --second;       }     }     long long f(long long x, int i) { return x * m[i] + c[i]; }     long long query(long long x) {       int l = 0, r = (int)m.size() - 1, id = 0;       while (l <= r) {         int del = (r - l) / 3;         int mid1 = l + del, mid2 = r - del;         if (f(x, mid1) > f(x, mid2))           id = mid1, r = mid2 - 1;         else           id = mid2, l = mid1 + 1;       }       return f(x, id);     }   } ds, ds1;   int main() {     int test = 1, tc = 0;     while (test--) {       int n = Int();       long long ans = 0;       for (int i = 1; i <= n; ++i) {         a[i] = Int();         p[i] = p[i - 1] + a[i];         ans += (1LL * i * a[i]);       }       long long res = 0;       ds.add(n, -p[n], 1);       for (int i = n - 1; i >= 1; --i) {         res = max(res, ds.query(a[i]) + p[i] - i * a[i]);         ds.add(i, -p[i], 1);       }       ds1.add(1, 0, 2);       for (int i = 2; i <= n; ++i) {         res = max(res, ds1.query(a[i]) + p[i] - (i + 1) * a[i]);         ds1.add(i, -p[i - 1], 2);       }       cout << res + ans <<   n ;     }     return 0;   }   