#include<bits/stdc++.h>
#define int ll
using namespace std;
using ll = long long;
const int MAXN = 1000007;
int n,m;
ll laz[5000007];
ll a[5000007],w[5000007];
void pushup(int u);
void build(const int u,int l, int r);
bool InRange(int L,int R,int l,int r);
bool OutofRange(int L,int R,int l,int r);
ll query(int u,int L,int R,int l,int r);
void maketag(int u,int len, ll x);
void pushdown(int u,int L,int R);
void update(int u,int L, int R,int l,int r,ll x);
void pushup(int u){
w[u]=w[u*2]+w[u*2+1];
}
void build(const int u, int l, int r){
if(l==r){
w[u]=a[l];
return;
}
int mid = (l+r)/2;
build(u*2,l,mid);
build(u*2+1,mid+1,r);
pushup(u);
}
bool InRange(int L, int R, int l, int r){
return (L>=l)&&(R<=r);
}
bool OutofRange(int L, int R, int l, int r){
return (L>r)||(R<l);
}
ll query(int u, int L, int R, int l, int r){ //cha2xun2
// if(L>R)return 0;
if(InRange(L,R,l,r)){ //包含于
return w[u];
}
else if(!OutofRange(L,R,l,r)){ //交集
int mid = (L+R)/2;
//printf("HERE!! , u=%lld, L=%lld,R=%lld,mid=%lld\n",u,L,R,mid);
if(L!=R)pushdown(u,L,R);
return query(u*2,L,mid,l,r)+query(u*2+1,mid+1,R,l,r);
}
else{
return 0;
} //空集
}
void maketag(int u,int len,ll x){
laz[u]+=x;
w[u]+=len*x;
}
void pushdown(int u,int L,int R){
int mid = (L+R)/2;
maketag(u*2,mid-L+1,laz[u]);
maketag(u*2+1,R-mid,laz[u]);
laz[u]=0;
}
void update(int u,int L,int R,int l,int r,ll x){
if(InRange(L,R,l,r)){
maketag(u,R-L+1,x);
}
else if(!OutofRange(L,R,l,r)){
int mid = (L+R)/2;
pushdown(u,L,R);
update(u*2,L,mid,l,r,x);
update(u*2+1,mid+1,R,l,r,x);
pushup(u);
}
}
signed main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;++i){
scanf("%lld",&a[i]);
}
build(1,1,n);
while(m--){
int op,x,y;
ll k;
scanf("%lld",&op);
scanf("%lld%lld",&x,&y);
if(op==1){
scanf("%lld",&k);
update(1,1,n,x,y,k);
}else{
printf("%lld\n",query(1,1,n,x,y));
}
}
return 0;
}