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

using namespace std;

bool _u;

namespace AK {

typedef 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;

struct node {
	ll len;
	ll hs, sa, sb, sab;
	ll ta, tb, hk, ha, hb;

	inline void add(ll xa, ll xb) {
		sab += xa * sb + xb * sa + xa * xb * len;
		sa += xa * len; sb += xb * len;
		ta += xa; tb += xb;
	}

	inline void hadd(ll k, ll xa, ll xb) {
		hs += sab * k + xa * sb + xb * sa + xa * xb * len;
		hk += k; ha += xa + ta * k; hb += xb + tb * k;
	}

} t[N * 4];

#define lc (p << 1)
#define rc (p << 1 | 1)

inline void upd(int p) {
	t[p].sa = t[lc].sa + t[rc].sa;
	t[p].sb = t[lc].sb + t[rc].sb;
	t[p].sab = t[lc].sab + t[rc].sab;
	t[p].hs = t[lc].hs + t[rc].hs;
}

inline void push(int p) {
	if(t[p].hk || t[p].ha || t[p].hb) {
		t[lc].hadd(t[p].hk, t[p].ha, t[p].hb);
		t[rc].hadd(t[p].hk, t[p].ha, t[p].hb);
		t[p].hk = t[p].ha = t[p].hb = 0;
	}
	if(t[p].ta || t[p].tb) {
		t[lc].add(t[p].ta, t[p].tb);
		t[rc].add(t[p].ta, t[p].tb);
		t[p].ta = t[p].tb = 0;
	}
}

void build(int p, int l, int r) {
	t[p].len = r - l + 1;
	if(l == r) return ;
	int mid = l + r >> 1;
	build(lc, l, mid);
	build(rc, mid + 1, r);
}

void modify(int p, int l, int r, int tl, int tr, ll xa, ll xb) {
	if(tl <= l && r <= tr) {
		t[p].add(xa, xb);
		return ;
	}
	int mid = l + r >> 1;
	push(p);
	if(tl <= mid) modify(lc, l, mid, tl, tr, xa, xb);
	if(mid < tr) modify(rc, mid + 1, r, tl, tr, xa, xb);
	upd(p);
}

ll query(int p, int l, int r, int tl, int tr) {
	if(tl <= l && r <= tr) return t[p].hs;
	int mid = l + r >> 1;
	ll res = 0;
	push(p);
	if(tl <= mid) res += query(lc, l, mid, tl, tr);
	if(mid < tr) res += query(rc, mid + 1, r, tl, tr);
	return res;
}

void Main() {
	int n = read(), q = read(), x, y;
	build(1, 1, n);
	while(q --) {
		int opt = read(), l, r;
		if(opt == 1) l = read(), r = read(),printf("%llu\n", query(1, 1, n, l, r));
		else if(opt == 2) t[1].hadd(1, 0, 0);
		else l = read(), r = read(),x = read(), y = read(), modify(1, 1, n, l, r, x, y);
		//printf("%llu\n", t[1].sab);
	}
}

}

bool _v;

signed main() {
	freopen("test.in", "r", stdin);
	freopen("1.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;
}
