#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, q;
struct tree {
  int l, r;
  long long minn;
} tr[4 * N];
long long a[N];
int l, r, v, p, x;
long long ans = 0;
long long abss(long long x) { return x < 0 ? -x : x; }
void build(int i, int l, int r) {
  tr[i].l = l, tr[i].r = r;
  if (l == r) {
    ans += abss(a[l]);
    if (l > 1) tr[i].minn = max(0ll, -a[l - 1]) + max(0ll, a[l]);
    return;
  }
  int mid = l + r >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  tr[i].minn = min(tr[i << 1].minn, tr[i << 1 | 1].minn);
}
void modify(int i, int pos, int x) {
  int L = tr[i].l, R = tr[i].r;
  if (L == R) {
    ans -= abss(a[L]);
    a[L] += x;
    ans += abss(a[L]);
    if (pos > 1) tr[i].minn = max(0ll, -a[L - 1]) + max(0ll, a[R]);
    if (x && pos < n - 1) modify(1, pos + 1, 0);
    return;
  }
  int mid = L + R >> 1;
  if (mid >= pos)
    modify(i << 1, pos, x);
  else
    modify(i << 1 | 1, pos, x);
  tr[i].minn = min(tr[i << 1].minn, tr[i << 1 | 1].minn);
}
long long query(int i, int l, int r) {
  int L = tr[i].l, R = tr[i].r;
  if (L > r || l > R) return 1e18;
  if (l <= L && R <= r) return tr[i].minn;
  long long as = query(i << 1, l, r);
  as = min(as, query(i << 1 | 1, l, r));
  return as;
}
void pr_tree(int i) {
  int L = tr[i].l, R = tr[i].r;
  cerr << "L"
       << "=" << L << " ",
      cerr << "R"
           << "=" << R << " ",
      cerr << "tr[i].minn"
           << "=" << tr[i].minn << " " << endl;
  if (L == R) return;
  pr_tree(i << 1), pr_tree(i << 1 | 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) a[i] = a[i + 1] - a[i];
  build(1, 1, n - 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d%d", &p, &l, &r, &x);
    if (p == 1) {
      if (l == r) {
        if (l == 1)
          printf("%I64d\n", ans - abss(a[1]) + abss(a[1] - x));
        else if (l == n)
          printf("%I64d\n", ans - abss(a[n - 1]) + abss(a[n - 1] + x));
        else
          printf("%I64d\n", ans - abss(a[l]) - abss(a[l - 1]) +
                                abss(a[l - 1] + x) + abss(a[l] - x));
      } else {
        long long del = 0;
        del = max(del, 2 * x - 2 * query(1, (l > 1 ? l : l + 1), r));
        if (l == 1) del = max(del, -abss(a[l]) + abss(a[l] - x));
        if (r == n) del = max(del, -abss(a[r - 1]) + abss(a[r - 1] + x));
        printf("%I64d\n", ans + del);
      }
    } else {
      if (l > 1) modify(1, l - 1, x);
      if (r < n) modify(1, r, -x);
    }
  }
}
