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

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



template<typename Monoid, typename Operand>
class lazy_segment_tree {
	struct node {
		Monoid element;
		Operand lazy;
	};
	std::vector<node> tree;
	uint32 size, height;
	void push(uint32 index) {
		tree[index << 1].lazy = tree[index << 1].lazy*tree[index].lazy;
		tree[index << 1 | 1].lazy = tree[index << 1 | 1].lazy*tree[index].lazy;
		tree[index].element = tree[index].element*tree[index].lazy;
		tree[index].lazy.inactive();
		return;
	}
	void recalc(uint32 index) {
		tree[index].element = (tree[index << 1].element*tree[index << 1].lazy) + (tree[index << 1 | 1].element*tree[index << 1 | 1].lazy);
	}
public:
	lazy_segment_tree(uint32 length) :height(static_cast<uint32>(0)) {
		--length;
		length |= length >> 1;
		length |= length >> 2;
		length |= length >> 4;
		length |= length >> 8;
		length |= length >> 16;
		if (!length) length = 1;
		height = __builtin_popcount(length);
		size = length + 1;
		tree = std::vector<node>(size << 1);
	}
	void set(void) {
		uint32 const s = size;
		uint32 i = s << 1;
		while (--i >= s) {
			tree[i].element.set();
			tree[i].lazy.inactive();
		}
		do {
			tree[i].element = tree[i << 1].element + tree[i << 1 | 1].element;
			tree[i].lazy.inactive();
		} while (--i);
		return;
	}

	void update(uint32 begin, uint32 end, const Operand &data) {
		begin += size;
		end += size - 1;
		uint32 i = height;
		do {
			push(begin >> i);
			push(end >> i);
		} while (--i);
		for (uint32 left = begin, right = end + 1;left < right;left >>= 1, right >>= 1) {
			if (left & 1) {
				tree[left].lazy = tree[left].lazy * data;
				++left;
			}
			if (right & 1) {
				--right;
				tree[right].lazy = tree[right].lazy * data;
			}
		}
		i = height;
		do {
			recalc(begin >>= 1);
			recalc(end >>= 1);
		} while (--i);
		return;
	}
	Monoid range(uint32 begin, uint32 end) {
		Monoid retL, retR;
		begin += size;end += size - 1;
		uint32 i = height;
		do {
			push(begin >> i);
			push(end >> i);
		} while (--i);
		++end;
		for (;begin < end;(++begin) >>= 1, end >>= 1) {
			if (begin & 1) {
				retL = retL + (tree[begin].element * tree[begin].lazy);
			}
			if (end & 1) {
				retR = (tree[end - 1].element * tree[end - 1].lazy) + retR;
			}
		}
		return retL + retR;
	}
};

struct ADD {
	int64 e;
	ADD(int64 x = 0) { e = x; }
	void inactive() { e = 0; }
	ADD operator*(const ADD &other) {
		return ADD(e + other.e);
	}
};
struct SUM {
	int64 e;
	int64 s;
	SUM(int64 x = 0, int64 y = 1) { 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(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n, q;
	std::cin >> n >> q;
	lazy_segment_tree<SUM, ADD> T(n);
	T.set();
	int64 c, s, t, x;
	do {
		std::cin >> c >> s >> t;
		if (c) {
			std::cout << T.range(s - 1, t).e << "\n";
		}
		else {
			std::cin >> x;
			T.update(s - 1, t, ADD(x));
		}
	} while (--q);
	return 0;
}


Measured memory_bytes: 8904