#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define maxn 100010
using namespace std;
struct tree {
int l, r;
long long pre, add;
} t[maxn];
int a[maxn];
int n, m;
void build(int p, int l, int r) {
t[p].l = l;
t[p].r = r;
if (l == r) {
t[p].pre = a[l];
return;
}
int mid = (r + l) / 2;
build(p * 2, l, mid);
build(p * 2 + 1, mid + 1, r);
t[p].pre = t[p * 2].pre + t[p * 2 + 1].pre;
}
void spread(int p) {
if (t[p].add) {
t[p * 2].pre += t[p].add * (t[p * 2].r - t[p * 2].l + 1);
t[p * 2 + 1].pre += t[p].add * (t[p * 2 + 1].r - t[p * 2 + 1].l + 1);
t[p * 2].add = t[p].add, t[p * 2 + 1].add = t[p].add;
t[p].add = 0;
}
}
void change(int p, int x, int y, int z) {
if (x <= t[p].l && y >= t[p].r) {
t[p].pre += (long long)z * (t[p].r - t[p].l + 1);
t[p].add += z;
return;
}
spread(p);
int mid = (t[p].l + t[p].r) / 2;
if (x <= mid) {
change(p * 2, x, y, z);
}
if (y > mid) {
change(p * 2 + 1, x, y, z);
}
t[p].pre = t[p * 2].pre + t[p * 2 + 1].pre;
}
long long ask(int p, int x, int y) {
if (x <= t[p].l && y > t[p].r) {
cout << "ok3" << endl;
return t[p].pre;
}
spread(p);
int mid = (t[p].l + t[p].r) / 2;
long long ans = 0;
if (x <= mid) {
ans += ask(p * 2, x, y);
}
if (y > mid) {
ans += ask(p * 2 + 1, x, y);
}
cout << "ok2" << endl;
return ans;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
build(1, 1, n);
int op;
int x, y, z;
for (int i = 1; i <= m; i++) {
scanf("%d", &op);
cout << "ok" << endl;
if (op == 1) {
scanf("%d%d%d", &x, &y, &z);
change(1, x, y, z);
} else {
scanf("%d%d", &x, &y);
cout << "ok" << endl;
long long ans = ask(1, x, y);
cout << "ok1" << endl;
cout << ans << endl;
}
}
return 0;
}