#include <bits/stdc++.h>
using namespace std;
const int M = 1000010;
int n;
long long min1[M << 2], a[M], cha[M];
void update(int k, int l, int r, int pl) {
  if (pl < l || pl > r) return;
  if (l == r) {
    long long now = 0;
    if (cha[l - 1] > 0) now += cha[l - 1];
    if (cha[l] < 0) now -= cha[l];
    min1[k] = now;
    return;
  }
  int mid = l + r >> 1;
  if (mid >= pl)
    update(k << 1, l, mid, pl);
  else
    update(k << 1 | 1, mid + 1, r, pl);
  min1[k] = min(min1[k << 1], min1[k << 1 | 1]);
}
long long query(int k, int l, int r, int x, int y) {
  if (l == x && r == y) return min1[k];
  int mid = l + r >> 1;
  if (mid >= y) return query(k << 1, l, mid, x, y);
  if (mid < x) return query(k << 1 | 1, mid + 1, r, x, y);
  return min(query(k << 1, l, mid, x, mid),
             query(k << 1 | 1, mid + 1, r, mid + 1, y));
}
int main() {
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", a + i);
  for (int i = 1; i <= n; i++) {
    cha[i] = a[i] - a[i + 1];
    ans += abs(cha[i]);
    update(1, 1, n, i);
  }
  ans -= cha[n];
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int q, l, r, x;
    scanf("%d%d%d%d", &q, &l, &r, &x);
    if (q == 1) {
      if (l == r) {
        printf("%I64d\n", ans - abs(cha[l - 1]) - abs(cha[l]) +
                              abs(cha[l - 1] - x) + abs(cha[l] + x));
        continue;
      }
      long long s = query(1, 1, n, l, r);
      if (s > x)
        printf("%I64d\n", ans);
      else
        printf("%I64d\n", ans + (x - s) * 2);
    } else {
      ans = ans - abs(cha[l - 1]) - abs(cha[r]);
      cha[l - 1] -= x;
      cha[r] += x;
      ans = ans + abs(cha[l - 1]) + abs(cha[r]);
      update(1, 1, n, l);
      update(1, 1, n, r);
      update(1, 1, n, l - 1);
      update(1, 1, n, r + 1);
    }
  }
  return 0;
}

### 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 M = 1000010;
int n;
long long min1[M << 2], a[M], cha[M];
void update(int k, int l, int r, int pl) {
  if (pl < l || pl > r) return;
  if (l == r) {
    long long now = 0;
    if (cha[l - 1] > 0) now += cha[l - 1];
    if (cha[l] < 0) now -= cha[l];
    min1[k] = now;
    return;
  }
  int mid = l + r >> 1;
  if (mid >= pl)
    update(k << 1, l, mid, pl);
  else
    update(k << 1 | 1, mid + 1, r, pl);
  min1[k] = min(min1[k << 1], min1[k << 1 | 1]);
}
long long query(int k, int l, int r, int x, int y) {
  if (l == x && r == y) return min1[k];
  int mid = l + r >> 1;
  if (mid >= y) return query(k << 1, l, mid, x, y);
  if (mid < x) return query(k << 1 | 1, mid + 1, r, x, y);
  return min(query(k << 1, l, mid, x, mid),
             query(k << 1 | 1, mid + 1, r, mid + 1, y));
}
int main() {
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", a + i);
  for (int i = 1; i <= n; i++) {
    cha[i] = a[i] - a[i + 1];
    ans += abs(cha[i]);
    update(1, 1, n, i);
  }
  ans -= cha[n];
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int q, l, r, x;
    scanf("%d%d%d%d", &q, &l, &r, &x);
    if (q == 1) {
      if (l == r) {
        printf("%I64d\n", ans - abs(cha[l - 1]) - abs(cha[l]) +
                              abs(cha[l - 1] - x) + abs(cha[l] + x));
        continue;
      }
      long long s = query(1, 1, n, l, r);
      if (s > x)
        printf("%I64d\n", ans);
      else
        printf("%I64d\n", ans + (x - s) * 2);
    } else {
      ans = ans - abs(cha[l - 1]) - abs(cha[r]);
      cha[l - 1] -= x;
      cha[r] += x;
      ans = ans + abs(cha[l - 1]) + abs(cha[r]);
      update(1, 1, n, l);
      update(1, 1, n, r);
      update(1, 1, n, l - 1);
      update(1, 1, n, r + 1);
    }
  }
  return 0;
}

```