#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int M = int(7e5) + 10;
const int inf = int(1e9);
const int mod = int(1e9) + 7;
const long double eps = 1e-15;
long long a[N];
long long b[N], c[N];
pair<long long, long long> d[4 * N], e[4 * N];
void build(int n, int l, int r) {
  int m = (l + r) / 2;
  if (l == r) {
    if (b[m] >= 0 && c[m] >= 0) {
      d[n] = pair<long long, long long>(2, 0);
      e[n] = pair<long long, long long>(0, 0);
    } else if (b[m] < 0 && c[m] < 0) {
      d[n] = pair<long long, long long>(0, -1e18);
      e[n] = pair<long long, long long>(b[m], c[m]);
    } else {
      if (b[m] < 0) {
        d[n] = pair<long long, long long>(1, b[m]);
      } else {
        d[n] = pair<long long, long long>(1, c[m]);
      }
      e[n] = pair<long long, long long>(-1e18, -1e18);
    }
    return;
  }
  build(2 * n, l, m);
  build(2 * n + 1, m + 1, r);
  d[n] = max(d[2 * n], d[2 * n + 1]);
  e[n] = max(e[2 * n], e[2 * n + 1]);
}
long long query(int n, int l, int r, int L, int R, int x) {
  if (L > R) {
    return (long long)-1e18;
  }
  if (l == L && r == R) {
    if (d[n].first == 2) {
      return 2 * x;
    }
    if (e[n] == pair<long long, long long>(-1e18, -1e18)) {
      return max(0ll, 2 * (x + d[n].second));
    }
    long long res =
        max(0ll - x, 2 * e[n].first + x) + max(0ll - x, 2 * e[n].second + x);
    if (l == r) {
      return res;
    }
    return max(res, max(0ll, 2 * (x + d[n].second)));
  }
  int m = (l + r) / 2;
  return max(query(2 * n, l, m, L, min(m, R), x),
             query(2 * n + 1, m + 1, r, max(m + 1, L), R, x));
}
void update(int n, int l, int r, int pos) {
  int m = (l + r) / 2;
  if (l == r) {
    if (b[m] >= 0 && c[m] >= 0) {
      d[n] = pair<long long, long long>(2, 0);
      e[n] = pair<long long, long long>(0, 0);
    } else if (b[m] < 0 && c[m] < 0) {
      d[n] = pair<long long, long long>(0, -1e18);
      e[n] = pair<long long, long long>(b[m], c[m]);
    } else {
      if (b[m] < 0) {
        d[n] = pair<long long, long long>(1, b[m]);
      } else {
        d[n] = pair<long long, long long>(1, c[m]);
      }
      e[n] = pair<long long, long long>(-1e18, -1e18);
    }
    return;
  }
  if (pos <= m) {
    update(2 * n, l, m, pos);
  } else {
    update(2 * n + 1, m + 1, r, pos);
  }
  d[n] = max(d[2 * n], d[2 * n + 1]);
  e[n] = max(e[2 * n], e[2 * n + 1]);
}
void solve() {
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    if (i > 1) {
      ans += abs(a[i] - a[i - 1]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    b[i] = a[i] - a[i - 1];
    c[i] = a[i] - a[i + 1];
  }
  build(1, 1, n);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int t, l, r, x;
    scanf("%d%d%d%d", &t, &l, &r, &x);
    if (t == 1) {
      printf("%lld\n", ans + query(1, 1, n, l, r, x));
    } else {
      if (b[l] >= 0) {
        ans += x;
      } else if (b[l] + x >= 0) {
        ans += 2 * b[l] + x;
      } else {
        ans -= x;
      }
      if (c[r] >= 0) {
        ans += x;
      } else if (c[r] + x >= 0) {
        ans += 2 * c[r] + x;
      } else {
        ans -= x;
      }
      b[l] += x;
      c[l - 1] -= x;
      c[r] += x;
      b[r + 1] -= x;
      update(1, 1, n, l);
      update(1, 1, n, l - 1);
      update(1, 1, n, r);
      update(1, 1, n, r + 1);
    }
  }
}
int main() {
  solve();
  return 0;
}
