#include <bits/stdc++.h>
using namespace std;
long long int n = 0;
struct Value {
  long long int a, b, c;
  long long int flag;
  bool par;
  long long int first, second;
};
void SetFlag(Value& current) {
  if ((current.a >= current.b) && (current.a >= current.c))
    current.flag = 1;
  else if ((current.a < current.b) && (current.a < current.c))
    current.flag = 3;
  else
    current.flag = 2;
}
void SetPar(Value& current) {
  if (current.flag == 3) {
    current.par = true;
    current.first = max(current.b, current.c) - current.a;
    current.second = min(current.b, current.c) - current.a;
  } else {
    current.par = false;
    current.first = 0;
    current.second = 0;
  }
}
long long int GetValue(Value& current) {
  if (current.flag == 1) return 0;
  if (current.flag == 2) return (max(current.b, current.c) - current.a);
  return (max(current.b, current.c) - current.a);
}
struct Segtree {
  vector<Value> tree;
  Segtree(long long int sz = 0) : tree(4 * sz) {}
  void build(vector<long long int>& value, long long int v, long long int tl,
             long long int tr);
  Value query(long long int left, long long int right, long long int v,
              long long int tl, long long int tr);
  void update(long long int index, long long int value, long long int check,
              long long int v, long long int tl, long long int tr);
  void fix(long long int index, long long int value, bool check,
           long long int v, long long int tl, long long int tr);
  Value merge(Value& f, Value& s);
};
void Segtree::build(vector<long long int>& value, long long int v,
                    long long int tl, long long int tr) {
  if (tl == tr) {
    if (tl == 0) {
      tree[v].a = value[tl];
      tree[v].b = 0;
      tree[v].c = value[tl + 1];
      tree[v].flag = 4;
      SetPar(tree[v]);
    } else if (tl == value.size() - 1) {
      tree[v].a = value[tl];
      tree[v].b = value[tl - 1];
      tree[v].c = 0;
      tree[v].flag = 4;
      SetPar(tree[v]);
    } else {
      tree[v].a = value[tl];
      tree[v].b = value[tl - 1];
      tree[v].c = value[tl + 1];
      SetFlag(tree[v]);
      SetPar(tree[v]);
    }
    return;
  }
  long long int tm = (tl + tr) / 2;
  build(value, 2 * v + 1, tl, tm);
  build(value, 2 * v + 2, tm + 1, tr);
  tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
Value Segtree::query(long long int left, long long int right, long long int v,
                     long long int tl, long long int tr) {
  if ((tr < left) || (tl > right))
    return {0, (long long int)1e17, (long long int)1e17, 5, false, 0, 0};
  if ((tl >= left) && (tr <= right)) return tree[v];
  long long int tm = (tl + tr) / 2;
  auto q1 = query(left, right, 2 * v + 1, tl, tm),
       q2 = query(left, right, 2 * v + 2, tm + 1, tr);
  return merge(q1, q2);
}
void Segtree::update(long long int index, long long int value,
                     long long int check, long long int v, long long int tl,
                     long long int tr) {
  if ((tr < index) || (tl > index)) return;
  if (tl == tr) {
    tree[v].a += value;
    if ((check == 1) && (tl != n - 1)) tree[v].c += value;
    if ((check == 2) && (tl != 0)) tree[v].b += value;
    if ((tl != 0) && (tl != n - 1)) SetFlag(tree[v]);
    SetPar(tree[v]);
    if (check == 1) {
      if (tl - 1 >= 0) fix(tl - 1, value, true, 0, 0, n - 1);
    } else if (check == 2) {
      if (tl + 1 < n) fix(tl + 1, value, false, 0, 0, n - 1);
    } else if (check == 0) {
      if (tl - 1 >= 0) fix(tl - 1, value, true, 0, 0, n - 1);
      if (tl + 1 < n) fix(tl + 1, value, false, 0, 0, n - 1);
    }
    return;
  }
  long long int tm = (tl + tr) / 2;
  update(index, value, check, 2 * v + 1, tl, tm);
  update(index, value, check, 2 * v + 2, tm + 1, tr);
  tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
void Segtree::fix(long long int index, long long int value, bool check,
                  long long int v, long long int tl, long long int tr) {
  if ((tr < index) || (tl > index)) return;
  if (tl == tr) {
    if (check)
      tree[v].c += value;
    else
      tree[v].b += value;
    if ((tl != 0) && (tl != n - 1)) SetFlag(tree[v]);
    SetPar(tree[v]);
    return;
  }
  long long int tm = (tl + tr) / 2;
  fix(index, value, check, 2 * v + 1, tl, tm);
  fix(index, value, check, 2 * v + 2, tm + 1, tr);
  tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
Value Segtree::merge(Value& f, Value& s) {
  Value result;
  if (f.flag < s.flag) {
    result.a = f.a;
    result.b = f.b;
    result.c = f.c;
    result.flag = f.flag;
  } else if ((f.flag == s.flag) && (GetValue(f) < GetValue(s))) {
    result.a = f.a;
    result.b = f.b;
    result.c = f.c;
    result.flag = f.flag;
  } else {
    result.a = s.a;
    result.b = s.b;
    result.c = s.c;
    result.flag = s.flag;
  }
  if (f.par) {
    result.par = true;
    result.first = f.first;
    result.second = f.second;
  } else if (s.par) {
    result.par = true;
    result.first = s.first;
    result.second = s.second;
  } else {
    result.par = false;
    result.first = 0;
    result.second = 0;
  }
  return result;
}
void Print(Segtree& from) {
  for (long long int j = 0; j < n; j++) {
    Value answer = from.query(j, j, 0, 0, n - 1);
    printf("[%lld] ", answer.a);
  }
  printf("\n");
}
int main() {
  cin >> n;
  vector<long long int> data(n);
  for (auto& it : data) cin >> it;
  long long int f = 0;
  for (long long int i = 0; i < n - 1; i++) f += abs(data[i] - data[i + 1]);
  Segtree from(data.size());
  from.build(data, 0, 0, n - 1);
  long long int q = 0;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    long long int t = 0, l = 0, r = 0, x = 0;
    cin >> t >> l >> r >> x;
    l--, r--;
    if (t == 1) {
      long long int result = -1e18;
      if (l == 0) {
        Value answer = from.query(l, l, 0, 0, n - 1);
        if (answer.a >= answer.c)
          result = max(result, x);
        else
          result = max(result, x - (answer.c - answer.a));
      }
      if (r == n - 1) {
        Value answer = from.query(r, r, 0, 0, n - 1);
        if (answer.a >= answer.b)
          result = max(result, x);
        else
          result = max(result, x - (answer.b - answer.a));
      }
      if ((r - l + 1 >= 2) || ((l != 0) && (l != n - 1))) {
        long long int delta = -1e18;
        Value answer = from.query(l, r, 0, 0, n - 1);
        if (answer.par)
          delta = max(delta, 2LL * max(0LL, x - answer.first) -
                                 2LL * min(x, answer.second));
        if (answer.flag == 1)
          delta = max(delta, 2LL * x);
        else if (answer.flag == 3)
          delta = max(delta,
                      2LL * max(0LL, x - (max(answer.b, answer.c) - answer.a)) -
                          2LL * min(x, min(answer.b, answer.c) - answer.a));
        else if (answer.flag == 2)
          delta = max(delta,
                      2LL * max(0LL, x - (max(answer.b, answer.c) - answer.a)));
        result = max(result, delta);
      }
      cout << f + result << '\n';
    } else if (t == 2) {
      if (l == r) {
        Value tmp1 = from.query(l, l, 0, 0, n - 1);
        if (l != 0) f -= abs(tmp1.b - tmp1.a);
        if (l != n - 1) f -= abs(tmp1.c - tmp1.a);
        from.update(l, x, 0, 0, 0, n - 1);
        Value tmp2 = from.query(l, l, 0, 0, n - 1);
        if (l != 0) f += abs(tmp2.b - tmp2.a);
        if (l != n - 1) f += abs(tmp2.c - tmp2.a);
      } else {
        Value tmp1 = from.query(l, l, 0, 0, n - 1),
              tmp2 = from.query(r, r, 0, 0, n - 1);
        if (l != 0) f -= abs(tmp1.b - tmp1.a);
        if (l != n - 1) f -= abs(tmp1.c - tmp1.a);
        if (r != 0) f -= abs(tmp2.b - tmp2.a);
        if (r != n - 1) f -= abs(tmp2.c - tmp2.a);
        from.update(l, x, 1, 0, 0, n - 1);
        from.update(r, x, 2, 0, 0, n - 1);
        Value tmp3 = from.query(l, l, 0, 0, n - 1),
              tmp4 = from.query(r, r, 0, 0, n - 1);
        if (l != 0) f += abs(tmp3.b - tmp3.a);
        if (l != n - 1) f += abs(tmp3.c - tmp3.a);
        if (r != 0) f += abs(tmp4.b - tmp4.a);
        if (r != n - 1) f += abs(tmp4.c - tmp4.a);
      }
    }
  }
  return 0;
}
