func_code_string: #include <bits/stdc++.h>   using namespace std;   const int n0 = 1 << 17;   const long long inf = 1e18;   int n, a[n0], q;   long long d[n0], gaps;   struct Node {     int l = 0, r = 0;     long long val[3];     Node() { val[0] = val[1] = val[2] = -inf; }     void init(int pos) {       l = r = pos;       if (l < 2 || l > n - 1) {         val[0] = val[1] = val[2] = -inf;         return;       }       long long d1 = d[l - 1], d2 = d[l];       long long t = -abs(d1) - abs(d2);       val[0] = d1 - d2 + t;       val[1] = max(d1 + d2, -d1 - d2) + t;       val[2] = -d1 + d2 + t;     }     void merge(Node &x, Node &y) {       if (!x.l) {         x = y;         return;       }       l = x.l, r = y.r;       for (int i = 0; i < 3; i++) val[i] = max(x.val[i], y.val[i]);     }     long long get(long long x) {       return max({-2 * x + val[0], val[1], 2 * x + val[2]});     }   };   struct Segtree {     Node t[n0 << 1];     void build() {       for (int i = (n0 << 1) - 1; i > 0; i--) {         if (i >= n0)           t[i].init(i - n0);         else           t[i].merge(t[i << 1], t[i << 1 | 1]);       }     }     void upd(int x) {       t[x + n0].init(x);       for (x += n0; x > 1; x /= 2) t[x >> 1].merge(t[x], t[x ^ 1]);     }     Node get(int l, int r) {       r++;       Node res;       for (l += n0, r += n0; l < r; l /= 2, r /= 2) {         if (l & 1) res.merge(res, t[l++]);         if (r & 1) res.merge(res, t[--r]);       }       return res;     }   };   Segtree st;   void upd(int x, int y) {     gaps -= abs(d[x]);     d[x] += y;     gaps += abs(d[x]);     st.upd(x), st.upd(x + 1);   }   long long get(int l, int r, long long x) {     long long res = st.get(l, r).get(x);     if (l == 1) res = max(res, abs(d[1] + x) - abs(d[1]));     if (r == n) res = max(res, abs(d[n - 1] - x) - abs(d[n - 1]));     return gaps + res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) d[i] = a[i] - a[i + 1], gaps += abs(d[i]);     st.build();     cin >> q;     while (q--) {       int t, l, r, x;       cin >> t >> l >> r >> x;       if (t == 1) {         cout << get(l, r, x) <<   n ;       } else {         upd(l - 1, -x), upd(r, x);       }     }   }   