#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long zero = 1LL * 0;
long long tree[maxn << 4][2];
long long a[maxn];
long long cha[maxn];
int l, r;
int o;
int ch[10];
void buildsum(int s, int e, int root) {
  if (s == e) {
    tree[root][0] = abs(a[s]);
    tree[root][1] = cha[s];
  } else {
    int mid = (s + e) >> 1;
    buildsum(s, mid, root << 1);
    buildsum(mid + 1, e, root << 1 | 1);
    tree[root][0] = tree[root << 1][0] + tree[root << 1 | 1][0];
    tree[root][1] = min(tree[root << 1][1], tree[root << 1 | 1][1]);
  }
}
void Update(int s, int e, int root) {
  if (s == e) {
    tree[root][0] = abs(a[s]);
    tree[root][1] = cha[s];
  } else {
    int mid = (s + e) >> 1;
    int flag1 = 1, flag2 = 1;
    for (int i = 0; i < o; i++) {
      if (ch[i] < s || ch[i] > e) continue;
      if (ch[i] <= mid && flag1) {
        Update(s, mid, root << 1);
        flag1 = 0;
      } else if (ch[i] > mid && flag2) {
        Update(mid + 1, e, root << 1 | 1);
        flag2 = 0;
      }
    }
    tree[root][0] = tree[root << 1][0] + tree[root << 1 | 1][0];
    tree[root][1] = min(tree[root << 1][1], tree[root << 1 | 1][1]);
  }
}
void change(int pos) { cha[pos] = max(zero, a[pos - 1]) + max(zero, -a[pos]); }
long long findmin(int s, int e, int root) {
  if (l <= s && e <= r) {
    return tree[root][1];
  } else {
    int mid = (s + e) >> 1;
    long long a = 2000000000, b = 2000000000;
    if (l <= mid) {
      a = findmin(s, mid, root << 1);
    }
    if (r > mid) {
      b = findmin(mid + 1, e, root << 1 | 1);
    }
    return min(a, b);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    a[i] -= a[i + 1];
    if (i > 1 && i < n) {
      cha[i] = max(zero, a[i - 1]) + max(zero, -a[i]);
    }
  }
  a[n] = 0;
  cha[1] = 2000000000;
  cha[n] = 2000000000;
  buildsum(1, n - 1, 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int k;
    long long x;
    scanf("%d%d%d%lld", &k, &l, &r, &x);
    if (k == 1) {
      if (l == r) {
        if (l == 1) {
          printf("%lld\n", tree[1][0] - abs(a[1]) + abs(a[1] + x));
        } else if (l == n) {
          printf("%lld\n", tree[1][0] - abs(a[l - 1]) + abs(a[l - 1] - x));
        } else {
          printf("%lld\n", tree[1][0] - abs(a[l]) - abs(a[l - 1]) +
                               abs(a[l] + x) + abs(a[l - 1] - x));
        }
      } else {
        long long p = findmin(1, n - 1, 1);
        printf("%lld\n", tree[1][0] + 2 * max(zero, abs(x) - p));
      }
    } else {
      o = 0;
      if (l == r) {
        if (l == 1) {
          a[1] += x;
          change(2);
          ch[o++] = 1;
          ch[o++] = 2;
        } else if (l == n) {
          a[l - 1] -= x;
          change(l - 1);
          ch[o++] = l - 1;
        } else {
          a[l - 1] -= x;
          a[l] += x;
          change(l - 1);
          change(l);
          change(l + 1);
          ch[o++] = l - 1;
          ch[o++] = l;
          ch[o++] = l + 1;
        }
      } else {
        if (l != 1) {
          a[l - 1] -= x;
          change(l - 1);
          change(l);
          ch[o++] = l - 1;
          ch[o++] = l;
        }
        if (r != n) {
          a[r] += x;
          change(r);
          change(r + 1);
          ch[o++] = r;
          ch[o++] = r + 1;
        }
      }
      Update(1, n - 1, 1);
    }
  }
  return 0;
}
