#include <bits/stdc++.h>
using std::max;
using std::min;
const int N = 100005;
long long t[N << 2], a[N], sum;
int n, l, r, x, Q, opt;
long long cal(int x) {
  if (x == 1 || x == n) return 1000000000000000;
  return -min(a[x], 0ll) + max(a[x + 1], 0ll);
}
long long Abs(long long x) { return x < 0 ? -x : x; }
void modify(int k, int L, int R, int x) {
  if (L == R) {
    t[k] = cal(x);
    return;
  }
  int mid = (L + R) >> 1;
  if (x <= mid)
    modify(k << 1, L, mid, x);
  else
    modify(k << 1 | 1, mid + 1, R, x);
  t[k] = std::min(t[k << 1], t[k << 1 | 1]);
}
long long query(int k, int L, int R, int l, int r) {
  if (L == l && R == r) return t[k];
  int mid = (L + R) >> 1;
  if (r <= mid) return query(k << 1, L, mid, l, r);
  if (l > mid) return query(k << 1 | 1, mid + 1, R, l, r);
  return min(query(k << 1, L, mid, l, mid),
             query(k << 1 | 1, mid + 1, R, mid + 1, r));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = n; i >= 2; i--) a[i] = a[i] - a[i - 1], sum += Abs(a[i]);
  modify(1, 1, n, 1), modify(1, 1, n, n);
  for (int i = 2; i < n; i++) modify(1, 1, n, i);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d%d%d", &opt, &l, &r, &x);
    if (opt == 1) {
      if (l == r) {
        printf("%lld\n", sum - Abs(a[l]) - Abs(a[l + 1]) + Abs(a[l] + x) +
                             Abs(a[l + 1] - x));
        continue;
      }
      long long tt = query(1, 1, n, l, r);
      if (tt > x)
        printf("%lld\n", sum);
      else
        printf("%lld\n", sum + 2 * (x - tt));
    } else {
      sum = sum - Abs(a[l]) - Abs(a[r + 1]);
      a[l] += x, a[r + 1] -= x;
      sum = sum + Abs(a[l]) + Abs(a[r + 1]);
      modify(1, 1, n, l), modify(1, 1, n, r + 1);
      modify(1, 1, n, l - 1), modify(1, 1, n, r);
    }
  }
}
