#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const int maxn = 1e5 + 5;
int n, q;
long long a[maxn];
long long st[4][maxn << 1];
void upd(long long st[], int p, long long val) {
  for (st[p += n] = val; p > 1;)
    p >>= 1, st[p] = min(st[p << 1], st[p << 1 | 1]);
}
long long query(long long st[], int l, int r) {
  long long res = LINF;
  for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) chkmin(res, st[l++]);
    if (r & 1) chkmin(res, st[--r]);
  }
  return res;
}
void upd(int pos) {
  for (int i = (0); i < (2); ++i)
    for (int j = (0); j < (2); ++j) {
      long long t = 0;
      if (pos) t -= abs(a[pos - 1]);
      if (pos < n - 1) t -= abs(a[pos]);
      if (pos) t += (i ? -1 : +1) * -a[pos - 1];
      if (pos < n - 1) t += (j ? -1 : +1) * a[pos];
      upd(st[i * 2 + j], pos, -t);
    }
}
void chemthan() {
  cin >> n;
  for (int i = (0); i < (n); ++i) cin >> a[i];
  for (int i = (0); i < (n - 1); ++i) a[i] = a[i + 1] - a[i];
  for (int i = (0); i < (n); ++i) {
    upd(i);
  }
  long long cost = 0;
  for (int i = (0); i < (n - 1); ++i) cost += abs(a[i]);
  cin >> q;
  while (q--) {
    int op, l, r, x;
    cin >> op >> l >> r >> x;
    l--, r--;
    if (op == 1) {
      long long res = -LINF;
      for (int i = (0); i < (2); ++i)
        for (int j = (0); j < (2); ++j) {
          long long tmp = cost;
          tmp += i ? x : -x;
          tmp += j ? x : -x;
          tmp -= query(st[i * 2 + j], l, r);
          chkmax(res, tmp);
        }
      cout << res << "\n";
    } else {
      if (l) {
        cost -= abs(a[l - 1]);
        a[l - 1] += x;
        cost += abs(a[l - 1]);
      }
      if (r < n - 1) {
        cost -= abs(a[r]);
        a[r] -= x;
        cost += abs(a[r]);
      }
      if (l) {
        upd(l - 1);
      }
      upd(l);
      upd(r);
      if (r < n - 1) {
        upd(r + 1);
      }
    }
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

### Prompt

Your task is to create a CPP solution to the following problem:

Fafa has an array A of n positive integers, the function f(A) is defined as <image>. He wants to do q queries of two types:

  * 1 l r x — find the maximum possible value of f(A), if x is to be added to one element in the range [l, r]. You can choose to which element to add x. 
  * 2 l r x — increase all the elements in the range [l, r] by value x. 



Note that queries of type 1 don't affect the array elements.

Input

The first line contains one integer n (3 ≤ n ≤ 105) — the length of the array.

The second line contains n positive integers a1, a2, ..., an (0 < ai ≤ 109) — the array elements.

The third line contains an integer q (1 ≤ q ≤ 105) — the number of queries. 

Then q lines follow, line i describes the i-th query and contains four integers ti li ri xi <image>. 

It is guaranteed that at least one of the queries is of type 1.

Output

For each query of type 1, print the answer to the query.

Examples

Input

5
1 1 1 1 1
5
1 2 4 1
2 2 3 1
2 4 4 2
2 3 4 1
1 3 3 2


Output

2
8


Input

5
1 2 3 4 5
4
1 2 4 2
2 2 4 1
2 3 4 1
1 2 4 2


Output

6
10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const int maxn = 1e5 + 5;
int n, q;
long long a[maxn];
long long st[4][maxn << 1];
void upd(long long st[], int p, long long val) {
  for (st[p += n] = val; p > 1;)
    p >>= 1, st[p] = min(st[p << 1], st[p << 1 | 1]);
}
long long query(long long st[], int l, int r) {
  long long res = LINF;
  for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) chkmin(res, st[l++]);
    if (r & 1) chkmin(res, st[--r]);
  }
  return res;
}
void upd(int pos) {
  for (int i = (0); i < (2); ++i)
    for (int j = (0); j < (2); ++j) {
      long long t = 0;
      if (pos) t -= abs(a[pos - 1]);
      if (pos < n - 1) t -= abs(a[pos]);
      if (pos) t += (i ? -1 : +1) * -a[pos - 1];
      if (pos < n - 1) t += (j ? -1 : +1) * a[pos];
      upd(st[i * 2 + j], pos, -t);
    }
}
void chemthan() {
  cin >> n;
  for (int i = (0); i < (n); ++i) cin >> a[i];
  for (int i = (0); i < (n - 1); ++i) a[i] = a[i + 1] - a[i];
  for (int i = (0); i < (n); ++i) {
    upd(i);
  }
  long long cost = 0;
  for (int i = (0); i < (n - 1); ++i) cost += abs(a[i]);
  cin >> q;
  while (q--) {
    int op, l, r, x;
    cin >> op >> l >> r >> x;
    l--, r--;
    if (op == 1) {
      long long res = -LINF;
      for (int i = (0); i < (2); ++i)
        for (int j = (0); j < (2); ++j) {
          long long tmp = cost;
          tmp += i ? x : -x;
          tmp += j ? x : -x;
          tmp -= query(st[i * 2 + j], l, r);
          chkmax(res, tmp);
        }
      cout << res << "\n";
    } else {
      if (l) {
        cost -= abs(a[l - 1]);
        a[l - 1] += x;
        cost += abs(a[l - 1]);
      }
      if (r < n - 1) {
        cost -= abs(a[r]);
        a[r] -= x;
        cost += abs(a[r]);
      }
      if (l) {
        upd(l - 1);
      }
      upd(l);
      upd(r);
      if (r < n - 1) {
        upd(r + 1);
      }
    }
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

```