#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
const long long N = (1 << 17);
long long test;
long long n, q;
long long t[4 * N + 7];
long long akt = 0;
long long load[4 * N + 7], load1[4 * N + 7];
void build(long long v = 1, long long L = 1, long long R = N) {
  if (L == R && L < n && L > 1) {
    if (t[L] < t[L - 1]) {
      load[v] += t[L - 1] - t[L];
    }
    if (t[L] < t[L + 1]) {
      load[v] += t[L + 1] - t[L];
    }
    return;
  } else if (L == R) {
    load[v] = 1000000000000000000LL;
    return;
  }
  build(v * 2, L, (L + R) / 2);
  build(v * 2 + 1, (L + R) / 2 + 1, R);
  load[v] = min(load[v * 2], load[v * 2 + 1]);
}
long long query(long long x) {
  if (x == 1) {
    return load1[x];
  }
  return load1[x] + query(x / 2);
}
void ins(long long v, long long L) {
  if (v == 0 || L == 1 || L == n) return;
  if (v >= N) {
    long long x1 = t[L] + query(N - 1 + L);
    long long x2 = t[L - 1] + query(N - 1 + L - 1);
    long long x3 = t[L + 1] + query(N - 1 + L + 1);
    load[v] = 0;
    if (x1 < x2) {
      load[v] += x2 - x1;
    }
    if (x1 < x3) {
      load[v] += x3 - x1;
    }
  }
  if (v < N) {
    load[v] = min(load[v * 2], load[v * 2 + 1]);
  }
  ins(v / 2, L);
}
long long query1(long long l, long long r, long long v = 1, long long L = 1,
                 long long R = N) {
  if (L > r || R < l) {
    return 1000000000000000000LL;
  }
  if (L >= l && R <= r) {
    return load[v];
  }
  return min(query1(l, r, v * 2, L, (L + R) / 2),
             query1(l, r, v * 2 + 1, (L + R) / 2 + 1, R));
}
void ins1(long long l, long long r, long long x, long long v = 1,
          long long L = 1, long long R = N) {
  if (L > r || R < l) {
    return;
  }
  if (L >= l && R <= r) {
    load1[v] += x;
    return;
  }
  ins1(l, r, x, v * 2, L, (L + R) / 2);
  ins1(l, r, x, v * 2 + 1, (L + R) / 2 + 1, R);
}
long long zrob(long long x, long long v) {
  long long x1 = t[x] + query(N - 1 + x);
  long long x2 = t[x - 1] + query(N - 1 + x - 1);
  long long x3 = t[x + 1] + query(N - 1 + x + 1);
  akt += abs(x1 - x2) * v;
  akt += abs(x1 - x3) * v;
}
long long check(long long x, long long y) {
  long long x1 = t[x] + query(N - 1 + x);
  long long x2 = t[x - 1] + query(N - 1 + x - 1);
  long long x3 = t[x + 1] + query(N - 1 + x + 1);
  long long odp = abs(x1 - x2) + abs(x1 - x3);
  long long odp1 = abs(x1 + y - x2) + abs(x1 + y - x3);
  return odp1 - odp;
}
void solve() {
  cin >> n;
  for (long long i = 1; i <= (n); ++i) {
    cin >> t[i];
  }
  for (long long i = 1; i <= (n - 1); ++i) {
    akt += abs(t[i] - t[i + 1]);
  }
  build();
  cin >> q;
  for (long long i = 1; i <= (q); ++i) {
    long long c, l, r, x;
    cin >> c >> l >> r >> x;
    if (c == 1) {
      long long xd = query1(l, r);
      if (xd == 0)
        cout << akt + 2 * x << '\n';
      else {
        if (r - l <= 10) {
          long long kek = -1000000000000000000LL;
          for (long long j = l; j <= (r); ++j) {
            kek = max(kek, check(j, x));
          }
          cout << akt + kek << '\n';
        } else {
          cout << akt - xd + abs(xd - x) + x << '\n';
        }
      }
    } else if (c == 2) {
      if (l == r) {
        zrob(l, -1);
        ins1(l, r, x);
        ins(l + 1 + N - 1, l + 1);
        ins(l + N - 1, l);
        ins(l - 1 + N - 1, l - 1);
        zrob(l, 1);
        continue;
      }
      zrob(l, -1);
      zrob(r, -1);
      ins1(l, r, x);
      ins(l + 1 + N - 1, l + 1);
      ins(l + N - 1, l);
      ins(l - 1 + N - 1, l - 1);
      ins(r - 1 + N - 1, r - 1);
      ins(r + N - 1, r);
      ins(r + 1 + N - 1, r + 1);
      zrob(l, 1);
      zrob(r, 1);
    }
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
