#include using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second typedef long long ll; typedef vector vec; typedef vector mat; ll N,M,H,W,Q,K,A,B; string S; const ll MOD = 998244353; //const ll MOD = (1e+9) + 7; typedef pair P; const ll INF = (1LL<<58); int main() { const int bnum = 450, bsize = 450, max_n = bnum * bsize; cin >> N; vec a(max_n, 0); rep(i,N) cin>>a[i]; vec as(bnum, 0), as2(bnum, 0), tx(bnum, 0); rep(i,N){ as[i / bsize] += a[i]; as2[i / bsize] += a[i] * a[i]; } cin>>Q; rep(_,Q){ int q, l, r, x; cin>>q>>l>>r; --l; --r; int lb = l / bsize, rb = r / bsize; if(q == 1){ cin>>x; if(lb < rb) { reps(i, lb * bsize, (lb + 1) * bsize) { int temp = tx[lb] + (i >= l ? x : 0); as2[lb] += (a[i] + temp) * (a[i] + temp) - a[i] * a[i]; as[lb] += temp; a[i] += temp; } reps(i, rb * bsize, (rb + 1) * bsize) { int temp = tx[rb] + (i <= r ? x : 0); as2[rb] += (a[i] + temp) * (a[i] + temp) - a[i] * a[i]; as[rb] += temp; a[i] += temp; } tx[lb] = tx[rb] = 0; reps(i, lb + 1, rb) tx[i] += x; }else{ reps(i, lb * bsize, (lb + 1) * bsize) { int temp = tx[lb] + (i >= l && i <= r ? x : 0); as2[lb] += (a[i] + temp) * (a[i] + temp) - a[i] * a[i]; as[lb] += temp; a[i] += temp; } tx[lb] = 0; } }else{ ll res = 0; if(lb < rb) { as[lb] += tx[lb] * bsize; as[rb] += tx[rb] * bsize; reps(i, lb * bsize, (lb + 1) * bsize) { as2[lb] += (a[i] + tx[lb]) * (a[i] + tx[lb]) - a[i] * a[i]; a[i] += tx[lb]; if (i >= l) res += a[i] * a[i]; } reps(i, rb * bsize, (rb + 1) * bsize) { as2[rb] += (a[i] + tx[rb]) * (a[i] + tx[rb]) - a[i] * a[i]; a[i] += tx[rb]; if (i <= r) res += a[i] * a[i]; } tx[lb] = tx[rb] = 0; reps(i, lb + 1, rb) res += as2[i] + 2LL * as[i] * tx[i] + tx[i] * tx[i] * bsize; }else{ as[lb] += tx[lb] * bsize; reps(i, lb * bsize, (lb + 1) * bsize) { as2[lb] += (a[i] + tx[lb]) * (a[i] + tx[lb]) - a[i] * a[i]; a[i] += tx[lb]; if(i >= l && i <= r) res += a[i] * a[i]; } tx[lb] = 0; } cout<