#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, M = N << 2;
long long ans;
long long tr[M], a[N];
void pushup(long long p) { tr[p] = min(tr[p << 1], tr[p << 1 | 1]); }
void build(long long p, long long l, long long r) {
  if (l == r) {
    if (l > 1) tr[p] = max(-a[l - 1], 0ll) + max(a[l], 0ll);
    return;
  }
  long long mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void upt(long long p, long long l, long long r, long long pos, long long w) {
  if (l == r) {
    ans += abs(a[l] + w) - abs(a[l]);
    a[l] += w;
    if (l > 1) tr[p] = max(-a[l - 1], 0ll) + max(a[l], 0ll);
    return;
  }
  long long mid = (l + r) >> 1;
  if (pos <= mid)
    upt(p << 1, l, mid, pos, w);
  else
    upt(p << 1 | 1, mid + 1, r, pos, w);
  pushup(p);
}
long long query(long long p, long long l, long long r, long long ql,
                long long qr) {
  if (ql <= l && r <= qr) return tr[p];
  long long mid = (l + r) >> 1;
  if (qr <= mid) return query(p << 1, l, mid, ql, qr);
  if (mid + 1 <= ql) return query(p << 1 | 1, mid + 1, r, ql, qr);
  return min(query(p << 1, l, mid, ql, qr),
             query(p << 1 | 1, mid + 1, r, ql, qr));
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  for (long long i = 1; i < n; ++i) a[i] = a[i + 1] - a[i], ans += abs(a[i]);
  build(1, 1, n - 1);
  long long q, opt, l, r, x;
  cin >> q;
  while (q--) {
    cin >> opt >> l >> r >> x;
    if (opt == 2) {
      if (l >= 2) upt(1, 1, n - 1, l - 1, x), upt(1, 1, n - 1, l, 0);
      if (r < n) upt(1, 1, n - 1, r, -x), upt(1, 1, n - 1, r + 1, 0);
    } else {
      if (l == r) {
        if (l == 1)
          cout << ans - abs(a[l]) + abs(a[l] - x) << endl;
        else if (r == n)
          cout << ans - abs(a[r - 1]) + abs(a[r - 1] + x) << endl;
        else
          cout << ans - abs(a[l]) + abs(a[l] - x) - abs(a[l - 1]) +
                      abs(a[l - 1] + x)
               << endl;
      } else {
        long long tmp = 2ll * (x - query(1, 1, n - 1, l > 1 ? l : 2, r));
        if (l == 1) tmp = max(tmp, -abs(a[l]) + abs(a[l] - x));
        if (r == n) tmp = max(tmp, -abs(a[r - 1]) + abs(a[r - 1] + x));
        cout << ans + max(tmp, 0ll) << endl;
      }
    }
  }
  return 0;
}
