#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, q;
struct tree {
  int l, r;
  long long minn;
} tr[4 * N];
long long a[N];
int l, r, v, p, x;
long long ans = 0;
long long abss(long long x) { return x < 0 ? -x : x; }
void build(int i, int l, int r) {
  tr[i].l = l, tr[i].r = r;
  if (l == r) {
    ans += abss(a[l]);
    if (l > 1) tr[i].minn = max(0ll, -a[l - 1]) + max(0ll, a[l]);
    return;
  }
  int mid = l + r >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  tr[i].minn = min(tr[i << 1].minn, tr[i << 1 | 1].minn);
}
void modify(int i, int pos, int x) {
  int L = tr[i].l, R = tr[i].r;
  if (L == R) {
    ans -= abss(a[L]);
    a[L] += x;
    ans += abss(a[L]);
    if (pos > 1) tr[i].minn = max(0ll, -a[L - 1]) + max(0ll, a[R]);
    if (x && pos < n - 1) modify(1, pos + 1, 0);
    return;
  }
  int mid = L + R >> 1;
  if (mid >= pos)
    modify(i << 1, pos, x);
  else
    modify(i << 1 | 1, pos, x);
  tr[i].minn = min(tr[i << 1].minn, tr[i << 1 | 1].minn);
}
long long query(int i, int l, int r) {
  int L = tr[i].l, R = tr[i].r;
  if (L > r || l > R) return 1e18;
  if (l <= L && R <= r) return tr[i].minn;
  long long as = query(i << 1, l, r);
  as = min(as, query(i << 1 | 1, l, r));
  return as;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) a[i] = a[i + 1] - a[i];
  build(1, 1, n - 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d%d", &p, &l, &r, &x);
    if (p == 1) {
      if (l == r) {
        if (l == 1)
          printf("%I64d\n", ans - abss(a[1]) + abss(a[1] - x));
        else if (l == n)
          printf("%I64d\n", ans - abss(a[n - 1]) + abss(a[n - 1] + x));
        else
          printf("%I64d\n", ans - abss(a[l]) - abss(a[l - 1]) +
                                abss(a[l - 1] + x) + abss(a[l] - x));
      } else {
        long long del = 0;
        del = max(del, 2 * x - 2 * query(1, (l > 1 ? l : l + 1),
                                         (r < n ? r : r - 1)));
        if (l == 1) del = max(del, -abss(a[l]) + abss(a[l] - x));
        if (r == n) del = max(del, -abss(a[r - 1]) + abss(a[r - 1] + x));
        printf("%I64d\n", ans + del);
      }
    } else {
      if (l > 1) modify(1, l - 1, x);
      if (r < n) modify(1, r, -x);
    }
  }
}

### Prompt

In CPP, your task is to solve 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 N = 100010;
int n, q;
struct tree {
  int l, r;
  long long minn;
} tr[4 * N];
long long a[N];
int l, r, v, p, x;
long long ans = 0;
long long abss(long long x) { return x < 0 ? -x : x; }
void build(int i, int l, int r) {
  tr[i].l = l, tr[i].r = r;
  if (l == r) {
    ans += abss(a[l]);
    if (l > 1) tr[i].minn = max(0ll, -a[l - 1]) + max(0ll, a[l]);
    return;
  }
  int mid = l + r >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  tr[i].minn = min(tr[i << 1].minn, tr[i << 1 | 1].minn);
}
void modify(int i, int pos, int x) {
  int L = tr[i].l, R = tr[i].r;
  if (L == R) {
    ans -= abss(a[L]);
    a[L] += x;
    ans += abss(a[L]);
    if (pos > 1) tr[i].minn = max(0ll, -a[L - 1]) + max(0ll, a[R]);
    if (x && pos < n - 1) modify(1, pos + 1, 0);
    return;
  }
  int mid = L + R >> 1;
  if (mid >= pos)
    modify(i << 1, pos, x);
  else
    modify(i << 1 | 1, pos, x);
  tr[i].minn = min(tr[i << 1].minn, tr[i << 1 | 1].minn);
}
long long query(int i, int l, int r) {
  int L = tr[i].l, R = tr[i].r;
  if (L > r || l > R) return 1e18;
  if (l <= L && R <= r) return tr[i].minn;
  long long as = query(i << 1, l, r);
  as = min(as, query(i << 1 | 1, l, r));
  return as;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) a[i] = a[i + 1] - a[i];
  build(1, 1, n - 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d%d", &p, &l, &r, &x);
    if (p == 1) {
      if (l == r) {
        if (l == 1)
          printf("%I64d\n", ans - abss(a[1]) + abss(a[1] - x));
        else if (l == n)
          printf("%I64d\n", ans - abss(a[n - 1]) + abss(a[n - 1] + x));
        else
          printf("%I64d\n", ans - abss(a[l]) - abss(a[l - 1]) +
                                abss(a[l - 1] + x) + abss(a[l] - x));
      } else {
        long long del = 0;
        del = max(del, 2 * x - 2 * query(1, (l > 1 ? l : l + 1),
                                         (r < n ? r : r - 1)));
        if (l == 1) del = max(del, -abss(a[l]) + abss(a[l] - x));
        if (r == n) del = max(del, -abss(a[r - 1]) + abss(a[r - 1] + x));
        printf("%I64d\n", ans + del);
      }
    } else {
      if (l > 1) modify(1, l - 1, x);
      if (r < n) modify(1, r, -x);
    }
  }
}

```