#include<iostream>
#include<cstdio>
#define ll long long
#define maxn 100005
using namespace std;
ll n,m;
ll a[maxn];
struct SegmentTree
{
ll l,r;
ll sum,tag;
}t[maxn*4];
void build(ll p,ll l,ll r)
{
t[p].l=l,t[p].r=r;
if(l==r)
{
t[p].sum=a[l];
return ;
}
ll mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
t[p].sum=t[p<<1].sum+t[p<<1|1].sum;
}
void push_down(ll p)
{
if(t[p].tag)
{
t[p<<1].sum+=t[p].tag*(t[p<<1].r-t[p<<1].l+1);
t[p<<1||1].sum+=t[p].tag*(t[p<<1||1].r-t[p<<1||1].l+1);
t[p<<1].tag+=t[p].tag;
t[p<<1||1].tag+=t[p].tag;
t[p].tag=0;
}
}
void update(ll p,ll l,ll r,ll k)
{
if(l<=t[p].l&&r>=t[p].r)
{
t[p].sum+=(ll)k*(t[p].r-t[p].l+1);
t[p].tag+=k;
return ;
}
push_down(p);
ll mid=(t[p].l+t[p].r)>>1;
if(l<=mid) update(p<<1,l,r,k);
if(r>mid) update(p<<1|1,l,r,k);
t[p].sum=t[p<<1].sum+t[p<<1|1].sum;
}
ll query(ll p,ll l,ll r)
{
if(l<=t[p].l&&r>=t[p].r) return t[p].sum;
push_down(p);
ll mid=(t[p].l+t[p].r)>>1;
ll val=0;
if(l<=mid) val+=query(p<<1,l,r);
if(r>mid) val+=query(p<<1|1,l,r);
return val;
}
int main()
{
scanf("%lld%lld",&n,&m);
for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
build(1,1,n);
while(m--)
{
ll opt,x,y,k;
scanf("%lld%lld%lld",&opt,&x,&y);
if(opt==1)
{
scanf("%lld",&k);
update(1,x,y,k);
}
else
{
printf("%lld\n",query(1,x,y));
}
}
return 0;
}