#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, double> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

// ????????????????????????
class LazySegTree {
public:
	int n;
	vector<ll> dat;
	vector<ll> lazy;
	vector<int> depth;
	vector<int> width;
	const int NIL = -INF;

	ll def = 0;
	ll operation(ll a, ll b) {
		return a + b;
	}

	// ????????????_n????????????????´???°???
	LazySegTree(int _n) {
		n = 1;
		while (n < _n) {
			n *= 2;
		}
		dat = vector<ll>(2 * n - 1, def);
		lazy = vector<ll>(2 * n - 1, NIL);
		depth = vector<int>(2 * n - 1);
		width = vector<int>(2 * n - 1);
		depth[0] = 0;
		width[0] = n;
		repl(i, 1, 2 * n - 1) {
			depth[i] = depth[(i - 1) / 2] + 1;
			width[i] = width[(i - 1) / 2] / 2;
		}
	}

	// ????????????????????????k???Lazy???v????????????
	void setLazy(int k, ll v) {
		if (lazy[k] == NIL) {
			lazy[k] = v;
		}
		else {
			lazy[k] += v;
		}

		// min,max?????´???
		//dat[k] += v;

		// sum?????´???
		dat[k] += v * width[k];
	}

	void push(int k) {
		//cout << "push: " << k << endl;
		if (lazy[k] == NIL)return;
		setLazy(k * 2 + 1, lazy[k]);
		setLazy(k * 2 + 2, lazy[k]);
		lazy[k] = NIL;
	}

	// ??????[a,b)???v????¶????
	void rangeAdd(int a, int b, ll v, int k = 0, int l = 0, int r = -1) {
		if (r == -1)r = n;
		if (r <= a || b <= l)return;  // ???????????????
		if (a <= l && r <= b) {   // a,l,r,b????????§?????¨???????????????
			setLazy(k, v);
			return;
		}

		push(k);

		rangeAdd(a, b, v, 2 * k + 1, l, (l + r) / 2);    // ?????????
		rangeAdd(a, b, v, 2 * k + 2, (l + r) / 2, r);    // ?????????

		dat[k] = operation(dat[k * 2 + 1], dat[k * 2 + 2]);
	}

	// ??????[a,b)?????????????????????k=[l,r)????????????????????????
	ll _query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return def;  // ???????????????
		if (a <= l && r <= b)return dat[k];   // a,l,r,b????????§?????¨???????????????

		push(k);

		ll c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);    // ?????????
		ll c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);    // ?????????
		return operation(c1, c2);
	}

	// ?????¨?????¨???_query()???????????????
	ll query(int a, int b) {
		return _query(a, b, 0, 0, n);
	}

	ll operator[](int i) {
		//return dat[i + n - 1];
		return query(i, i + 1);
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	LazySegTree seg(N);
	rep(q, Q) {
		int c;
		cin >> c;
		if (c == 0) {
			int s, t, x;
			cin >> s >> t >> x;
			s--; t--;
			seg.rangeAdd(s, t + 1, x);
		}
		else {
			int s, t;
			cin >> s >> t;
			s--; t--;
			cout << seg.query(s, t + 1) << endl;
		}
		/*
		rep(i, N) {
			cout << seg[i] << " ";
		}
		cout << endl;
		*/
	}

	return 0;
}

Measured memory_bytes: 8836