#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

bool _u;

namespace AK {

typedef unsigned long long ll;
typedef double db;
#define int ll

#define rep(i, l, r) for(int i = l, i##end = r; i <= i##end; ++ i)
#define per(i, l, r) for(int i = l, i##end = r; i >= i##end; -- i)

template <class T>
inline void chmax(T &x,const T &y) {
	if(x < y) x = y;
}

template <class T>
inline void chmin(T &x, const T &y) {
	if(y < x) x = y;
}

inline int read() {
	int res = 0; char ch = getchar(); bool f = 1;
	for(; ch < '0' || ch > '9'; ch = getchar())
		if(ch == '-') f = 0;
	for(; ch >= '0' && ch <= '9'; ch = getchar())
		res = res * 10 + ch - '0';
	return f ? res : -res;
}
const int N = 1e5 + 15;
ll sum[N];
ll a[N], b[N];

void Main() {
	int n = read(), q = read(), x, y;
	while(q --) {
		int opt = read(), l, r;
		if(opt == 1) {
			ll ans = 0;l = read(), r = read();
			rep(i, l, r) ans += sum[i];
			printf("%llu\n", ans);
		} else if(opt == 2) {
			rep(i, 1, n) sum[i] += a[i] * b[i];
		} else {
			l = read(), r = read();
			x = read(), y = read();
			rep(i, l, r) a[i] += x, b[i] += y;
		}
	}
}

}

bool _v;

signed main() {
	freopen("test.in", "r", stdin);
	freopen("2.out", "w", stdout);
	clock_t st = clock();
	AK :: Main();
	printf("==============================\n");
	cerr << "time = " << (clock() - st) * 1.0 / CLOCKS_PER_SEC << endl;
	cerr << "space = " << (&_u - &_v) / 1048576.0 << endl;
	return 0;
}
