#include #if __has_include() #include using namespace atcoder; #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; struct S { ll x, x2; int size; S(ll x=0, ll x2=0, int size=0): x(x), x2(x2), size(size) {} }; S op(S a, S b) { return S(a.x+b.x, a.x2+b.x2, a.size+b.size); } S e() { return S(); } S mapping(ll f, S s) { return S(s.x + f*s.size, s.x2 + 2*f*s.x + f*f*s.size, s.size); } ll composition(ll g, ll f) { return f+g; } ll id() { return 0; } int main() { int n; cin >> n; vector a; rep(i, n) { ll x; cin >> x; a.emplace_back(x, x*x, 1); } int q; cin >> q; lazy_segtree t(a); rep(qi, q) { int type, l, r; cin >> type >> l >> r; --l; if (type == 1) { int x; cin >> x; t.apply(l, r, x); } else { cout << t.prod(l, r).x2 << '\n'; } } return 0; }