#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   inline long long int max(long long int a, long long int b) {     return a > b ? a : b;   }   inline long long int min(long long int a, long long int b) {     return a > b ? b : a;   }   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x;   }   long long int sum[maxn * 4], mq[maxn * 4], dl[maxn * 4], dr[maxn * 4];   int lb[maxn * 4], rb[maxn * 4];   int N, M;   int a[maxn];   inline void update(int i) {     if (lb[i] == rb[i]) {       sum[i] = fabs(dr[i]);       mq[i] = max(dl[i], 0) + max(dr[i], 0);       return;     }     sum[i] = sum[i << 1] + sum[(i << 1) + 1];     mq[i] = min(mq[i << 1], mq[(i << 1) + 1]);   }   inline void updateall(int i) {     while (i > 1) {       update(i);       i = i >> 1;     }     update(1);   }   void build(int i, int l, int r) {     lb[i] = l;     rb[i] = r;     if (l == r) {       dl[i] = a[l - 1] - a[l];       dr[i] = a[l + 1] - a[l];       sum[i] = fabs(dr[i]);       mq[i] = max(dl[i], 0) + max(dr[i], 0);     } else {       int m = (l + r) >> 1;       build(i << 1, l, m);       build((i << 1) + 1, m + 1, r);       update(i);     }   }   long long int getmq(int i, int l, int r) {     if (l == lb[i] && r == rb[i]) return mq[i];     int m = (lb[i] + rb[i]) >> 1;     long long int re = 1e9 + 10;     if (l <= m) re = min(re, getmq(i << 1, l, min(m, r)));     if (r > m) re = min(re, getmq((i << 1) + 1, max(m + 1, l), r));     return re;   }   int find(int x, int i) {     if (lb[i] == rb[i] && lb[i] == x)       return i;     else if (x <= ((lb[i] + rb[i]) >> 1))       return find(x, i << 1);     else       return find(x, (i << 1) + 1);   }   inline long long int solve1(int l, int r, int x) {     if (l == r) {       int p = find(l, 1);       return fabs(dl[p] - x) + fabs(dr[p] - x) - fabs(dl[p]) - fabs(dr[p]) +              sum[1];     } else {       return max(0, 2 * x - 2 * getmq(1, l, r)) + sum[1];     }   }   inline void solve2(int l, int r, int x) {     int p = find(l, 1);     dl[p] -= x;     updateall(p);     p = find(l - 1, 1);     dr[p] += x;     updateall(p);     p = find(r, 1);     dr[p] -= x;     updateall(p);     p = find(r + 1, 1);     dl[p] += x;     updateall(p);   }   int main() {     int i, j, k, x, y;     N = read();     for (i = 1; i <= N; i++) a[i] = read();     a[N + 1] = a[N];     a[0] = a[1];     build(1, 1, N);     M = read();     for (i = 1; i <= M; i++) {       j = read();       k = read();       x = read();       y = read();       if (j == 1) {         printf( %I64d n , solve1(k, x, y));       } else {         solve2(k, x, y);       }     }   }   