#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct AVL {
	struct Node {
		int l;
		int r;
		int val;
		int sum;
		int lazy;
		int size;
		int height;
	};
	static std::vector<Node> nodes;
	int root = 0;
	AVL() {
		if (!nodes.size()) nodes.push_back({0, 0, 0, 0, -1000000000, 0, 0});
	}
private:
	AVL(int root) : root(root) {}
	static inline int fetch(int i) {
		flush(i);
		if (nodes[i].l) flush(nodes[i].l);
		if (nodes[i].r) flush(nodes[i].r);
		nodes[i].size = 1 + nodes[nodes[i].l].size + nodes[nodes[i].r].size;
		nodes[i].height = 1 + std::max(nodes[nodes[i].l].height, nodes[nodes[i].r].height);
		nodes[i].sum = nodes[i].val + nodes[nodes[i].l].sum + nodes[nodes[i].r].sum;
		return i;
	}
	static inline void flush(int i) {
		int val = nodes[i].lazy;
		if (val != -1000000000) {
			nodes[nodes[i].l].lazy = val;
			nodes[nodes[i].r].lazy = val;
			nodes[i].val = val;
			nodes[i].sum = val * nodes[i].size;
		}
		nodes[i].lazy = -1000000000;
	}
	static inline int rotate_l(int i) {
		flush(i);
		if (nodes[i].l) flush(nodes[i].l);
		if (nodes[i].r) flush(nodes[i].r);
		int new_root = nodes[i].r;
		nodes[i].r = nodes[new_root].l;
		nodes[new_root].l = i;
		fetch(i);
		fetch(new_root);
		return new_root;
	}
	static inline int rotate_r(int i) {
		flush(i);
		if (nodes[i].l) flush(nodes[i].l);
		if (nodes[i].r) flush(nodes[i].r);
		int new_root = nodes[i].l;
		nodes[i].l = nodes[new_root].r;
		nodes[new_root].r = i;
		fetch(i);
		fetch(new_root);
		return new_root;
	}
	static inline int height_diff(int i) {
		return nodes[nodes[i].l].height - nodes[nodes[i].r].height;
	}
	static int balance(int i) {
		int dif = height_diff(i);
		if (dif == 2) {
			if (height_diff(nodes[i].l) < 0) nodes[i].l = rotate_l(nodes[i].l);
			return rotate_r(i);
		} else if (dif == -2) {
			if (height_diff(nodes[i].r) > 0) nodes[i].r = rotate_r(nodes[i].r);
			return rotate_l(i);
		} else return fetch(i);
	}
	static int insert(int node, int index, int val) {
		if (!node) {
			nodes.push_back({0, 0, val, val, -1000000000, 1, 1});
			return nodes.size() - 1;
		}
		flush(node);
		int lsize = nodes[nodes[node].l].size, tmp;
		if (index <= lsize) tmp = insert(nodes[node].l, index, val), nodes[node].l = tmp;
		else tmp = insert(nodes[node].r, index - lsize - 1, val), nodes[node].r = tmp;
		return balance(node);
	}
	static int removed_tmp;
	static int remove_rightest(int i) {
		flush(i);
		if (nodes[i].r) {
			nodes[i].r = remove_rightest(nodes[i].r);
			return balance(i);
		} else return nodes[removed_tmp = i].l;
	}
	static int remove(int node, int index) {
		flush(node);
		int lsize = nodes[nodes[node].l].size;
		if (index < lsize) nodes[node].l = remove(nodes[node].l, index);
		else if (index > lsize) nodes[node].r = remove(nodes[node].r, index - lsize - 1);
		else {
			if (!nodes[node].l) return nodes[node].r;
			if (!nodes[node].r) return nodes[node].l;
			nodes[node].l = remove_rightest(nodes[node].l);
			nodes[removed_tmp].l = nodes[node].l;
			nodes[removed_tmp].r = nodes[node].r;
			return balance(removed_tmp);
		}
		return balance(node);
	}
	
	static int merge_with_root(int l, int root, int r) {
		int dif = nodes[l].height - nodes[r].height;
		if (-1 <= dif && dif <= 1) {
			nodes[root].l = l;
			nodes[root].r = r;
			return fetch(root);
		} else if (dif > 0) {
			nodes[l].r = merge_with_root(nodes[l].r, root, r);
			return balance(l);
		} else {
			nodes[r].l = merge_with_root(l, root, nodes[r].l);
			return balance(r);
		}
	}
	static int merge(int l, int r) {
		if (!l) return r;
		if (!r) return l;
		l = remove_rightest(l);
		return merge_with_root(l, removed_tmp, r);
	}
	static std::pair<int, int> split(int node, int index) {
		if (!node) return {0, 0};
		flush(node);
		int l = nodes[node].l;
		int r = nodes[node].r;
		int lsize = nodes[l].size;
		nodes[node].l = nodes[node].r = 0;
		if (index < lsize) {
			std::pair<int, int> tmp = split(l, index);
			return {tmp.first, merge_with_root(tmp.second, node, r)};
		} else if (index > lsize) {
			std::pair<int, int> tmp = split(r, index - lsize - 1);
			return {merge_with_root(l, node, tmp.first), tmp.second};
		} else return {l, merge(fetch(node), r)};
	}
	static int sum(int node, int l, int r) {
		flush(node);
		if (l <= 0 && r >= nodes[node].size) return nodes[node].sum;
		int res = 0;
		int lsize = nodes[nodes[node].l].size;
		if (l <= lsize && r > lsize) res = nodes[node].val;
		if (l < lsize && nodes[node].l) res += sum(nodes[node].l, l, r);
		if (r > lsize + 1 && nodes[node].r) res += sum(nodes[node].r, l - lsize - 1, r - lsize - 1);
		return res;
	}
	static int update(int node, int l, int r, int val) {
		flush(node);
		if (l <= 0 && r >= nodes[node].size) {
			nodes[node].lazy = val;
			flush(node);
			return node;
		}
		int lsize = nodes[nodes[node].l].size;
		if (l <= lsize && r > lsize) nodes[node].val = val;
		if (l < lsize && nodes[node].l) update(nodes[node].l, l, r, val);
		if (r > lsize + 1 && nodes[node].r) update(nodes[node].r, l - lsize - 1, r - lsize - 1, val);
		return fetch(node);
	}
