#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
struct node {
  int l, r;
  long long val;
} tree[4 * maxn + 5];
long long a[maxn + 5], b[maxn + 5];
void build(int k, int l, int r) {
  tree[k].l = l;
  tree[k].r = r;
  if (l == r) {
    tree[k].val = min((long long)0, -b[l - 1]) + min((long long)0, b[l]);
    return;
  }
  int mid = (l + r) / 2;
  build(2 * k, l, mid);
  build(2 * k + 1, mid + 1, r);
  tree[k].val = max(tree[2 * k].val, tree[2 * k + 1].val);
}
void update(int k, int x) {
  if (tree[k].l == tree[k].r) {
    tree[k].val =
        min((long long)0, -b[tree[k].l - 1]) + min((long long)0, b[tree[k].l]);
    return;
  }
  int mid = (tree[k].l + tree[k].r) / 2;
  if (x <= mid)
    update(2 * k, x);
  else
    update(2 * k + 1, x);
  tree[k].val = max(tree[2 * k].val, tree[2 * k + 1].val);
}
long long query(int k, int l, int r) {
  if (tree[k].l >= l && tree[k].r <= r) {
    return tree[k].val;
  }
  int mid = (tree[k].l + tree[k].r) / 2;
  long long ans = -0xfffffffffffffff;
  if (l <= mid) ans = query(2 * k, l, r);
  if (r > mid) ans = max(ans, query(2 * k + 1, l, r));
  return ans;
}
int main() {
  int n, q;
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i < n; i++) {
    b[i] = a[i] - a[i + 1];
    sum += abs(b[i]);
  }
  build(1, 2, n - 1);
  scanf("%d", &q);
  while (q--) {
    int op, l, r;
    long long x;
    scanf("%d%d%d%lld", &op, &l, &r, &x);
    long long ans = -0xfffffffffffffff;
    if (op == 1) {
      if (l == 1) {
        ans = max(ans, abs(b[1] + x) - abs(b[1]));
        l++;
      }
      if (r == n) {
        ans = max(ans, abs(b[n - 1] - x) - abs(b[n - 1]));
        r--;
      }
      if (l == r)
        ans = max(
            ans, abs(b[l] + x) + abs(b[l - 1] - x) - abs(b[l]) - abs(b[l - 1]));
      else if (l < r) {
        ans = max(ans, max((long long)0, 2 * x + 2 * query(1, l, r)));
      }
      printf("%lld\n", ans + sum);
    } else {
      if (l != 1) {
        sum -= abs(b[l - 1]);
        b[l - 1] -= x;
        sum += abs(b[l - 1]);
        update(1, l);
        if (l > 2) update(1, l - 1);
      }
      if (r != n) {
        sum -= abs(b[r]);
        b[r] += x;
        sum += abs(b[r]);
        update(1, r);
        if (r < n - 1) update(1, r + 1);
      }
    }
  }
}
