#include<bits/stdc++.h>
using namespace std;
#define re register
#define inf 0x3f3f3f
#define ll long long
const int N = 1e7 + 1;
ll n, m, a[N], sum[N];
ll add[N];
inline ll read()
{
char c = getchar();
ll f = 1,x = 0;
while(!isdigit(c)){if(c == '-') f = -1; c = getchar();}
while(isdigit(c)){x = (x << 1) + (x << 3) + (c - '0'); c = getchar();}
return x * f;
}
inline void build(ll l, ll r, ll k){
if(l == r){
sum[k] = a[l];
return ;
}
ll mid = (l + r) >> 1;
build(l, mid, k << 1);
build(mid + 1, r, k << 1 | 1);
sum[k] = sum[k << 1] + sum[k << 1 | 1];
}
inline void up(ll l, ll r, ll k, ll s){
add[k] += s;
sum[k] += (r - l + 1) * s;
}
inline void pushdown(ll l, ll r, ll k){
if(!add[k]) return ;
ll mid = (l + r) >> 1;
up(l, mid, k << 1, add[k]);
up(mid + 1, r, k << 1 | 1, add[k]);
add[k] = 0;
}
inline void Add(ll l, ll r, ll L, ll R, ll k, ll q){
if(L <= l && r <= R) {up(l, r, k, q); return ;}
pushdown(l, r, k);
ll mid = (l + r) >> 1;
if(L <= mid) Add(l, mid, L, R, k << 1, q);
if(R > mid) Add(mid + 1, r, L, R, k << 1 | 1, q);
sum[k] = sum[k << 1] + sum[k << 1 | 1];
}
inline ll query(ll l, ll r, ll L, ll R, ll k){
if(L <= l && r <= R) return sum[k];
pushdown(l ,r, k);
ll mid = (l + r) >> 1, ans = 0;
if(L <= mid) ans += query(l ,mid, L, R, k << 1);
if(R > mid) ans += query(mid + 1, r, L, R, k << 1 | 1);
return ans;
}
int main()
{
n = read(), m = read();
for(int i = 1;i <= n;i ++) a[i] = read();
build(1, n, 1);
for(int i = 1;i <= m;i ++)
{
ll op;
op = read();
if(op == 1){
ll l, r, x;
l = read(), r = read(), x = read();
Add(1, n, l, r, 1, x);
}
else if(op == 2){
ll l, r;
l = read(), r = read();
printf("%lld\n", query(1, n, l, r, 1));
}
}
}