#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll id = 0;
ll merge(ll l, ll r) {
	return l + r;
}

unsigned xor128() {
	static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned t = x ^ (x << 11);
	x = y; y = z; z = w;
	return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}

template <typename T>
struct node {
	T val, all, lazy;
	node<T> *lch, *rch;
	int size;
	node(T v, node<T>* l = nullptr, node<T>* r = nullptr) : val(v), all(v), lazy(id), lch(l), rch(r), size(1) {}
};

template <typename T>
int count(node<T> *t) { return t == nullptr ? 0 : t->size; }
template <typename T>
T que(node<T> *t) { return t == nullptr ? id : t->all + t->lazy * t->size; }
template <typename T>
node<T> *update(node<T> *t) {
	t->size = count(t->lch) + count(t->rch) + 1;
	t->all = merge(que(t->lch), merge(t->val, que(t->rch)));
	return t;
}
template <typename T>
node<T> *push(node<T> *t) {
	if (t == nullptr || t->lazy == id) return t;
	if (t->lch != nullptr) {
		t->lch->lazy = merge(t->lch->lazy, t->lazy);
	}
	if (t->rch != nullptr) {
		t->rch->lazy = merge(t->rch->lazy, t->lazy);
	}
	t->val = merge(t->val, t->lazy);
	t->all = merge(que(t->lch), merge(t->val, que(t->rch)));
	t->lazy = id;
	return t;
}
template <typename T>
node<T> *merge(node<T> *l, node<T> *r) {
	if (l == nullptr || r == nullptr) return l == nullptr ? r : l;
	if (xor128() % (l->size + r->size) < (unsigned)l->size) {
		l = push(l);
		l->rch = merge(l->rch, r);
		return update(l);
	}
	else {
		r = push(r);
		r->lch = merge(l, r->lch);
		return update(r);
	}
}
template <typename T>
pair<node<T>*, node<T>*> split(node<T> *t, int k) {
	if (t == nullptr) return make_pair(nullptr, nullptr);
	t = push(t);
	if (k <= count(t->lch)) {
		pair<node<T>*, node<T>*> s = split(t->lch, k);
		t->lch = s.second;
		return make_pair(s.first, update(t));
	}
	else {
		pair<node<T>*, node<T>*> s = split(t->rch, k - count(t->lch) - 1);
		t->rch = s.first;
		return make_pair(update(t), s.second);
	}
}
template <typename T>
node<T> *insert(node<T> *t, int k, T v) {
	pair<node<T>*, node<T>*> s = split(t, k);
	node<T> *r = merge(s.first, new node<T>(v));
	r = merge(r, s.second);
	return r;
}
template <typename T>
node<T> *erase(node<T> *t, int k) {
	pair<node<T>*, node<T>*> s1 = split(t, k), s2 = split(s1.second, 1);
	if (s2.first != nullptr) delete s2.first;
	return merge(s1.first, s2.second);
}
template <typename T>
node<T> *find(node<T> *t, int k) {
	if (t == nullptr) return t;
	int c = count(t->lch);
	return k < c ? find(t->lch, k) : k == c ? t : find(t->rch, k - (c + 1));
}
template <typename T>
T find(node<T> *t, int l, int r) {
	if (t == nullptr) return id;
	if (r < 0 || l >= count(t)) return id;
	t = push(t);
	if (l <= 0 && r >= count(t)) return t->all;
	int c = count(t->lch);
	return merge(t->lch == nullptr ? id : find(t->lch, l, r), merge(l <= c && c < r ? t->val : id, t->rch == nullptr ? id : find(t->rch, l - (c + 1), r - (c + 1))));
}
template <typename T>
void print(node<T> *t) {
	if (t == nullptr) return;
	t = push(t);
	print(t->lch);
	printf(" %d", t->val);
	print(t->rch);
}
template <typename T>
int cnt(node<T> *t, T v) {
	if (t == nullptr) return 0;
	t = push(t);
	if (t->val < v) return count(t->lch) + 1 + cnt(t->rch, v);
	if (t->val == v) return count(t->lch);
	return cnt(t->lch, v);
}
template <typename T>
node<T> *update(node<T> *t, int l, int r, T v) {
	auto t1 = split(t, l);
	auto t2 = split(t1.second, r - l);
	t2.first->lazy = merge(t2.first->lazy, v);
	return merge(t1.first, merge(t2.first, t2.second));
}
int main()
{
	cin.sync_with_stdio(false);
	int n, q, type, s, t;
	ll x;
	cin >> n >> q;
	node<ll> *root = nullptr;
	for (int i = 0; i < n; i++) {
		root = insert(root, i, 0ll);
	}
	while (q--) {
		cin >> type;
		if (type == 0) {
			cin >> s >> t >> x; s--;
			root = update(root, s, t, x);
		}
		else {
			cin >> s >> t; s--;
			printf("%lld\n", find(root, s, t));
		}
	}
	return 0;
}

Measured memory_bytes: 9404