#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#define MOD 1000000007
#define exit return 0
#define N 1555
#define inf 1000000000000000000LL
typedef long long ll;
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left v<<1
#define right left|1
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
using namespace std;
struct seg{
int sum, val;
seg *l, *r;
seg(){
l = r = NULL;
sum = 0;
}
};
#define mid ((tl+tr)>>1)
void add(seg &v, int tl, int tr, int pos1, int pos2, int val){
if (tl > pos2 || tr < pos1)return;
if (tl <= pos1&&tr >= pos2){
v.val += val;
return;
}
if (!v.r)v.r = new seg;
if (!v.l)v.l = new seg;
add(*v.l, tl, mid, pos1, pos2, val);
add(*v.r, mid + 1, tr, pos1, pos2, val);
v.sum = v.l->sum + v.r->sum + (mid + 1 - tl)*v.l->val + (tr - mid)*v.r->val;
}
int get(seg &v, int tl, int tr, int l, int r){
if (tl > r || tr < l){
return 0;
}
if (tl >= l&&tr <= r){
return v.sum;
}
if (!v.l)v.l = new seg;
if (!v.r)v.r = new seg;
int L = get(*v.l, tl, mid, l, r);
int R = get(*v.r, mid + 1, tr, l, r);
return (L + R);
}
int n, m, i, j, k;
seg *root;
int main(){
root = new seg;
//add(*root, 1, 1200000000, 1, 1);
scanf_s("%d %d", &n, &m);
int a, b, c, d;
for (int i = 0; i < m; i++){
cin >> a >> b >> c;
if (a == 0){
cin >> d;
add(*root, 1, n, b, c, d);
}
else cout << get(*root, 1, n, b, c);
}
PS;
exit;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoj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