#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

template<typename Monoid, typename Operand>
class SegTreeLazy {
public:
	Monoid* tree;
	Operand* calc;
	size_t size, i, hight = 0;
	//?????????????????????
	SegTreeLazy(size_t length) {
		--length;
		size = length;
		if (size & 0xffff0000) { size = size & 0xffff0000;hight += 16; }
		if (size & 0xff00ff00) { size = size & 0xff00ff00;hight += 8; }
		if (size & 0xf0f0f0f0) { size = size & 0xf0f0f0f0;hight += 4; }
		if (size & 0xcccccccc) { size = size & 0xcccccccc;hight += 2; }
		if (size & 0xaaaaaaaa) { size = size & 0xaaaaaaaa;hight += 1; }
		if (length) { size <<= 1;hight += 1; }
		else { size = 1;hight = 0; }
		tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
		calc = (Operand *)calloc(size << 1, sizeof(Operand));
	}
	//?????????
	void set(bool merge) {
		i = size << 1;
		while (--i) {
			tree[i].set();
			calc[i].set();
		}
		if (merge) {
			i = size;
			while (--i) { tree[i] = tree[i << 1] + tree[i << 1 | 1]; }
		}
	}
	//calc[begin,end)???data???????????????????¨????
	void update(size_t begin, size_t end, Operand &data) {
		begin += size;
		end += size - 1;
		size_t left, right;
		i = hight;
		while (i--) {
			left = begin >> i;
			right = end >> i;
			calc[left] = calc[left] * calc[left >> 1];
			calc[left ^ 1] = calc[left ^ 1] * calc[left >> 1];
			calc[left >> 1].set();
			calc[right] = calc[right] * calc[right >> 1];
			calc[right ^ 1] = calc[right ^ 1] * calc[right >> 1];
			calc[right >> 1].set();
		}
		for (left = begin, right = end + 1;left < right;left >>= 1, right >>= 1) {
			if (left & 1) {
				calc[left] = calc[left] * data;
				++left;
			}
			if (right & 1) {
				--right;
				calc[right] = calc[right] * data;
			}
		}
		for (begin >>= 1, end >>= 1;begin < end;begin >>= 1, end >>= 1) {
			tree[begin] = (tree[begin << 1] * calc[begin << 1]) + (tree[begin << 1 | 1] * calc[begin << 1 | 1]);
			tree[end] = (tree[end << 1] * calc[end << 1]) + (tree[end << 1 | 1] * calc[end << 1 | 1]);
		}
		begin <<= 1;
		while (begin >>= 1) {
			tree[begin] = (tree[begin << 1] * calc[begin << 1]) + (tree[begin << 1 | 1] * calc[begin << 1 | 1]);
		}
	}
	//[begin,end)??????????????????
	Monoid range(size_t begin, size_t end) {
		Monoid retL, retR;
		begin += size;end += size - 1;
		size_t left, right;
		i = hight;
		while (i--) {
			left = begin >> i;
			right = end >> i;
			calc[left] = calc[left] * calc[left >> 1];
			calc[left ^ 1] = calc[left ^ 1] * calc[left >> 1];
			tree[left >> 1] = tree[left >> 1] * calc[left >> 1];
			calc[left >> 1].set();
			calc[right] = calc[right] * calc[right >> 1];
			calc[right ^ 1] = calc[right ^ 1] * calc[right >> 1];
			tree[right >> 1] = tree[right >> 1] * calc[right >> 1];
			calc[right >> 1].set();
		}
		++end;
		for (;begin < end;(++begin) >>= 1, end >>= 1) {
			if (begin & 1) {
				retL = retL + (tree[begin] * calc[begin]);
			}
			if (end & 1) {
				retR = (tree[end - 1] * calc[end - 1]) + retR;
			}
		}
		return retL + retR;
	}
};

struct ADD {
	int64 e;
	ADD() { set(); }
	ADD(int64 x) { e = x; }
	void set() { e = 0; }
	ADD operator*(const ADD &other) {
		return ADD(e + other.e);
	}
};
struct SUM {
	int64 e;
	int64 s;
	SUM() { set(); }
	SUM(int64 x, int64 y) { e = x;s = y; }
	void set() { e = 0; s = 1; }
	SUM operator+(const SUM &other) {
		return  SUM(e + other.e, s + other.s);
	};
	SUM operator*(const ADD &other) {
		return SUM(e + (s*other.e), s);
	}
};

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	size_t n, q;
	cin >> n >> q;
	bool c;
	size_t x, y;
	ADD z;
	SegTreeLazy<SUM, ADD> t(n);
	t.set(1);
	while (q--) {
		cin >> c;
		if (c) {
			cin >> x >> y;
			printf("%lld\n", t.range(x - 1, y).e);
		}
		else {
			cin >> x >> y >> z.e;
			t.update(x - 1, y, z);
		}
	}
	return 0;
}

Measured memory_bytes: 9312