#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, Q;
long long a[100010], tot;
set<int> up, down;
struct node {
  int l, r;
  long long mn;
} tree[100010 << 2];
inline long long Abs(long long x) { return x >= 0 ? x : -x; }
inline void update(int i) {
  tree[i].mn = min(tree[i << 1].mn, tree[i << 1 | 1].mn);
}
void build(int i, int l, int r) {
  tree[i].l = l;
  tree[i].r = r;
  tree[i].mn = inf;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
}
void Change(int i, int p, long long d) {
  if (tree[i].l == tree[i].r) {
    tree[i].mn = d;
    return;
  }
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (p <= mid) {
    Change(i << 1, p, d);
  } else {
    Change(i << 1 | 1, p, d);
  }
  update(i);
}
long long Query(int i, int l, int r) {
  if (tree[i].l >= l && tree[i].r <= r) {
    return tree[i].mn;
  }
  int mid = (tree[i].l + tree[i].r) >> 1;
  long long ans = inf;
  if (l <= mid) ans = min(ans, Query(i << 1, l, r));
  if (r > mid) ans = min(ans, Query(i << 1 | 1, l, r));
  return ans;
}
void Del(int u) {
  if (u <= 1 || u >= n) return;
  if (a[u] >= 0 && a[u + 1] <= 0)
    up.erase(u);
  else if (a[u] < 0 && a[u + 1] > 0)
    down.erase(u);
  else if (a[u] >= 0) {
    Change(1, u, inf);
  } else {
    Change(1, u, inf);
  }
}
void Insert(int u) {
  if (u <= 1 || u >= n) return;
  if (a[u] >= 0 && a[u + 1] <= 0)
    up.insert(u);
  else if (a[u] < 0 && a[u + 1] > 0)
    down.insert(u);
  else if (a[u] >= 0) {
    Change(1, u, a[u + 1]);
  } else {
    Change(1, u, -a[u]);
  }
}
long long Ask(int l, int r, int x) {
  auto it = up.lower_bound(l);
  if (it != up.end() && (*it) <= r) return tot + 2 * x;
  long long mx = -inf;
  it = down.lower_bound(l);
  if (it != down.end() && (*it) <= r) {
    int u = (*it);
    mx = max(mx, Abs(a[u] + x) + Abs(a[u + 1] - x) - Abs(a[u]) - Abs(a[u + 1]));
  }
  long long qwq = Query(1, l, r);
  if (qwq ^ inf) mx = max(mx, max(0LL, 2LL * (x - qwq)));
  return tot + mx;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
  }
  for (int i = n; i >= 2; --i) {
    a[i] = a[i] - a[i - 1];
    tot += Abs(a[i]);
  }
  build(1, 1, n);
  for (int i = 2; i < n; ++i) {
    Insert(i);
  }
  Q = read();
  while (Q--) {
    int opt = read(), l = read(), r = read(), x = read();
    if (opt == 2) {
      Del(l - 1), Del(l);
      Del(r), Del(r + 1);
      tot -= Abs(a[l]) + Abs(a[r + 1]);
      a[l] += x;
      a[r + 1] -= x;
      tot += Abs(a[l]) + Abs(a[r + 1]);
      Insert(l - 1), Insert(l);
      Insert(r), Insert(r + 1);
    } else {
      printf("%lld\n", Ask(l, r, x));
    }
  }
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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 long long inf = 0x3f3f3f3f3f3f3f3fll;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, Q;
long long a[100010], tot;
set<int> up, down;
struct node {
  int l, r;
  long long mn;
} tree[100010 << 2];
inline long long Abs(long long x) { return x >= 0 ? x : -x; }
inline void update(int i) {
  tree[i].mn = min(tree[i << 1].mn, tree[i << 1 | 1].mn);
}
void build(int i, int l, int r) {
  tree[i].l = l;
  tree[i].r = r;
  tree[i].mn = inf;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
}
void Change(int i, int p, long long d) {
  if (tree[i].l == tree[i].r) {
    tree[i].mn = d;
    return;
  }
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (p <= mid) {
    Change(i << 1, p, d);
  } else {
    Change(i << 1 | 1, p, d);
  }
  update(i);
}
long long Query(int i, int l, int r) {
  if (tree[i].l >= l && tree[i].r <= r) {
    return tree[i].mn;
  }
  int mid = (tree[i].l + tree[i].r) >> 1;
  long long ans = inf;
  if (l <= mid) ans = min(ans, Query(i << 1, l, r));
  if (r > mid) ans = min(ans, Query(i << 1 | 1, l, r));
  return ans;
}
void Del(int u) {
  if (u <= 1 || u >= n) return;
  if (a[u] >= 0 && a[u + 1] <= 0)
    up.erase(u);
  else if (a[u] < 0 && a[u + 1] > 0)
    down.erase(u);
  else if (a[u] >= 0) {
    Change(1, u, inf);
  } else {
    Change(1, u, inf);
  }
}
void Insert(int u) {
  if (u <= 1 || u >= n) return;
  if (a[u] >= 0 && a[u + 1] <= 0)
    up.insert(u);
  else if (a[u] < 0 && a[u + 1] > 0)
    down.insert(u);
  else if (a[u] >= 0) {
    Change(1, u, a[u + 1]);
  } else {
    Change(1, u, -a[u]);
  }
}
long long Ask(int l, int r, int x) {
  auto it = up.lower_bound(l);
  if (it != up.end() && (*it) <= r) return tot + 2 * x;
  long long mx = -inf;
  it = down.lower_bound(l);
  if (it != down.end() && (*it) <= r) {
    int u = (*it);
    mx = max(mx, Abs(a[u] + x) + Abs(a[u + 1] - x) - Abs(a[u]) - Abs(a[u + 1]));
  }
  long long qwq = Query(1, l, r);
  if (qwq ^ inf) mx = max(mx, max(0LL, 2LL * (x - qwq)));
  return tot + mx;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
  }
  for (int i = n; i >= 2; --i) {
    a[i] = a[i] - a[i - 1];
    tot += Abs(a[i]);
  }
  build(1, 1, n);
  for (int i = 2; i < n; ++i) {
    Insert(i);
  }
  Q = read();
  while (Q--) {
    int opt = read(), l = read(), r = read(), x = read();
    if (opt == 2) {
      Del(l - 1), Del(l);
      Del(r), Del(r + 1);
      tot -= Abs(a[l]) + Abs(a[r + 1]);
      a[l] += x;
      a[r + 1] -= x;
      tot += Abs(a[l]) + Abs(a[r + 1]);
      Insert(l - 1), Insert(l);
      Insert(r), Insert(r + 1);
    } else {
      printf("%lld\n", Ask(l, r, x));
    }
  }
  return 0;
}

```