#include <bits/stdc++.h>
using namespace std;
template <class I, class BiOp = I (*)(I, I)>
class SegTree {
  int n;
  std::vector<I> dat;
  BiOp op;
  I e;

 public:
  SegTree(int n_, BiOp op, I e) : op(op), e(e) {
    n = 1;
    while (n < n_) {
      n *= 2;
    }
    dat.resize(2 * n);
    for (int i = 0; i < 2 * n - 1; i++) {
      dat[i] = e;
    }
  }
  void update(int k, I v) {
    k += n - 1;
    dat[k] = v;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  void update_array(int k, int len, const I *vals) {
    for (int i = 0; i < len; ++i) {
      update(k + i, vals[i]);
    }
  }
  void update_all(const I *vals, int len) {
    for (int k = 0; k < std::min(n, len); ++k) {
      dat[k + n - 1] = vals[k];
    }
    for (int k = std::min(n, len); k < n; ++k) {
      dat[k + n - 1] = e;
    }
    for (int b = n / 2; b >= 1; b /= 2) {
      for (int k = 0; k < b; ++k) {
        dat[k + b - 1] = op(dat[k * 2 + b * 2 - 1], dat[k * 2 + b * 2]);
      }
    }
  }
  I querySub(int a, int b) const {
    I left = e;
    I right = e;
    a += n - 1;
    b += n - 1;
    while (a < b) {
      if ((a & 1) == 0) {
        left = op(left, dat[a]);
      }
      if ((b & 1) == 0) {
        right = op(dat[b - 1], right);
      }
      a = a / 2;
      b = (b - 1) / 2;
    }
    return op(left, right);
  }
  I query(int a, int b) const { return querySub(a, b + 1); }
};
struct pmin {
  long long int operator()(long long int x, long long int y) const {
    return min(x, y);
  }
};
const long long int inf = 1e16;
const int N = 100100;
long long int a[N], b[N];
long long int btot = 0;
SegTree<long long int, pmin> *st;
void upd_seg(int idx) {
  long long int u = b[idx];
  long long int v = b[idx + 1];
  long long int val = 0;
  if (u >= 0 && v <= 0) {
    val = 0;
  } else if (u >= 0 && v >= 0) {
    val = v;
  } else if (u <= 0 && v <= 0) {
    val = -u;
  } else {
    val = -u + v;
  }
  st->update(idx, val);
}
void add(int idx, long long int val) {
  btot -= abs(b[idx]);
  b[idx] += val;
  btot += abs(b[idx]);
  upd_seg(idx);
  upd_seg(idx - 1);
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n;
  for (int i = (int)(0); i < (int)(n); i++) cin >> a[i];
  for (int i = (int)(0); i < (int)(n); i++) {
    b[i] = a[i] - (i == 0 ? 0 : a[i - 1]);
  }
  cin >> q;
  for (int i = (int)(1); i < (int)(n); i++) btot += abs(b[i]);
  st = new SegTree<long long int, pmin>(n, pmin(), inf);
  for (int i = (int)(0); i < (int)(n - 1); i++) {
    upd_seg(i);
  }
  for (int i = (int)(0); i < (int)(q); i++) {
    int t, l, r;
    long long int x;
    cin >> t >> l >> r >> x;
    l--, r--;
    if (t == 2) {
      add(r + 1, -x);
      add(l, x);
      continue;
    }
    long long int ma = -inf;
    if (r - l <= 1) {
      for (int i = (int)(l); i < (int)(r + 1); i++) {
        long long int diff =
            abs(b[i] + x) + abs(b[i + 1] - x) - (abs(b[i]) + abs(b[i + 1]));
        ma = max(ma, diff);
      }
    } else {
      long long int segm = st->query(l, r);
      ma = max(0LL, 2 * (x - segm));
      int tgs[2] = {l, r};
      for (int dir = (int)(0); dir < (int)(2); dir++) {
        int i = tgs[dir];
        long long int diff =
            abs(b[i] + x) + abs(b[i + 1] - x) - (abs(b[i]) + abs(b[i + 1]));
        ma = max(ma, diff);
      }
    }
    cout << btot + ma << "\n";
  }
}
