// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



template <typename T>

class DynamicFenwickTree {

	const ll n;

	unordered_map<ll, T> data;

public:

	DynamicFenwickTree(ll n_, int pmax = 1e5) : n(n_), data(pmax) {}

	T find(ll p) {

		T res = 0;

		while (p >= 0) {

			res += data[p];

			p = (p & (p + 1)) - 1;

		}

		return res;

	}

	void add(ll p, T val) {

		while (p < n) {

			data[p] += val;

			p |= p + 1;

		}

	}

};



template <typename T>

class DynamicRARS {

	const ll n;

	DynamicFenwickTree<T> bit0, bit1;

public:

	DynamicRARS(ll n_) : n(n_), bit0(n), bit1(n) {}

	T find(ll p) {

		return bit1.find(p) * (p + 1) + bit0.find(p);

	}

	T find(ll l, ll r) {

		return find(r) - find(l - 1);

	}

	void add(ll l, ll r, T val) {

		bit0.add(l, -val * l);

		bit1.add(l, val);

		bit0.add(r + 1, val * (r + 1));

		bit1.add(r + 1, -val);

	}

};



int main()

{

	ios::sync_with_stdio(false), cin.tie(0);

	int n, q;

	cin >> n >> q;

	DynamicRARS<ll> rars(n);

	for (int i = 0, type, s, t, x; i < q; i++) {

		cin >> type >> s >> t; s--; t--;

		if (type) {

			printf("%lld\n", rars.find(s, t));

		}

		else {

			cin >> x;

			rars.add(s, t, x);

		}

	}

	return 0;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



struct RS {

	using type = ll;

	static type id() { return 0; }

	static type op(const type& l, const type& r) {

		return l + r;

	}

};



class seg_node {

public:

	using M = RS;

	using T = typename M::type;

	using U = ll;



	T val;



private:

	int size;

	U lazy;



public:

	seg_node() : val(M::id()), size(1), lazy(0) {}

	void init(const T& v) {

		val = v;

	}

	void init(const seg_node& l, const seg_node& r) {

		size = l.size + r.size;

	}

	void update(U v) {

		val += v * size;

		lazy += v;

	}

	void push(seg_node& l, seg_node& r) {

		if (lazy == 0) return;

		l.update(lazy);

		r.update(lazy);

		lazy = 0;

	}

	bool is_updated() const {

		return lazy;

	}



};



class segment_tree {

	using M = typename seg_node::M;

	using T = typename seg_node::T;

	using U = typename seg_node::U;

	const int h, n;

	vector<seg_node> data;

	void init() {

		for (int i = n - 1; i >= 1; i--) {

			data[i].init(data[i << 1], data[(i << 1) | 1]);

		}

	}

	void push(int node) {

		data[node].push(data[node << 1], data[(node << 1) | 1]);

	}

	void update(int node) {

		data[node].val = M::op(data[node << 1].val, data[(node << 1) | 1].val);

	}

public:

	segment_tree(int n_)

		: h(ceil(log2(n_))), n(1 << h), data(n * 2) {

		init();

	}

	segment_tree(int n_, T v1)

		: h(ceil(log2(n_))), n(1 << h), data(n * 2) {

		for (int i = 0; i < n_; i++) {

			data[i + n].init(v1);

		}

		init();

	}

	segment_tree(const vector<T>& data_)

		: h(ceil(log2(data_.size()))), n(1 << h), data(n * 2) {

		for (int i = 0; i < (int)data_.size(); i++) {

			data[i + n].init(data_[i]);

		}

		init();

	}

	void update(int l, int r, U val) {

		l += n, r += n;

		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);

		int tl = l, tr = r;

		r++;

		while (l < r) {

			if (l & 1) data[l++].update(val);

			if (r & 1) data[--r].update(val);

			l >>= 1; r >>= 1;

		}

		while (tl >>= 1, tr >>= 1, tl) {

			if (!data[tl].is_updated()) update(tl);

			if (!data[tr].is_updated()) update(tr);

		}

	}

	T find(int l, int r) {

		l += n, r += n;

		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);

		r++;

		T res1 = M::id(), res2 = M::id();

		while (l < r) {

			if (l & 1) res1 = M::op(res1, data[l++].val);

			if (r & 1) res2 = M::op(data[--r].val, res2);

			l >>= 1; r >>= 1;

		}

		return M::op(res1, res2);

	}

};



int main()

{

	ios::sync_with_stdio(false), cin.tie(0);

	int n, q;

	cin >> n >> q;

	segment_tree st(n);

	while (q--) {

		int type, s, t;

		cin >> type >> s >> t; s--; t--;

		if (type) {

			printf("%lld\n", st.find(s, t));

		}

		else {

			int x;

			cin >> x;

			st.update(s, t, x);

		}

	}

	return 0;

}




// Fastest known solution for this problem: