#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
const int maxn = maxN * 8;
struct Tree {
  int l, r, minx, npos;
  long long sum;
};
int max_idx = 0;
int seek_idx = 0;
Tree node[maxn];
int diff[maxn];
void PushUp(int i) {
  node[i].npos = node[i << 1].npos + node[(i << 1) | 1].npos;
  node[i].sum = node[i << 1].sum + node[(i << 1) | 1].sum;
  node[i].minx = min(node[i << 1].minx, node[(i << 1) | 1].minx);
}
void build(int i, int l, int r) {
  max_idx = max(i, max_idx);
  node[i].l = l;
  node[i].r = r;
  if (l == r) {
    node[i].minx = abs(diff[l]);
    node[i].sum = diff[l];
    node[i].npos = diff[l] > 0;
    return;
  }
  int mid = (l + r) / 2;
  build(i << 1, l, mid);
  build((i << 1) | 1, mid + 1, r);
  PushUp(i);
}
long long getsum(int i, int l, int r) {
  if (node[i].l == l && node[i].r == r) return node[i].sum;
  int mid = (node[i].l + node[i].r) / 2;
  if (r <= mid)
    return getsum(i << 1, l, r);
  else if (l > mid)
    return getsum((i << 1) | 1, l, r);
  else
    return getsum(i << 1, l, mid) + getsum((i << 1) | 1, mid + 1, r);
}
int getmin(int i, int l, int r) {
  if (node[i].l == l && node[i].r == r) return node[i].minx;
  int mid = (node[i].l + node[i].r) / 2;
  if (r <= mid)
    return getmin(i << 1, l, r);
  else if (l > mid)
    return getmin((i << 1) | 1, l, r);
  else
    return min(getmin(i << 1, l, mid), getmin((i << 1) | 1, mid + 1, r));
}
int getnpos(int i, int l, int r) {
  seek_idx = max(seek_idx, i);
  if (node[i].l == l && node[i].r == r) return node[i].npos;
  int mid = (node[i].l + node[i].r) / 2;
  if (r <= mid)
    return getnpos(i << 1, l, r);
  else if (l > mid)
    return getnpos((i << 1) | 1, l, r);
  else
    return getnpos(i << 1, l, mid) + getnpos((i << 1) | 1, mid + 1, r);
}
void add(int i, int k, int v) {
  if (node[i].l == k && node[i].r == k) {
    node[i].sum += v;
    node[i].minx = abs(node[i].sum);
    node[i].npos = node[i].sum > 0;
    return;
  }
  int mid = (node[i].l + node[i].r) / 2;
  if (k <= mid)
    add(i << 1, k, v);
  else
    add((i << 1) | 1, k, v);
  PushUp(i);
}
long long a[maxN];
int find_first(int l, int r) {
  int low = l;
  int high = r;
  int ans = -1;
  while (low <= high) {
    int mid = (low + high) >> 1;
    if (getnpos(1, l, mid) > 0) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return ans;
}
int find_last(int l, int r) {
  int low = l;
  int high = r;
  int ans = -1;
  while (low <= high) {
    int mid = (low + high) >> 1;
    if (getnpos(1, mid, r) == r - mid + 1) {
      high = mid - 1;
    } else {
      ans = mid;
      low = mid + 1;
    }
  }
  return ans;
}
bool debug = false;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long fA = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    diff[i] = a[i] - a[i - 1];
    if (i >= 2) fA += abs(diff[i]);
  }
  if (debug) cout << "debug init fA " << fA << endl;
  build(1, 1, n);
  if (debug) cout << "debug max_idx " << max_idx << endl;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t, l, r, x;
    cin >> t >> l >> r >> x;
    if (t == 2) {
      if (debug) cout << "debug before change fA " << fA << endl;
      long long old = getsum(1, 1, l) - getsum(1, 1, l - 1);
      long long now = old + x;
      if (debug) cout << "L old " << old << " now " << now << endl;
      fA += abs(now) - abs(old);
      if (r < n) {
        old = getsum(1, 1, r + 1) - getsum(1, 1, r);
        now = old - x;
        if (debug) cout << "R old " << old << " now " << now << endl;
        fA += abs(now) - abs(old);
      }
      add(1, l, x);
      add(1, r + 1, -x);
      if (debug) cout << "debug after change fA " << fA << endl;
    } else {
      long long maxt = -(1LL << 60);
      if (r == n) {
        long long origin_i = getsum(1, 1, i) - getsum(1, 1, i - 1);
        long long tmp = abs(origin_i + x) - abs(origin_i);
        if (maxt < tmp) maxt = tmp;
        r--;
      }
      if (r - l <= 5) {
        for (int i = l; i <= r; i++) {
          long long origin_i = getsum(1, 1, i) - getsum(1, 1, i - 1);
          long long origin_i1 = getsum(1, 1, i + 1) - getsum(1, 1, i);
          long long tmp = abs(origin_i + x) + abs(origin_i1 - x) -
                          abs(origin_i) - abs(origin_i1);
          if (maxt < tmp) maxt = tmp;
        }
      } else {
        r++;
        int pos_idx = find_first(l, r);
        if (pos_idx < 0) {
          int min_v = getmin(1, l, r - 1);
          if (x > min_v)
            maxt = max(maxt, 2LL * (x - min_v));
          else
            maxt = max(maxt, 0LL);
          goto xxx;
        }
        int neg_idx = find_last(l, r);
        if (neg_idx < 0) {
          int min_v = getmin(1, l + 1, r);
          if (x > min_v)
            maxt = max(maxt, 2LL * (x - min_v));
          else
            maxt = max(maxt, 0LL);
          goto xxx;
        }
        if (pos_idx < neg_idx) {
          maxt = max(maxt, 2LL * x);
        } else {
          if (neg_idx - l >= 1) {
            int min_neg = getmin(1, l, neg_idx - 1);
            if (x > min_neg)
              maxt = max(maxt, 2LL * (x - min_neg));
            else
              maxt = max(maxt, 0LL);
          }
          if (r - pos_idx >= 1) {
            int min_pos = getmin(1, pos_idx + 1, r);
            if (x > min_pos)
              maxt = max(maxt, 2LL * (x - min_pos));
            else
              maxt = max(maxt, 0LL);
          }
          long long ori_neg = getsum(1, 1, neg_idx) - getsum(1, 1, neg_idx - 1);
          long long ori_pos = getsum(1, 1, pos_idx) - getsum(1, 1, pos_idx - 1);
          maxt = max(maxt, abs(ori_neg + x) + abs(ori_pos - x) - abs(ori_neg) -
                               abs(ori_pos));
        }
      }
    xxx:
      if (debug) cout << "seek_idx " << seek_idx << endl;
      cout << fA + maxt << endl;
    }
  }
  return 0;
}
