#include<cstdio>
#define ll long long
using namespace std;
const int M=400001;
int n,m,k,x,y,val;
ll a[M],sum[M],lazy[M];
void pushup(int index)
{
sum[index]=sum[index<<1]+sum[index<<1|1];
}
void build(int index,int l,int r)
{
lazy[index]=0;
if(r==l)
sum[index]=a[l];
else
{
int mid=(l+r)>>1;
build(index<<1,l,mid);
build(index<<1|1,mid+1,r);
pushup(index);
}
}
void pushdown(int index,int l,int r)
{
if(lazy[index])
{
int ls=index<<1,rs=index<<1|1,mid=(l+r)>>1;
lazy[ls]+=lazy[index];
sum[ls]+=(mid-l+1)*lazy[index];
lazy[rs]+=lazy[index];
sum[rs]+=(r-(mid+1)+1)*lazy[index];
lazy[index]=0;
}
}
void update(int index,int l,int r,int L,int R,int val)//区间修改(l,r,为当前区间,L,R为目标区间)
{
if(R<l||L>r)//不在目标区间内
return;
else if(R>=r&&L<=l)//刚好在目标区间内
{
lazy[index]+=val;
sum[index]+=(r-l+1)*val;
return;
}
else//需要将当前区间拆开
{
pushdown(index,l,r);//下放懒标记
int mid=(l+r)>>1;
update(index<<1,l,mid,L,R,val);
update(index<<1|1,mid+1,r,L,R,val);
pushup(index);
}
}
ll query(int index,int l,int r,int L,int R)
{
if(L>r||R<l)return 0;
else if(L<=l&&R>=r)return sum[index];
else
{
pushdown(index,l,r);
ll ans=0;
int mid=(l+r)>>1;
if(L<=mid)ans+=query(index<<1,l,mid,L,R);
if(R>=mid+1)ans+=query(index<<1|1,mid+1,r,L,R);
return ans;
}
}
int main()
{
scanf("%ld%ld",&n,&m);
for(int i=1;i<=n;++i)
scanf("%ld",&a[i]);
build(1,1,n);
for(int i=1;i<=m;++i)
{
scanf("%ld",&k);
if(k==1)
{
scanf("%d%d%d",&x,&y,&val);
update(1,1,n,x,y,val);
}
else
{
scanf("%d%d",&x,&y);
printf("%ld\n",query(1,1,n,x,y));
}
}
return 0;
}
#define ll long long
using namespace std;
const int M=400001;
int n,m,k,x,y,val;
ll a[M],sum[M],lazy[M];
void pushup(int index)
{
sum[index]=sum[index<<1]+sum[index<<1|1];
}
void build(int index,int l,int r)
{
lazy[index]=0;
if(r==l)
sum[index]=a[l];
else
{
int mid=(l+r)>>1;
build(index<<1,l,mid);
build(index<<1|1,mid+1,r);
pushup(index);
}
}
void pushdown(int index,int l,int r)
{
if(lazy[index])
{
int ls=index<<1,rs=index<<1|1,mid=(l+r)>>1;
lazy[ls]+=lazy[index];
sum[ls]+=(mid-l+1)*lazy[index];
lazy[rs]+=lazy[index];
sum[rs]+=(r-(mid+1)+1)*lazy[index];
lazy[index]=0;
}
}
void update(int index,int l,int r,int L,int R,int val)//区间修改(l,r,为当前区间,L,R为目标区间)
{
if(R<l||L>r)//不在目标区间内
return;
else if(R>=r&&L<=l)//刚好在目标区间内
{
lazy[index]+=val;
sum[index]+=(r-l+1)*val;
return;
}
else//需要将当前区间拆开
{
pushdown(index,l,r);//下放懒标记
int mid=(l+r)>>1;
update(index<<1,l,mid,L,R,val);
update(index<<1|1,mid+1,r,L,R,val);
pushup(index);
}
}
ll query(int index,int l,int r,int L,int R)
{
if(L>r||R<l)return 0;
else if(L<=l&&R>=r)return sum[index];
else
{
pushdown(index,l,r);
ll ans=0;
int mid=(l+r)>>1;
if(L<=mid)ans+=query(index<<1,l,mid,L,R);
if(R>=mid+1)ans+=query(index<<1|1,mid+1,r,L,R);
return ans;
}
}
int main()
{
scanf("%ld%ld",&n,&m);
for(int i=1;i<=n;++i)
scanf("%ld",&a[i]);
build(1,1,n);
for(int i=1;i<=m;++i)
{
scanf("%ld",&k);
if(k==1)
{
scanf("%d%d%d",&x,&y,&val);
update(1,1,n,x,y,val);
}
else
{
scanf("%d%d",&x,&y);
printf("%ld\n",query(1,1,n,x,y));
}
}
return 0;
}