#include <bits/stdc++.h>
using namespace std;
long long int Pow(long long int a, long long int b, long long int md,
                  long long int ans = 1) {
  for (; b; b >>= 1, a = a * a % md)
    if (b & 1) ans = ans * a % md;
  return ans % md;
}
const long long int MAXN = 1e5 + 10;
const long long int INF = 1e18;
const long long int MOD = 1e9 + 7;
long long int A[MAXN], B[MAXN], seg[MAXN << 2], n, q, ans = 0;
void update(long long int pos, long long int x, long long int id = 1,
            long long int l = 0, long long int r = MAXN) {
  if (r - l == 1) {
    ans -= abs(B[l]);
    B[l] += x;
    ans += abs(B[l]);
    seg[id] = max(0LL, -B[l]) + max(0LL, B[r]);
    return;
  }
  long long int mid = (l + r) >> 1;
  if (pos < mid)
    update(pos, x, id << 1, l, mid);
  else
    update(pos, x, id << 1 | 1, mid, r);
  seg[id] = min({seg[id << 1 | 1], seg[id << 1],
                 max(0LL, -B[mid - 1]) + max(0LL, B[mid])});
}
long long int get(long long int ql, long long int qr, long long int id = 1,
                  long long int l = 0, long long int r = MAXN) {
  if (qr <= l || r <= ql) return INF;
  if (ql <= l && r <= qr) return seg[id];
  long long int mid = (l + r) >> 1;
  return min(get(ql, qr, id << 1, l, mid), get(ql, qr, id << 1 | 1, mid, r));
}
int main() {
  fill(seg, seg + MAXN * 4, INF);
  scanf("%lld", &n);
  for (long long int i = 1; i <= n; i++) {
    scanf("%lld", &A[i]);
  }
  for (long long int i = 1; i < n; i++) {
    update(i, A[i + 1] - A[i]);
    update(i - 1, 0);
  }
  scanf("%lld", &q);
  while (q--) {
    long long int t, l, r, x;
    scanf("%lld%lld%lld%lld", &t, &l, &r, &x);
    if (t == 1) {
      if (r == l) {
        printf("%lld\n", ans - abs(B[l - 1]) - abs(B[l]) + abs(B[l - 1] + x) +
                             abs(B[l] - x));
      } else {
        printf("%lld\n", ans + max(0LL, 2 * x - get(l - 1, r) * 2));
      }
    } else {
      update(l - 1, x), update(l - 2, 0), update(r, -x), update(r - 1, 0);
    }
  }
  return 0;
}
