#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int cur;
  long long int lr;
  long long int e;
  long long int f;
  long long int rl;
  node() {}
  node(long long int cur, long long int lr, long long int e, long long int f,
       long long int rl)
      : cur(cur), lr(lr), e(e), f(f), rl(rl) {}
  void update(node &elem) {
    lr += elem.lr + cur - elem.cur;
    e += elem.e + cur - elem.cur;
    f += elem.f + cur - elem.cur;
    rl += elem.rl + cur - elem.cur;
    cur = elem.cur;
    return;
  }
  long long int get_maxi(long long int x) {
    long long int v1 = max(lr, rl);
    long long int v2 = max(-2 * x + e, 2 * x + f);
    return max(v1, v2);
  }
};
const int MAXN = (int)1e5 + 5;
const long long int INF = (long long int)1e16;
int v[MAXN];
node tree[4 * MAXN];
long long int delta[MAXN];
node max(node &x, node &y) {
  return node(0, max(x.lr, y.lr), max(x.e, y.e), max(x.f, y.f),
              max(x.rl, y.rl));
}
void init(int idx, int a, int b) {
  if (a == b) {
    long long int cur = abs(delta[a - 1]) + abs(delta[a]);
    long long int lr = v[a - 1] - v[a + 1];
    long long int e = v[a - 1] + v[a + 1] - 2 * v[a];
    long long int f = 2 * v[a] - v[a - 1] - v[a + 1];
    long long int rl = v[a + 1] - v[a - 1];
    tree[idx] = node(cur, lr - cur, e - cur, f - cur, rl - cur);
    return;
  }
  int mid = (a + b) / 2;
  init(idx * 2, a, mid);
  init(idx * 2 + 1, mid + 1, b);
  tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]);
  return;
}
node query(int idx, int a, int b, int l, int r) {
  if (b < l || a > r) {
    return node(0, -INF, -INF, -INF, -INF);
  }
  if (l <= a && b <= r) {
    return tree[idx];
  }
  int mid = (a + b) / 2;
  node q1 = query(idx * 2, a, mid, l, r);
  node q2 = query(idx * 2 + 1, mid + 1, b, l, r);
  return max(q1, q2);
}
void update(int idx, int a, int b, int l, int r, node elem) {
  if (b < l || a > r) {
    return;
  }
  if (l <= a && b <= r) {
    tree[idx].update(elem);
    return;
  }
  int mid = (a + b) / 2;
  update(idx * 2, a, mid, l, r, elem);
  update(idx * 2 + 1, mid + 1, b, l, r, elem);
  tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]);
  return;
}
int main(void) {
  int n, q;
  int t, l, r, x;
  long long int sum = 0;
  scanf(" %d", &n);
  v[0] = v[n + 1] = 0;
  for (int i = 1; i <= n; i++) {
    scanf(" %d", &v[i]);
  }
  for (int i = 1; i < n; i++) {
    sum += abs(v[i] - v[i + 1]);
    delta[i] = v[i] - v[i + 1];
  }
  init(1, 1, n);
  scanf(" %d", &q);
  while (q--) {
    scanf(" %d %d %d %d", &t, &l, &r, &x);
    if (t == 1) {
      long long int res = query(1, 1, n, l, r).get_maxi(x);
      printf("%lld\n", sum + res);
    } else {
      sum -= abs(delta[l - 1]);
      sum -= abs(delta[r]);
      delta[l - 1] -= x;
      delta[r] += x;
      sum += abs(delta[l - 1]);
      sum += abs(delta[r]);
      if (l == r) {
        update(1, 1, n, l - 1, l - 1,
               node(abs(delta[l - 2]) + abs(delta[l - 1]), -x, +x, -x, +x));
        update(1, 1, n, l, l,
               node(abs(delta[l - 1]) + abs(delta[l]), 0, -2 * x, +2 * x, 0));
        update(1, 1, n, r + 1, r + 1,
               node(abs(delta[r]) + abs(delta[r + 1]), +x, +x, -x, -x));
      } else {
        update(1, 1, n, l - 1, l - 1,
               node(abs(delta[l - 2]) + abs(delta[l - 1]), -x, +x, -x, +x));
        update(1, 1, n, l, l,
               node(abs(delta[l - 1]) + abs(delta[l]), -x, -x, +x, +x));
        update(1, 1, n, r, r,
               node(abs(delta[r - 1]) + abs(delta[r]), +x, -x, +x, -x));
        update(1, 1, n, r + 1, r + 1,
               node(abs(delta[r]) + abs(delta[r + 1]), +x, +x, -x, -x));
      }
    }
  }
  return 0;
}
