#include <bits/stdc++.h>
using namespace std;
set<int> sp, sv;
const int N = 100010;
const long long INF = 1LL << 60;
long long d[N], ca[N];
int a[N], n;
bool peak[N], valley[N];
long long tmin[N << 2];
struct zkw_segment_tree {
  int M = 1, len = 0;
  void init(int LEN) {
    len = LEN;
    for (M = 1; M <= len + 1; M <<= 1)
      ;
  }
  void update(int x, long long w) {
    for (tmin[x += M] = w, x >>= 1; x; x >>= 1)
      tmin[x] = min(tmin[x << 1], tmin[x << 1 | 1]);
  }
  long long query(int l, int r) {
    if (l > r) return INF;
    if (l == r) return tmin[l + M];
    long long ans = INF;
    for (l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (!(l & 1)) ans = min(ans, tmin[l ^ 1]);
      if (r & 1) ans = min(ans, tmin[r ^ 1]);
    }
    return ans;
  }
} t;
int has(const set<int> &s, int l, int r) {
  auto it = s.lower_bound(l);
  if (it == s.end()) return -1;
  return ((*it) <= r ? (*it) : -1);
}
void check(int x) {
  if (x <= 1 || x >= n) return;
  long long tmp = max(-d[x], d[x + 1]);
  if (tmp != ca[x]) {
    ca[x] = tmp;
    t.update(x, tmp);
  }
  if ((ca[x] > 0) ^ !peak[x]) {
    peak[x] ^= 1;
    if (ca[x] <= 0)
      sp.insert(x);
    else
      sp.erase(x);
  }
  if ((d[x] < 0 && d[x + 1] > 0) ^ valley[x]) {
    valley[x] ^= 1;
    if (d[x] < 0 && d[x + 1] > 0)
      sv.insert(x);
    else
      sv.erase(x);
  }
}
long long delta(int pos, long long x) {
  return -abs(d[pos]) - abs(d[pos + 1]) + abs(x + d[pos]) + abs(d[pos + 1] - x);
}
int main() {
  scanf("%d%d%d", &n, a + 1, a + 2);
  t.init(n);
  d[2] = a[2] - a[1];
  long long sum = abs(d[2]);
  for (int i = 3; i <= n; ++i) {
    scanf("%d", a + i);
    d[i] = a[i] - a[i - 1];
    sum += abs(d[i]);
    check(i - 1);
  }
  int Q, op, l, r;
  long long x;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d%d%lld", &op, &l, &r, &x);
    if (op == 2) {
      sum -= abs(d[l]) + abs(d[r + 1]);
      d[l] += x;
      d[r + 1] -= x;
      sum += abs(d[l]) + abs(d[r + 1]);
      check(l - 1);
      check(l);
      check(r);
      check(r + 1);
      continue;
    }
    if (l == r)
      printf("%lld\n", sum + delta(l, x));
    else if (has(sp, l, r) != -1)
      printf("%lld\n", sum + x * 2);
    else {
      int pos = has(sv, l, r);
      if (pos == -1)
        printf("%lld\n", sum + max((x - t.query(l, r)) << 1, 0LL));
      else {
        long long tmp = min(t.query(l, pos - 1), t.query(pos + 1, r));
        tmp = max((x - tmp) << 1, 0LL);
        printf("%lld\n", sum + max(delta(pos, x), tmp));
      }
    }
  }
  return 0;
}
