#include<iostream>
using namespace std;
#define lowbit(x) ((x)&-(x))
#define ll long long
#define maxn 100010
ll tree1[maxn],tree2[maxn],n,m;
void update1(ll x,ll d){
while (x<=maxn){
tree1[x]+=d; x+=lowbit(x);
}
}
void update2(ll x,ll d){
while (x<=maxn){
tree2[x]+=d; x+=lowbit(x);
}
}
ll sum1(ll x){
ll ans=0;
while (x>0){
ans+=tree1[x]; x-=lowbit(x);
}
return ans;
}
ll sum2(ll x){
ll ans=0;
while (x>0){
ans+=tree2[x]; x-=lowbit(x);
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
ll a,old;
for (int i=1;i<=n;i++){
cin>>a;
update1(i,a-old);
update2(i,(i-1)*(a-old));
old=a;
}
while (m--){
ll q,l,r,d;
cin>>q;
if (q==1){
cin>>l>>r>>d;
update1(l,d);
update1(r+1,-d);
update2(l,d*(l-1));
update2(r+1,-d*r);
}
else {
cin>>l>>r;
cout<<r*sum1(r)-sum2(r)-(l-1)*sum1(l-1)+sum2(l-1)<<endl;
}
}
return 0;
}