#include <bits/stdc++.h>
int rd() {
  int k = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') k = k * 10 + c - 48, c = getchar();
  return k;
}
const int N = 100001;
long long Abs(long long x) { return x < 0 ? -x : x; }
long long Max(long long x, long long y) { return x > y ? x : y; }
long long Min(long long x, long long y) { return x < y ? x : y; }
int n, m, o, l, r, x;
long long s, a[N], t[N << 2];
void Make(int x, int l, int r) {
  if (l == r) {
    if (l > 1) t[x] = Max(0, a[l]) + Max(0, -a[l - 1]);
    s += Abs(a[l]);
    return;
  }
  int p = (l + r) >> 1, ls = x << 1, rs = ls | 1;
  Make(ls, l, p), Make(rs, p + 1, r), t[x] = Min(t[ls], t[rs]);
}
void Update(int x, int l, int r, int w, int v) {
  if (l == r) {
    s += Abs(a[l] + v) - Abs(a[l]), a[l] += v;
    if (l > 1) t[x] = Max(0, a[l]) + Max(0, -a[l - 1]);
    if (v && w < n - 1) Update(1, 1, n - 1, w + 1, 0);
    return;
  }
  int p = (l + r) >> 1, ls = x << 1, rs = ls | 1;
  if (w <= p)
    Update(ls, l, p, w, v);
  else
    Update(rs, p + 1, r, w, v);
  t[x] = Min(t[ls], t[rs]);
}
long long Query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return t[x];
  long long s = 9e18;
  int p = (l + r) >> 1, ls = x << 1, rs = ls | 1;
  if (L <= p) s = Min(s, Query(ls, l, p, L, R));
  if (p < R) s = Min(s, Query(rs, p + 1, r, L, R));
  return s;
}
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) a[i] = rd();
  for (int i = 1; i <= n; ++i) a[i] = a[i + 1] - a[i];
  Make(1, 1, n - 1), m = rd();
  while (m--) {
    o = rd(), l = rd(), r = rd(), x = rd();
    if (o == 1) {
      if (l == r) {
        if (l == 1)
          printf("%lld\n", s - Abs(a[1]) + Abs(a[1] - x));
        else if (l == n)
          printf("%lld\n", s - Abs(a[n - 1]) + Abs(a[n - 1] + x));
        else
          printf("%lld\n", s - Abs(a[l - 1]) - Abs(a[l]) + Abs(a[l - 1] + x) +
                               Abs(a[l] - x));
      } else {
        long long tmp = (x - Query(1, 1, n - 1, l > 1 ? l : 2, r)) * 2;
        if (l == 1) tmp = Max(tmp, Abs(a[1] - x) + Abs(a[1]));
        if (r == n) tmp = Max(tmp, Abs(a[n - 1] + x) - Abs(a[n - 1]));
        printf("%lld\n", Max(tmp, 0) + s);
      }
    } else {
      if (l > 1) Update(1, 1, n - 1, l - 1, x);
      if (r < n) Update(1, 1, n - 1, r, -x);
    }
  }
  return 0;
}
