#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

class SegmentTree {
	std::vector<std::vector<long long int>> _value_array;
	std::vector<std::vector<long long int>> _sum_array;
	static int depth(int n) {
		switch (n) {
		case 0: return 0;
		case 1: return 1;
		default: return 1 + depth((n + 1) >> 1);
		}
	}
	void ready_to_change_child(int depth, int pos) {
		//assert(depth > 0);
		switch (_value_array[depth][pos]) {
		case undefined:break;
		default:
			_value_array[depth - 1][pos << 1] += _value_array[depth][pos];
			_sum_array[depth - 1][pos << 1] += _value_array[depth][pos] << (depth - 1);
			if ((pos << 1) + 1 < _value_array[depth - 1].size()) {
				_value_array[depth - 1][(pos << 1) + 1] += _value_array[depth][pos];
				_sum_array[depth - 1][(pos << 1) + 1] += _value_array[depth][pos] << (depth - 1);
			}
			_value_array[depth][pos] = undefined;
		}
	}
	void solve_segment_operation(int depth, int pos) {
		//assert(depth > 0);
		ready_to_change_child(depth, pos);
	}
	void apply_change(int depth, int pos) {
		//assert(depth > 0);
		if (((pos << 1) + 1) < _sum_array[depth - 1].size()) _sum_array[depth][pos] = _sum_array[depth - 1][pos << 1] + _sum_array[depth - 1][(pos << 1) + 1];
		else _sum_array[depth][pos] = _sum_array[depth - 1][pos << 1];
	}
	static constexpr long long int undefined = 0;
	static constexpr long long int init_value = 0;
	static constexpr long long int init_sum = 0;
public:
	SegmentTree(int size) :_value_array(depth(size)), _sum_array(depth(size)) {
		for (auto i = 0; i < _value_array.size(); ++i) {
			_value_array[i] = std::vector<long long int>(size, init_value);
			_sum_array[i] = std::vector<long long int>(size, init_sum);
			size = (size + 1) >> 1;
		}
	}
	void add(int from, int to, long long int value) {
		for (int depth = _value_array.size() - 1; depth > 0; --depth) {
			if ((from - 1) >> depth == from >> depth)
				ready_to_change_child(depth, from >> depth);
			if (to >> depth == (to + 1) >> depth)
				ready_to_change_child(depth, to >> depth);
		}
		int left{ from }, right{ to };
		for (auto depth = 0; left <= right; ++depth) {
			if ((left >> depth) % 2 == 1) {
				_value_array[depth][left >> depth] += value;
				_sum_array[depth][left >> depth] += value << depth;
				left += 1 << depth;
			}
			if ((right >> depth) % 2 == 0) {
				_value_array[depth][right >> depth] += value;
				_sum_array[depth][right >> depth] += value << depth;
				right -= 1 << depth;
			}
		}
		for (auto depth = 1; depth < _sum_array.size(); ++depth) {
			if ((from - 1) >> depth == from >> depth)
				apply_change(depth, from >> depth);
			if (to >> depth == (to + 1) >> depth)
				apply_change(depth, to >> depth);
		}
	}
	long long int getSum(int from, int to) {
		for (int depth = _sum_array.size() - 1; depth > 0; --depth) {
			if ((from - 1) >> depth == from >> depth)
				solve_segment_operation(depth, from >> depth);
			if (to >> depth == (to + 1) >> depth)
				solve_segment_operation(depth, to >> depth);
		}
		long long int res = 0;
		int left{ from }, right{ to };
		for (auto depth = 0; left <= right; ++depth) {
			if ((left >> depth) % 2 == 1) {
				res += _sum_array[depth][left >> depth];
				left += 1 << depth;
			}
			if ((right >> depth) % 2 == 0) {
				res += _sum_array[depth][right >> depth];
				right -= 1 << depth;
			}
		}
		return res;
	}
};
int main() {
	int n, q_size;
	std::cin >> n >> q_size;
	SegmentTree st(n);
	int q, s, t, x;
	for (auto i = 0; i < q_size; ++i) {
		std::cin >> q;
		switch (q) {
		case 0:
			std::cin >> s >> t >> x;
			st.add(s - 1, t - 1, x); break;
		default:
			std::cin >> s >> t;
			std::cout << st.getSum(s - 1, t - 1) << std::endl;
		}
	}
}


Measured memory_bytes: 6004