#include #include using namespace std; using namespace atcoder; using ll = long long; struct S { ll sm; ll sm2; ll size; }; S op(S a, S b) { return S {a.sm + b.sm, a.sm2 + b.sm2, a.size + b.size}; } S mapping(ll f, S x) { return S {x.sm + (f * x.size), x.sm2 + (f *f * x.size) + (2 * f * x.sm), x.size}; } ll composition(ll f, ll g) {return f + g;} S e() {return S {0LL, 0LL, 0LL};} ll id() {return 0;} int main() { int N;cin >> N; vector A(N + 1, {0LL, 0LL, 1}); for (int i = 1;i <= N;i++) { ll a;cin >> a; A[i].sm = a;A[i].sm2 = a * a; } lazy_segtree seg(A); int Q;cin >> Q; while (Q--) { int op;cin >> op; if (op == 1) { int l, r;ll x;cin >> l >> r >> x; seg.apply(l, r + 1, x); continue; } int l, r;cin >> l >> r; cout << seg.prod(l, r + 1).sm2 << endl; } }