#include <bits/stdc++.h>
inline long long read() {
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  long long k = 0, kk = 1;
  if (c == '-') c = getchar(), kk = -1;
  while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
  return kk * k;
}
using namespace std;
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x / 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
long long mi[1000010], a[1000010], n, q, c, x, y, z, sum, kkk;
void build(long long l, long long r, long long d) {
  if (l == r) {
    mi[d] = max(0ll, -a[l]) + max(0ll, a[l + 1]);
    return;
  }
  long long m = (l + r) >> 1;
  build(l, m, d * 2);
  build(m + 1, r, d * 2 + 1);
  mi[d] = min(mi[d * 2], mi[d * 2 + 1]);
}
void put(long long x, long long l, long long r, long long d) {
  if (x < 1 || x > n) return;
  if (l == r) {
    mi[d] = max(0ll, -a[l]) + max(0ll, a[l + 1]);
    return;
  }
  long long m = (l + r) >> 1;
  if (x <= m)
    put(x, l, m, d * 2);
  else
    put(x, m + 1, r, d * 2 + 1);
  mi[d] = min(mi[d * 2], mi[d * 2 + 1]);
}
long long find(long long x, long long y, long long l, long long r,
               long long d) {
  if (x <= l && y >= r) return mi[d];
  long long m = (l + r) >> 1;
  if (x <= m && y > m)
    return min(find(x, y, l, m, d * 2), find(x, y, m + 1, r, d * 2 + 1));
  if (x <= m)
    return find(x, y, l, m, d * 2);
  else
    return find(x, y, m + 1, r, d * 2 + 1);
}
long long calc(long long x, long long y, long long z) {
  kkk++;
  if (x == y) {
    if (x == 1) return z - max(0ll, a[x + 1]);
    if (x == n) return z - max(0ll, -a[x]);
    return abs(a[x] + z) + abs(a[x + 1] - z) - abs(a[x]) - abs(a[x + 1]);
  }
  long long ans = 0;
  if (x == 1) x++, ans = max(ans, z - max(0ll, a[2]) * 2);
  if (y == n) y--, ans = max(ans, z - max(0ll, -a[n]) * 2);
  ans = max(ans, z * 2 - find(x, y, 1, n, 1) * 2);
  return ans;
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = n; i >= 1; i--)
    a[i] -= a[i - 1], sum += i > 1 ? abs(a[i]) : 0;
  build(1, n, 1);
  q = read();
  while (q--) {
    c = read();
    x = read();
    y = read();
    z = read();
    if (c == 1)
      writeln(calc(x, y, z) + sum);
    else {
      y++;
      sum -= x > 1 && x <= n ? abs(a[x]) : 0;
      sum -= y > 1 && y <= n ? abs(a[y]) : 0;
      a[x] += z;
      a[y] -= z;
      sum += x > 1 && x <= n ? abs(a[x]) : 0;
      sum += y > 1 && y <= n ? abs(a[y]) : 0;
      put(x, 1, n, 1);
      put(y, 1, n, 1);
      put(x - 1, 1, n, 1);
      put(y - 1, 1, n, 1);
      put(x + 1, 1, n, 1);
      put(y + 1, 1, n, 1);
    }
  }
}
