#include <bits/stdc++.h>
using namespace std;
struct triple {
  long long val[3];
} TR[100005 * 4];
int n, q, l, r, x, t;
long long ans;
int a[100005];
long long S[100005 * 4];
void make_vals(triple &x, long long a, long long b, long long c) {
  if (b >= a && b >= c) {
    x.val[0] = 0;
    x.val[1] = -1000000000000000001;
    x.val[2] = -1000000000000000001;
    return;
  }
  if (max(a, c) >= b && min(a, c) <= b) {
    x.val[0] = -1000000000000000001;
    x.val[1] = -2ll * (max(a, c) - b);
    x.val[2] = -1000000000000000001;
    return;
  }
  if (b <= a && b <= c) {
    x.val[0] = -1000000000000000001;
    x.val[1] = -1000000000000000001;
    x.val[2] = -4ll * (min(a, c) - b) - 2ll * abs(a - c);
    return;
  }
}
triple merge(triple A, triple B) {
  triple res;
  for (int i = 0; i < 3; i++) res.val[i] = max(A.val[i], B.val[i]);
  return res;
}
triple get(int node, int bas, int son, int l, int r) {
  if (bas >= l && son <= r) return TR[node];
  if (((bas + son) >> 1) >= l && ((bas + son) >> 1) + 1 <= r)
    return merge(get(node * 2, bas, ((bas + son) >> 1), l, r),
                 get(node * 2 + 1, ((bas + son) >> 1) + 1, son, l, r));
  if (((bas + son) >> 1) >= l)
    return get(node * 2, bas, ((bas + son) >> 1), l, r);
  return get(node * 2 + 1, ((bas + son) >> 1) + 1, son, l, r);
}
void push(int node) {
  S[node * 2] += S[node];
  S[node * 2 + 1] += S[node];
  S[node] = 0;
}
long long gval(int node, int bas, int son, int x) {
  if (bas == x && son == x) return S[node];
  push(node);
  if (((bas + son) >> 1) >= x)
    return gval(node * 2, bas, ((bas + son) >> 1), x);
  return gval(node * 2 + 1, ((bas + son) >> 1) + 1, son, x);
}
void upTR(int node, int bas, int son, int x) {
  if (bas > x || son < x) return;
  if (bas == x && son == x) {
    make_vals(TR[node], gval(1, 1, n, bas), gval(1, 1, n, bas + 1),
              gval(1, 1, n, bas + 2));
    return;
  }
  upTR(node * 2, bas, ((bas + son) >> 1), x);
  upTR(node * 2 + 1, ((bas + son) >> 1) + 1, son, x);
  TR[node] = merge(TR[node * 2], TR[node * 2 + 1]);
}
void up(int node, int bas, int son, int l, int r, int x) {
  if (bas > r || son < l) return;
  if (bas >= l && son <= r) {
    S[node] += x;
    return;
  }
  push(node);
  up(node * 2, bas, ((bas + son) >> 1), l, r, x);
  up(node * 2 + 1, ((bas + son) >> 1) + 1, son, l, r, x);
}
void buildTR(int node, int bas, int son) {
  if (bas == son) {
    make_vals(TR[node], a[bas], a[bas + 1], a[bas + 2]);
    return;
  }
  buildTR(node * 2, bas, ((bas + son) >> 1));
  buildTR(node * 2 + 1, ((bas + son) >> 1) + 1, son);
  TR[node] = merge(TR[node * 2], TR[node * 2 + 1]);
}
void build(int node, int bas, int son) {
  if (bas == son) {
    S[node] = a[bas];
    return;
  }
  build(node * 2, bas, ((bas + son) >> 1));
  build(node * 2 + 1, ((bas + son) >> 1) + 1, son);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) ans += abs(a[i] - a[i + 1]);
  buildTR(1, 1, n - 2);
  build(1, 1, n);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d %d", &t, &l, &r, &x);
    if (t == 1) {
      triple res = get(1, 1, n - 2, l - 1, r - 1);
      if (res.val[1] != -1000000000000000001)
        res.val[1] = max(res.val[1], -2ll * x);
      if (l == r && res.val[2] != -1000000000000000001) {
        long long a = gval(1, 1, n, l - 1);
        long long b = gval(1, 1, n, l);
        long long c = gval(1, 1, n, r + 1);
        if (max(a, c) - b >= x)
          res.val[2] = -4ll * min(min(a, c) - b, 1ll * x) -
                       2ll * (1ll * x - min(min(a, c) - b, 1ll * x));
      }
      long long add = max(max(res.val[0], res.val[1]), res.val[2]);
      printf("%lld\n", add + 2ll * x + ans);
    } else {
      long long valL1 = gval(1, 1, n, l - 1);
      long long valL2 = gval(1, 1, n, l);
      ans += -abs(valL1 - valL2) + abs(valL1 - valL2 - x);
      long long valR1 = gval(1, 1, n, r);
      long long valR2 = gval(1, 1, n, r + 1);
      ans += -abs(valR1 - valR2) + abs(valR1 + x - valR2);
      up(1, 1, n, l, r, x);
      for (int i = max(1, l - 2); i <= min(l - 1, n - 2); i++)
        upTR(1, 1, n - 2, i);
      for (int i = max(1, r - 1); i <= min(r, n - 2); i++) upTR(1, 1, n - 2, i);
    }
  }
}
