#include #include using namespace std; using namespace atcoder; #define rep(i,m,n) for (int i = (int)(m); i < (int)(n); i++) #define ll long long vector e(){ vector _e(3); return _e; }; vector op(vector x, vector y){ vector z(3); rep(i,0,3){ z[i] = x[i] + y[i]; }; return z; } vector mapping(ll f, vector x){ vector z(3); z[0] = x[0]; z[1] = x[1] + f*x[0]; z[2] = x[2] + 2*x[1]*f + x[0]*(f*f); return z; }; ll composition(ll f, ll g){ return f+g; }; ll id_(){ return 0LL; }; int main(){ int N,Q; cin >> N ; vector> A(N); vector a(3); ll tmp; rep(i,0,N){ cin >> tmp; a[0] = 1; a[1] = tmp; a[2] = tmp*tmp; A[i] = a; }; cin >> Q; lazy_segtree,op,e,ll,mapping,composition, id_> T(A); int q,l,r; ll x; rep(_,0,Q){ cin >> q; if (q==1){ cin >> l >> r >> x; l -= 1; T.apply(l,r,x); } else{ cin >> l >> r ; l -= 1; cout << T.prod(l,r)[2] << endl; }; } }