#include using namespace std; using i64 = long long; const int MAXN = 2e5 + 5; int N; i64 a[MAXN]; int Q; struct node { i64 x, y; node(i64 x = 0, i64 y = 0) : x(x), y(y) {} friend node operator + (node a, node b) { node c = node(); c.x = a.x + b.x; c.y = a.y + b.y; return c; } }; namespace ST { int N; node tree[MAXN * 4]; i64 lazy[MAXN * 4]; void build(int id, int l, int r) { if(l == r) { tree[id] = node(a[r], a[r] * a[r]); return; } int m = (l + r) / 2; build(id * 2, l, m); build(id * 2 + 1, m + 1, r); tree[id] = tree[id * 2] + tree[id * 2 + 1]; } void init(int _N) { N = _N; build(1, 1, N); } void down(int id, int l, int r) { i64 &o = lazy[id]; if(o == 0) return; if(l != r) { lazy[id * 2] += o; lazy[id * 2 + 1] += o; } tree[id].y += 2LL * tree[id].x * o + o * o * (r - l + 1); tree[id].x += o * (r - l + 1); o = 0; } void update(int id, int l, int r, int u, int v, int x) { down(id, l, r); if(r < u or l > v) return; if(u <= l and r <= v) { lazy[id] += x; down(id, l, r); return; } int m = (l + r) / 2; update(id * 2, l, m, u, v, x); update(id * 2 + 1, m + 1, r, u, v, x); tree[id] = tree[id * 2] + tree[id * 2 + 1]; } void update(int l, int r, int x) { return update(1, 1, N, l, r, x); } node get(int id, int l, int r, int u, int v) { down(id, l, r); if(r < u or l > v) return node(); if(u <= l and r <= v) return tree[id]; int m = (l + r) / 2; return get(id * 2, l, m, u, v) + get(id * 2 + 1, m + 1, r, u, v); } node get(int l, int r) { return get(1, 1, N, l, r); } } signed main() { #define task "" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1; i <= N; i++) cin >> a[i]; ST::init(N); cin >> Q; while(Q--) { int type = 0, l = 0, r = 0; cin >> type >> l >> r; if(type == 1) { int x = 0; cin >> x; ST::update(l, r, x); } else cout << ST::get(l, r).y << "\n"; } return (0 ^ 0); }