#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long double dist(long double x, long double arayikhalatyan, long double x2,
                 long double y2) {
  return sqrt((x - x2) * (x - x2) +
              (arayikhalatyan - y2) * (arayikhalatyan - y2));
}
long long int S(long long int a) { return (a * (a - 1LL)) / 2; }
mt19937 rnd(363542);
char vow[] = {'a', 'e', 'i', 'o', 'u'};
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1, 0};
int dy[] = {-1, 0, 1, 0, -1, 1, -1, 1, 0};
const int N = 3e5 + 30;
const long long int mod = 1e15 + 7;
const long double pi = acos(-1);
const int T = 550;
long long int bp(long long int a, long long int b = mod - 2LL) {
  long long int ret = 1;
  while (b) {
    if (b & 1) ret *= a, ret %= mod;
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return ret;
}
ostream& operator<<(ostream& c, pair<int, int> a) {
  c << a.first << " " << a.second;
  return c;
}
template <class T>
void maxi(T& a, T b) {
  a = max(a, b);
}
int n, q;
long long int t[4 * N], flg[4 * N], sum;
void push(int nd) {
  t[nd] += flg[nd];
  flg[nd * 2] += flg[nd];
  flg[nd * 2 + 1] += flg[nd];
  flg[nd] = 0;
}
void upd(int l, int r, long long int x, int nl = 0, int nr = n - 1,
         int nd = 1) {
  push(nd);
  if (l > nr || r < nl) return;
  if (l == nl && r == nr) {
    flg[nd] += x;
    push(nd);
    return;
  }
  int mid = (nl + nr) / 2;
  upd(l, min(mid, r), x, nl, mid, nd * 2);
  upd(max(mid + 1, l), r, x, mid + 1, nr, nd * 2 + 1);
}
long long int qry(int q, int l = 0, int r = n - 1, int nd = 1) {
  push(nd);
  if (q > r || q < l) return 0;
  if (l == r) return t[nd];
  int mid = (l + r) / 2;
  return qry(q, l, mid, nd * 2) + qry(q, mid + 1, r, nd * 2 + 1);
}
long long int t1[4 * N];
void upd1(int q, long long int x, int nl = 0, int nr = n - 1, int nd = 1) {
  if (q > nr || q < nl) return;
  if (nl == nr) {
    t1[nd] = x;
    return;
  }
  int mid = (nl + nr) / 2;
  upd1(q, x, nl, mid, nd * 2);
  upd1(q, x, mid + 1, nr, nd * 2 + 1);
  t1[nd] = max(t1[nd * 2], t1[nd * 2 + 1]);
}
long long int qry1(int l, int r, int nl = 0, int nr = n - 1, int nd = 1) {
  if (l > nr || r < nl) return LLONG_MIN;
  if (l == nl && r == nr) return t1[nd];
  int mid = (nl + nr) / 2;
  return max(qry1(l, min(mid, r), nl, mid, nd * 2),
             qry1(max(mid + 1, l), r, mid + 1, nr, nd * 2 + 1));
}
long long int t2[4 * N];
void upd2(int q, long long int x, int nl = 0, int nr = n - 1, int nd = 1) {
  if (q > nr || q < nl) return;
  if (nl == nr) {
    t2[nd] = x;
    return;
  }
  int mid = (nl + nr) / 2;
  upd2(q, x, nl, mid, nd * 2);
  upd2(q, x, mid + 1, nr, nd * 2 + 1);
  t2[nd] = max(t2[nd * 2], t2[nd * 2 + 1]);
}
long long int qry2(int l, int r, int nl = 0, int nr = n - 1, int nd = 1) {
  if (l > nr || r < nl) return LLONG_MIN;
  if (l == nl && r == nr) return t2[nd];
  int mid = (nl + nr) / 2;
  return max(qry2(l, min(mid, r), nl, mid, nd * 2),
             qry2(max(mid + 1, l), r, mid + 1, nr, nd * 2 + 1));
}
void sm(int i) {
  if (i == 0 || i == n - 1) return;
  long long int a = max(0LL, qry(i - 1) - qry(i)),
                b = max(0LL, qry(i + 1) - qry(i));
  upd1(i, -2LL * min(a, b));
  upd2(i, -2LL * (a + b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    upd(i, i, x);
    if (i) sum += abs(x - qry(i - 1));
  }
  for (int i = 0; i < n; i++) sm(i);
  cin >> q;
  while (q--) {
    int A, l, r;
    long long int x;
    cin >> A >> l >> r >> x;
    l--, r--;
    if (A == 1) {
      long long int pat = -2LL * x;
      if (l == 0)
        maxi(pat, -abs(qry(0) - qry(1)) + abs(qry(0) + x - qry(1))), l++;
      if (r == n - 1)
        maxi(pat, abs(qry(r) + x - qry(r - 1)) - abs(qry(r) - qry(r - 1))), r--;
      if (r >= l) maxi(pat, qry1(l, r)), maxi(pat, qry2(l, r) + 2LL * x);
      cout << sum + pat << endl;
    } else {
      if (l) sum -= abs(qry(l) - qry(l - 1));
      if (r < n - 1) sum -= abs(qry(r) - qry(r + 1));
      upd(l, r, x);
      if (l) sum += abs(qry(l) - qry(l - 1));
      if (r < n - 1) sum += abs(qry(r) - qry(r + 1));
      sm(l);
      if (l) sm(l - 1);
      sm(r);
      if (r < n - 1) sm(r + 1);
    }
  }
  return 0;
}
