#include using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct S { LL m[4][4] = {}; }; S f(S a, S b) { S res; rep(i, 4)rep(j, 4)rep(k, 4)res.m[i][j] += a.m[i][k] * b.m[k][j]; return res; } S multi(LL x, LL a) { return S{ {{1,x,x * x,0},{0,1,2*x,0},{0,0,1,a},{0,0,0,1}} }; } struct segtree { int N; vector V; S I; segtree(int n) { N = 1; while (N < n) N *= 2; V.resize(N * 2); rep(i, 4) I.m[i][i] = 1; } void upd(int p, S v) { p += N; V[p] = v; while (p != 1) { p /= 2; V[p] = f(V[p * 2], V[p * 2 + 1]); } } S get(int l, int r, int a = 0, int b = 0, int i = -1) { if (i == -1) { a = 0; b = N; i = 1; } if (r <= a || b <= l)return I; if (l <= a && b <= r)return V[i]; return f(get(l, r, a, (a + b) / 2, i * 2), get(l, r, (a + b) / 2, b, i * 2 + 1)); } }; int main() { int N; cin >> N; LL A[200000]; rep(i, N) cin >> A[i]; segtree G(N + 1); G.upd(0, multi(A[0], 0)); rep(i, N - 1) { G.upd(i + 1, multi(A[i+1] - A[i], 1)); } G.upd(N, multi(0, 1)); int Q; cin >> Q; rep(i, Q) { int c; cin >> c; if (c == 1) { int l, r; LL x; cin >> l >> r >> x; G.upd(l - 1, f(G.get(l - 1, l), multi(x, 0))); G.upd(r, f(G.get(r, r + 1), multi(-x, 0))); } else if (c == 2) { int l, r; cin >> l >> r; auto R = G.get(0, r + 1); auto L = G.get(0, l); cout << G.get(0, r + 1).m[0][3] - G.get(0, l).m[0][3] << endl; } } return 0; }