#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,a[N];
struct node{
int l;
int r;
int sum;
int lazy;
}tr[4*N];
void pushup(int u){
tr[u].sum=tr[u*2].sum+tr[u*2+1].sum;
}
void pushdown(int u){
if(tr[u].lazy){
tr[u*2].lazy+=tr[u].lazy;
tr[u*2].sum+=(tr[u*2].r-tr[u*2].l+1)*tr[u].lazy;
tr[u*2+1].lazy+=tr[u].lazy;
tr[u*2+1].sum+=(tr[u*2+1].r-tr[u*2+1].l+1)*tr[u].lazy;
tr[u].lazy=0;
}
}
void build(int u,int l,int r){
tr[u].l=l;
tr[u].r=r;
if(tr[u].l==tr[u].r){
tr[u].sum=a[l];
tr[u].lazy=0;
return;
}
int mid=tr[u].l+tr[u].r/2;
build(u*2,l,mid);build(u*2+1,mid+1,r);
pushup(u);
}
void mofity(int u,int l,int r,int v){
if(l<=tr[u].l&&tr[u].r<=r){
tr[u].lazy+=v;
tr[u].sum+=(tr[u].r-tr[u].l+1)/2*v;
return;
}
pushdown(u);
int mid=(tr[u].r-tr[u].l+1)/2;
if(l<=mid){
mofity(u*2,l,r,v);
}
else if(mid<r){
mofity(u*2+1,l,r,v);
}
pushup(u);
}
int query(int u,int l,int r){
if(l<=tr[u].l&&tr[u].r<=r){
return tr[u].sum;
}
pushdown(u);
int mid=(tr[u].r-tr[u].l+1)/2;
int ans=0;
if(l<=mid) ans+=query(u*2,l,r);
if(mid<r) ans+=query(u*2+1,l,r);
return ans;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
while(m--){
int op,x,y,k;
scanf("%d",&op);
if(op==1){
scanf("%d%d%d",&x,&y,&k);
mofity(1,x,y,k);
}
else{
scanf("%d%d",&x,&y);
int ans;
ans=query(1,x,y);
cout<<ans<<endl;
}
}
return 0;
}