#include <bits/stdc++.h>
template <class T>
inline bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool cmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
char ss[1 << 17], *A = ss, *B = ss;
inline char gc() {
  return A == B && (B = (A = ss) + fread(ss, 1, 1 << 17, stdin), A == B) ? -1
                                                                         : *A++;
}
template <class T>
inline void sd(T& x) {
  char c;
  T y = 1;
  while (c = gc(), (c < 48 || 57 < c) && c != -1)
    if (c == 45) y = -1;
  x = c - 48;
  while (c = gc(), 47 < c && c < 58) x = x * 10 + c - 48;
  x *= y;
}
char sr[1 << 21], z[20];
int C = -1, Z;
inline void Ot() { fwrite(sr, 1, C + 1, stdout), C = -1; }
template <class T>
inline void we(T x) {
  if (C > 1 << 20) Ot();
  if (x < 0) sr[++C] = 45, x = -x;
  while (z[++Z] = x % 10 + 48, x /= 10)
    ;
  while (sr[++C] = z[Z], --Z)
    ;
  sr[++C] = '\n';
}
const int N = 1e5 + 5;
const long long inf = 1e18;
int n, m;
long long ans, a[N], tr[N << 2];
inline void up(int p) { tr[p] = min(tr[p << 1], tr[p << 1 | 1]); }
void build(int p, int L, int R) {
  if (L == R) {
    if (L > 1) tr[p] = max(0ll, a[L]) + max(0ll, -a[L - 1]);
    ans += abs(a[L]);
    return;
  }
  int mid = (L + R) >> 1;
  build(p << 1, L, mid), build(p << 1 | 1, mid + 1, R);
  up(p);
}
void mdy(int p, int L, int R, int x, int w) {
  if (L == R) {
    ans += abs(a[L] + w) - abs(a[L]), a[L] += w;
    if (x > 1) tr[p] = max(0ll, -a[L - 1]) + max(0ll, a[L]);
    if (w && x < n - 1) mdy(1, 1, n - 1, x + 1, 0);
    return;
  }
  int mid = (L + R) >> 1;
  if (x <= mid)
    mdy(p << 1, L, mid, x, w);
  else
    mdy(p << 1 | 1, mid + 1, R, x, w);
  up(p);
}
long long qry(int p, int L, int R, int a, int b) {
  if (a <= L && R <= b) return tr[p];
  int mid = (L + R) >> 1;
  if (b <= mid) return qry(p << 1, L, mid, a, b);
  if (a > mid) return qry(p << 1 | 1, mid + 1, R, a, b);
  return min(qry(p << 1, L, mid, a, b), qry(p << 1 | 1, mid + 1, R, a, b));
}
int main() {
  sd(n);
  int op, l, r, x;
  for (register int i = 1, I = n + 1; i < I; ++i) sd(a[i]);
  for (register int i = 1, I = n + 1; i < I; ++i) a[i] = a[i + 1] - a[i];
  build(1, 1, n - 1);
  sd(m);
  while (m--) {
    sd(op), sd(l), sd(r), sd(x);
    if (op == 1) {
      if (l == r) {
        if (l == 1)
          we(ans - abs(a[l]) + abs(a[l] - x));
        else if (l == n)
          we(ans - abs(a[l - 1]) + abs(a[l - 1] + x));
        else
          we(ans - abs(a[l - 1]) - abs(a[l]) + abs(a[l - 1] + x) +
             abs(a[l] - x));
      } else {
        long long tp = 2 * (x - qry(1, 1, n - 1, l > 1 ? l : 2, r));
        if (l == 1) cmax(tp, -abs(a[l]) + abs(a[l] - x));
        if (r == n) cmax(tp, -abs(a[r - 1]) + abs(a[r - 1] + x));
        we(ans + max(0ll, tp));
      }
    } else {
      l > 1 ? mdy(1, 1, n - 1, l - 1, x) : void();
      r < n ? mdy(1, 1, n - 1, r, -x) : void();
    }
  }
  return Ot(), 0;
}
