#include <bits/stdc++.h>
using namespace std;
int n, q;
long long dat[400010], sub[100010], a[100010];
inline void modify(int p, int l, int r, int pos) {
  if (l == r) {
    long long cur = 0;
    if (sub[l - 1] > 0) cur += sub[l - 1];
    if (sub[l] < 0) cur -= sub[l];
    dat[p] = cur;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify((p << 1), l, mid, pos);
  else
    modify(((p << 1) | 1), mid + 1, r, pos);
  dat[p] = min(dat[(p << 1)], dat[((p << 1) | 1)]);
}
inline long long query(int p, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return dat[p];
  int mid = (l + r) >> 1;
  long long ret = 0x3f3f3f3f3f3f3f3f;
  if (ql <= mid) ret = query((p << 1), l, mid, ql, qr);
  if (qr > mid) ret = min(ret, query(((p << 1) | 1), mid + 1, r, ql, qr));
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sub[i] = a[i] - a[i + 1];
    sum += abs(sub[i]);
    if (i != 1) modify(1, 2, n - 1, i);
  }
  scanf("%d", &q);
  while (q--) {
    int op, l, r, x;
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      if (l == r) {
        printf("%lld\n", sum - abs(sub[l - 1]) - abs(sub[l]) +
                             abs(sub[l - 1] - x) + abs(sub[l] + x));
        continue;
      }
      long long s = query(1, 2, n - 1, l, r);
      if (s > x)
        printf("%lld\n", sum);
      else
        printf("%lld\n", sum + (x - s) * 2);
    } else {
      sum = sum - abs(sub[l - 1]) - abs(sub[r]);
      sub[l - 1] -= x;
      sub[r] += x;
      sum = sum + abs(sub[l - 1]) + abs(sub[r]);
      modify(1, 2, n - 1, l);
      modify(1, 2, n - 1, r);
      if (l >= 3) modify(1, 2, n - 1, l - 1);
      if (r <= n - 2) modify(1, 2, n - 1, r + 1);
    }
  }
  return 0;
}

### Prompt

Your challenge is to write 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;
int n, q;
long long dat[400010], sub[100010], a[100010];
inline void modify(int p, int l, int r, int pos) {
  if (l == r) {
    long long cur = 0;
    if (sub[l - 1] > 0) cur += sub[l - 1];
    if (sub[l] < 0) cur -= sub[l];
    dat[p] = cur;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify((p << 1), l, mid, pos);
  else
    modify(((p << 1) | 1), mid + 1, r, pos);
  dat[p] = min(dat[(p << 1)], dat[((p << 1) | 1)]);
}
inline long long query(int p, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return dat[p];
  int mid = (l + r) >> 1;
  long long ret = 0x3f3f3f3f3f3f3f3f;
  if (ql <= mid) ret = query((p << 1), l, mid, ql, qr);
  if (qr > mid) ret = min(ret, query(((p << 1) | 1), mid + 1, r, ql, qr));
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sub[i] = a[i] - a[i + 1];
    sum += abs(sub[i]);
    if (i != 1) modify(1, 2, n - 1, i);
  }
  scanf("%d", &q);
  while (q--) {
    int op, l, r, x;
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      if (l == r) {
        printf("%lld\n", sum - abs(sub[l - 1]) - abs(sub[l]) +
                             abs(sub[l - 1] - x) + abs(sub[l] + x));
        continue;
      }
      long long s = query(1, 2, n - 1, l, r);
      if (s > x)
        printf("%lld\n", sum);
      else
        printf("%lld\n", sum + (x - s) * 2);
    } else {
      sum = sum - abs(sub[l - 1]) - abs(sub[r]);
      sub[l - 1] -= x;
      sub[r] += x;
      sum = sum + abs(sub[l - 1]) + abs(sub[r]);
      modify(1, 2, n - 1, l);
      modify(1, 2, n - 1, r);
      if (l >= 3) modify(1, 2, n - 1, l - 1);
      if (r <= n - 2) modify(1, 2, n - 1, r + 1);
    }
  }
  return 0;
}

```