public:
	void insert(int index, int val) {
		root = insert(root, index, val);
	}
	void remove(int index) {
		assert(root);
		root = remove(root, index);
	}
	int operator [] (int i) {
		int cur = root;
		while (1) {
			flush(cur);
			int lsize = nodes[nodes[cur].l].size;
			if (i < lsize) cur = nodes[cur].l;
			else if (i > lsize) cur = nodes[cur].r, i -= lsize + 1;
			else return nodes[cur].val;
		}
	}
	static AVL merge(AVL l, AVL r) {
		return AVL(merge(l.root, r.root));
	}
	std::pair<AVL, AVL> split(int index) {
		auto res = split(root, index);
		return {AVL(res.first), AVL(res.second)};
	}
	int sum(int l, int r) {
		return sum(root, l, r);
	}
	void update(int l, int r, int val) {
		update(root, l, r, val);
	}
	
	void debug(int i, int indent) {
		if (!i) return;
		for (int i = 0; i < indent; i++) std::cerr << " ";
		std::cerr << i << ": val:" << nodes[i].val << " size:" << nodes[i].size << " height:" << nodes[i].height << std::endl;
		if (nodes[i].l) debug(nodes[i].l, indent + 1);
		if (nodes[i].r) debug(nodes[i].r, indent + 1);
	}
	void debug() { debug(root, 0); }
};
std::vector<AVL::Node> AVL::nodes;
int AVL::removed_tmp;

int main() {
	int n = ri(), q = ri();
	AVL tree;
	for (int i = 0; i < n; i++) tree.insert(0, 0);
	for (int i = 0; i < q; i++) {
		if (ri()) {
			int s = ri(), t = ri();
			printf("%d\n", tree.sum(s, t + 1));
		} else {
			int s = ri(), t = ri(), x = ri();
			tree.update(s, t + 1, x);
		}
	}
	return 0;
}



Measured memory_bytes: 6668