#include <bits/stdc++.h>
using namespace std;
bool home = 1;
signed realMain();
signed main() {
  home = 0;
  if (home) {
    freopen("tony_stark", "r", stdin);
  } else {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  realMain();
}
const long long N = (long long)1e5 + 7;
const long long INF = (long long)1e18;
long long n;
long long q;
long long vec[N];
long long lazy[4 * N];
long long base;
set<long long> type[4];
long long tree[4 * N];
void upd(long long v, long long tl, long long tr, long long i, long long dif) {
  if (tr < i || i < tl) return;
  if (tl == tr) {
    tree[v] = dif;
    return;
  }
  long long tm = (tl + tr) / 2;
  upd(2 * v, tl, tm, i, dif);
  upd(2 * v + 1, tm + 1, tr, i, dif);
  tree[v] = min(tree[2 * v], tree[2 * v + 1]);
}
void upd_dif(long long i, long long dif) { upd(1, 1, n, i, dif); }
long long getmin(long long v, long long tl, long long tr, long long l,
                 long long r) {
  if (tr < l || r < tl) return INF;
  if (l <= tl && tr <= r) return tree[v];
  long long tm = (tl + tr) / 2;
  return min(getmin(2 * v, tl, tm, l, r), getmin(2 * v + 1, tm + 1, tr, l, r));
}
long long getmin(long long l, long long r) { return getmin(1, 1, n, l, r); }
void push(long long v, long long tl, long long tr) {
  if (!lazy[v]) return;
  if (tl == tr)
    vec[tl] += lazy[v];
  else
    lazy[2 * v] += lazy[v], lazy[2 * v + 1] += lazy[v];
  lazy[v] = 0;
}
void add(long long v, long long tl, long long tr, long long l, long long r,
         long long val) {
  push(v, tl, tr);
  if (tr < l || r < tl) return;
  if (l <= tl && tr <= r) {
    lazy[v] += val;
    push(v, tl, tr);
    return;
  }
  long long tm = (tl + tr) / 2;
  add(2 * v, tl, tm, l, r, val);
  add(2 * v + 1, tm + 1, tr, l, r, val);
}
long long get(long long v, long long tl, long long tr, long long i) {
  push(v, tl, tr);
  if (tr < i || i < tl) assert(0);
  if (tl == tr) return vec[tl];
  long long tm = (tl + tr) / 2;
  if (i <= tm)
    return get(2 * v, tl, tm, i);
  else
    return get(2 * v + 1, tm + 1, tr, i);
}
void add(long long l, long long r, long long x) { add(1, 1, n, l, r, x); }
long long get(long long i) { return get(1, 1, n, i); }
void upd(long long i, long long sgn) {
  if (i <= 1 || i >= n) return;
  upd_dif(i, INF);
  long long me = get(i);
  long long b = get(i - 1);
  long long c = get(i + 1);
  if (b > c) swap(b, c);
  long long tp = -1;
  if (me >= b && me >= c)
    tp = 1;
  else if (me >= b && me < c)
    tp = 2;
  else if (me < b && me < c)
    tp = 3;
  assert(tp != -1);
  if (sgn == +1) {
    type[tp].insert(i);
  } else {
    type[tp].erase(i);
  }
  if (tp == 2) upd_dif(i, c - me);
}
long long get(long long l, long long r, long long x) {
  auto it = type[1].lower_bound(l);
  if (it != type[1].end()) {
    if (*it <= r) {
      return 2 * x;
    }
  }
  long long ret = -INF;
  it = type[3].lower_bound(l);
  if (it != type[3].end()) {
    if (*it <= r) {
      long long p = *it, b = get(p - 1), c = get(p + 1), me = get(p);
      ret = max(ret,
                abs(me + x - b) + abs(me + x - c) - abs(me - c) - abs(me - b));
      it++;
    }
  }
  long long mndif = getmin(l, r);
  if (mndif != INF) {
    ret = max(ret, 2 * max(0LL, x - mndif));
  }
  return ret;
}
signed realMain() {
  for (long long i = 0; i < 4 * N; i++) tree[i] = INF;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> vec[i];
  for (long long i = 1; i <= n; i++) upd(i, +1);
  for (long long i = 1; i < n; i++) base += abs(get(i) - get(i + 1));
  long long q;
  cin >> q;
  for (long long it = 1; it <= q; it++) {
    long long type, l, r, x;
    cin >> type >> l >> r >> x;
    if (type == 2) {
      base -= abs(get(l) - get(l - 1));
      base -= abs(get(r) - get(r + 1));
      long long sgn = -1;
      upd(l - 1, sgn), upd(l, sgn), upd(l + 1, sgn);
      upd(r - 1, sgn), upd(r, sgn), upd(r + 1, sgn);
      add(l, r, x);
      sgn *= -1;
      upd(l - 1, sgn), upd(l, sgn), upd(l + 1, sgn);
      upd(r - 1, sgn), upd(r, sgn), upd(r + 1, sgn);
      base += abs(get(l) - get(l - 1));
      base += abs(get(r) - get(r + 1));
    } else {
      cout << get(l, r, x) + base << "\n";
    }
  }
  return 0;
}

### Prompt

Create a solution in cpp for 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;
bool home = 1;
signed realMain();
signed main() {
  home = 0;
  if (home) {
    freopen("tony_stark", "r", stdin);
  } else {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  realMain();
}
const long long N = (long long)1e5 + 7;
const long long INF = (long long)1e18;
long long n;
long long q;
long long vec[N];
long long lazy[4 * N];
long long base;
set<long long> type[4];
long long tree[4 * N];
void upd(long long v, long long tl, long long tr, long long i, long long dif) {
  if (tr < i || i < tl) return;
  if (tl == tr) {
    tree[v] = dif;
    return;
  }
  long long tm = (tl + tr) / 2;
  upd(2 * v, tl, tm, i, dif);
  upd(2 * v + 1, tm + 1, tr, i, dif);
  tree[v] = min(tree[2 * v], tree[2 * v + 1]);
}
void upd_dif(long long i, long long dif) { upd(1, 1, n, i, dif); }
long long getmin(long long v, long long tl, long long tr, long long l,
                 long long r) {
  if (tr < l || r < tl) return INF;
  if (l <= tl && tr <= r) return tree[v];
  long long tm = (tl + tr) / 2;
  return min(getmin(2 * v, tl, tm, l, r), getmin(2 * v + 1, tm + 1, tr, l, r));
}
long long getmin(long long l, long long r) { return getmin(1, 1, n, l, r); }
void push(long long v, long long tl, long long tr) {
  if (!lazy[v]) return;
  if (tl == tr)
    vec[tl] += lazy[v];
  else
    lazy[2 * v] += lazy[v], lazy[2 * v + 1] += lazy[v];
  lazy[v] = 0;
}
void add(long long v, long long tl, long long tr, long long l, long long r,
         long long val) {
  push(v, tl, tr);
  if (tr < l || r < tl) return;
  if (l <= tl && tr <= r) {
    lazy[v] += val;
    push(v, tl, tr);
    return;
  }
  long long tm = (tl + tr) / 2;
  add(2 * v, tl, tm, l, r, val);
  add(2 * v + 1, tm + 1, tr, l, r, val);
}
long long get(long long v, long long tl, long long tr, long long i) {
  push(v, tl, tr);
  if (tr < i || i < tl) assert(0);
  if (tl == tr) return vec[tl];
  long long tm = (tl + tr) / 2;
  if (i <= tm)
    return get(2 * v, tl, tm, i);
  else
    return get(2 * v + 1, tm + 1, tr, i);
}
void add(long long l, long long r, long long x) { add(1, 1, n, l, r, x); }
long long get(long long i) { return get(1, 1, n, i); }
void upd(long long i, long long sgn) {
  if (i <= 1 || i >= n) return;
  upd_dif(i, INF);
  long long me = get(i);
  long long b = get(i - 1);
  long long c = get(i + 1);
  if (b > c) swap(b, c);
  long long tp = -1;
  if (me >= b && me >= c)
    tp = 1;
  else if (me >= b && me < c)
    tp = 2;
  else if (me < b && me < c)
    tp = 3;
  assert(tp != -1);
  if (sgn == +1) {
    type[tp].insert(i);
  } else {
    type[tp].erase(i);
  }
  if (tp == 2) upd_dif(i, c - me);
}
long long get(long long l, long long r, long long x) {
  auto it = type[1].lower_bound(l);
  if (it != type[1].end()) {
    if (*it <= r) {
      return 2 * x;
    }
  }
  long long ret = -INF;
  it = type[3].lower_bound(l);
  if (it != type[3].end()) {
    if (*it <= r) {
      long long p = *it, b = get(p - 1), c = get(p + 1), me = get(p);
      ret = max(ret,
                abs(me + x - b) + abs(me + x - c) - abs(me - c) - abs(me - b));
      it++;
    }
  }
  long long mndif = getmin(l, r);
  if (mndif != INF) {
    ret = max(ret, 2 * max(0LL, x - mndif));
  }
  return ret;
}
signed realMain() {
  for (long long i = 0; i < 4 * N; i++) tree[i] = INF;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> vec[i];
  for (long long i = 1; i <= n; i++) upd(i, +1);
  for (long long i = 1; i < n; i++) base += abs(get(i) - get(i + 1));
  long long q;
  cin >> q;
  for (long long it = 1; it <= q; it++) {
    long long type, l, r, x;
    cin >> type >> l >> r >> x;
    if (type == 2) {
      base -= abs(get(l) - get(l - 1));
      base -= abs(get(r) - get(r + 1));
      long long sgn = -1;
      upd(l - 1, sgn), upd(l, sgn), upd(l + 1, sgn);
      upd(r - 1, sgn), upd(r, sgn), upd(r + 1, sgn);
      add(l, r, x);
      sgn *= -1;
      upd(l - 1, sgn), upd(l, sgn), upd(l + 1, sgn);
      upd(r - 1, sgn), upd(r, sgn), upd(r + 1, sgn);
      base += abs(get(l) - get(l - 1));
      base += abs(get(r) - get(r + 1));
    } else {
      cout << get(l, r, x) + base << "\n";
    }
  }
  return 0;
}

```