#include <bits/stdc++.h>
using namespace std;

template <class T = long long, class U = long long>
class LazyST {
   private:
	int n;
	int height = -1;	  //木の高さ
	vector<T> data;		  // monoid
	vector<U> lazy;		  // operator
	T unit_data;		  // monoid単位元
	U unit_lazy;		  // operator単位元
	function<T(T, T)> f;  // monoid同士の演算
	function<T(T, U)> g;  // monoidとoperatorとの演算
	function<U(U, U)> h;  // operator同士の演算
	void propagate(int lef, int rig) {
		// 遅延させていた作用素を上から伝播させる [lef,rig)に有効な範囲で
		lef += n;
		rig += n - 1;  //閉区間にする
		for(int i = height; i > 0; i--) {
			int l = lef >> i;
			int r = rig >> i;
			lazy[l << 1] = h(lazy[l << 1], lazy[l]);
			lazy[l << 1 | 1] = h(lazy[l << 1 | 1], lazy[l]);
			data[l] = g(data[l], lazy[l]);
			lazy[l] = unit_lazy;
			lazy[r << 1] = h(lazy[r << 1], lazy[r]);
			lazy[r << 1 | 1] = h(lazy[r << 1 | 1], lazy[r]);
			data[r] = g(data[r], lazy[r]);
			lazy[r] = unit_lazy;
		}
	}

   public:
	// 全て同じmonoid = init_dataで初期化
	LazyST(int _n, function<T(T, T)> ope_data_data, function<T(T, U)> ope_data_lazy, function<U(U, U)> ope_lazy_lazy, T _unit_data,
		   U _unit_lazy, T init_data)
		: n(_n), f(ope_data_data), g(ope_data_lazy), h(ope_lazy_lazy), unit_data(_unit_data), unit_lazy(_unit_lazy) {
		data.assign(n * 2, unit_data);
		for(int i = 0; i < n; i++) {
			data[i + n] = init_data;
		}
		for(int i = n - 1; i > -1; i--) {
			data[i] = f(data[i << 1], data[i << 1 | 1]);
		}
		lazy.assign(n * 2, unit_lazy);
		for(int i = 1; i <= n; i *= 2) height++;
	}
	// 初期化配列をvectorで渡す
	LazyST(int _n, function<T(T, T)> ope_data_data, function<T(T, U)> ope_data_lazy, function<U(U, U)> ope_lazy_lazy, T _unit_data,
		   U _unit_lazy, vector<T> raw_data)
		: n(_n), f(ope_data_data), g(ope_data_lazy), h(ope_lazy_lazy), unit_data(_unit_data), unit_lazy(_unit_lazy) {
		data.assign(n * 2, unit_data);
		for(int i = 0; i < n; i++) {
			data[i + n] = raw_data[i];
		}
		for(int i = n - 1; i > -1; i--) {
			data[i] = f(data[i << 1], data[i << 1 | 1]);
		}
		lazy.assign(n * 2, unit_lazy);
		for(int i = 1; i <= n; i *= 2) height++;
	}

	void update(int lef, int rig, U _operator) {  //[lef,rig)にopeを作用させる
		propagate(lef, rig);
		lef += n;
		rig += n;  //半開区間にする 下から上にdataを更新
		int L0 = lef / (lef & -lef);
		int R0 = rig / (rig & -rig);
		while(lef < rig) {
			if(lef & 1) {
				lazy[lef] = h(lazy[lef], _operator);
				// data[lef >> 1] = f(g(data[lef - 1], lazy[lef - 1]), g(data[lef], lazy[lef]));
				// lazy[lef >> 1] = unit_lazy;
				lef++;
			}
			if(rig & 1) {
				lazy[rig - 1] = h(lazy[rig - 1], _operator);
				// data[(rig - 1) >> 1] = f(g(data[rig - 1], lazy[rig - 1]), g(data[rig], lazy[rig]));
				// lazy[(rig - 1) >> 1] = unit_lazy;
				rig--;
			}
			lef >>= 1;
			rig >>= 1;
		}
		lef = L0;
		rig = R0;
		while(lef > 1) {
			lef >>= 1;
			data[lef] = f(g(data[lef << 1], lazy[lef << 1]), g(data[lef << 1 | 1], lazy[lef << 1 | 1]));
			lazy[lef] = unit_lazy;
		}
		while(rig > 1) {
			rig >>= 1;
			data[rig] = f(g(data[rig << 1], lazy[rig << 1]), g(data[rig << 1 | 1], lazy[rig << 1 | 1]));
			lazy[rig] = unit_lazy;
		}
	}

