#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n;
long long a[MAXN], mi[MAXN << 2], ans;
const long long INF64 = 1LL << 60;
void pushup(int id) { mi[id] = min(mi[id << 1], mi[id << 1 | 1]); }
void build(int id, int l, int r) {
  if (l == r) {
    if (l > 1)
      mi[id] = max(0LL, -a[l - 1]) + max(0LL, a[l]);
    else
      mi[id] = INF64;
    ans += abs(a[l]);
    return;
  }
  int mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  pushup(id);
}
void update(int id, int l, int r, int L, int d) {
  if (L < l || L > r)
    while (1)
      ;
  if (l == r) {
    ans -= abs(a[l]);
    a[l] += d;
    ans += abs(a[l]);
    if (l > 1) mi[id] = max(0LL, -a[l - 1]) + max(0LL, a[l]);
    if (d && L < n - 1) update(1, 1, n - 1, L + 1, 0);
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= L)
    update(id << 1, l, mid, L, d);
  else
    update(id << 1 | 1, mid + 1, r, L, d);
  pushup(id);
}
long long query(int id, int l, int r, int L, int R) {
  if (l > R || r < L || l > r) return INF64;
  if (L <= l && r <= R) return mi[id];
  int mid = (l + r) >> 1;
  long long ans = INF64;
  if (L <= mid) ans = min(ans, query(id << 1, l, mid, L, R));
  if (R > mid) ans = min(ans, query(id << 1 | 1, mid + 1, r, L, R));
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n - 1; ++i) a[i] = a[i + 1] - a[i];
  build(1, 1, n - 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int op, l, r, x;
    scanf("%d%d%d%d", &op, &l, &r, &x);
    long long now = 0;
    if (op == 1) {
      if (l == r) {
        if (l == 1)
          now = ans - abs(a[1]) + abs(a[1] - x);
        else if (r == n)
          now = ans - abs(a[n - 1]) + abs(a[n - 1] + x);
        else
          now = ans - abs(a[l - 1]) - abs(a[l]) + abs(a[l - 1] + x) +
                abs(a[l] - x);
        printf("%I64d\n", now);
      } else {
        long long d = 0;
        if (l == 1) d = max(d, -abs(a[1]) + abs(a[1] - x)), ++l;
        if (r == n) d = max(d, -abs(a[n - 1]) + abs(a[n - 1] + x));
        d = max(d, 2 * x - 2 * query(1, 1, n - 1, l, r));
        printf("%I64d\n", ans + d);
      }
    } else {
      if (l > 1) update(1, 1, n - 1, l - 1, x);
      if (r < n) update(1, 1, n - 1, r, -x);
    }
  }
}