	T get(int lef, int rig) {  //区間の値取得
		propagate(lef, rig);
		T a = unit_data, b = unit_data;
		lef += n;
		rig += n;
		while(lef < rig) {
			if(lef & 1) a = f(a, g(data[lef], lazy[lef]));
			if(rig & 1) b = f(g(data[rig - 1], lazy[rig - 1]), b);
			(lef += 1) >>= 1;
			rig >>= 1;
		}
		return f(a, b);
	}
};

#pragma region macros_and_aliases
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define rrep(i, n) for(long long i = (n)-1; i > -1; i--)
#define Rep(i, m, n) for(long long i = (m); i < (n); i++)
#define rRep(i, m, n) for(long long i = (n)-1; i >= (m); i--)
#define REP(i, m, n, p) for(long long i = m; i < n; i += p)
#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pq priority_queue
#define bcnt(n) __builtin_popcountll(n)
#define endk endl
#define ednl endl
#define enld endl
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using qll = queue<long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
template <class T = ll>
using V = vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
//昇順pq(小さい方から取り出す)
template <class T = ll>
using pqup = priority_queue<T, vector<T>, greater<T>>;
//降順pq(大きい方から取り出す)
template <class T = ll>
using pqdn = priority_queue<T>;
#define debug(var)              \
	std::cout << #var << " : "; \
	view(var)
template <typename T>
void view(T e) {
	std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T> &v) {
	for(const auto &e : v) {
		std::cout << e << " ";
	}
	std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	for(const auto &v : vv) {
		view(v);
	}
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}
#pragma endregion

int main() {
	// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_F
	// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_G
	// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_H
	// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_I

	ll dekai = 3e16;
	ll unit_upd = -dekai;  // upd,PairUpdの単位元 被らなければ何でも
	// 合計値クエリに使用するpair<要素合計,個数>の単位元
	pair<long long, long long> unit_pair = {0, 0};
	// pairの初期化要素
	pair<long long, long long> init_pair = {0, 1};

	// 単位元 = 0
	auto add = [](ll a, ll b) { return a + b; };

	// 単位元 = dekai
	auto mini = [](ll a, ll b) { return min(a, b); };

	// 単位元 = -dekai
	auto maxi = [](ll a, ll b) { return max(a, b); };

	// 単位元 = unit_upd
	auto upd = [&](ll a, ll b) { return b == unit_upd ? a : b; };

	// 単位元 = unit_pair
	auto PairPlusPair = [](pll a, pll b) { return (pll){a.first + b.first, a.second + b.second}; };

	// 単位元 = 0
	auto PairPlusLL = [](pll a, ll b) { return (pll){a.first + b * a.second, a.second}; };

	// 単位元 = unit_upd
	auto PairUpd = [&](pll a, ll b) {
		if(b != unit_upd) return (pll){b * a.second, a.second};
		return a;
	};

	// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_G
	ll n, q;
	cin >> n >> q;
	int index = 1;
	LazyST<pll, ll> st(n, PairPlusPair, PairPlusLL, add, unit_pair, 0, init_pair);
	vll ans;
	rep(i, q) {
		int kind;
		cin >> kind;
		ll s, t;
		cin >> s >> t;
		if(index == 1)
			s--;
		else
			t++;
		if(kind) {
			pll k = st.get(s, t);
			ans.push_back(k.first);
		} else {
			ll x;
			cin >> x;
			st.update(s, t, x);
		}
	}
	foa(t, ans) cout << t << enld;
}



Measured memory_bytes: 8636