Problem: Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:

* $update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$.
* $getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$.



Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.

Constraints

* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$

Input


$n$ $q$
$query_1$
$query_2$
:
$query_q$


In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$-th query $query_i$ is given in the following format:


0 $s$ $t$ $x$


or


1 $s$ $t$


The first digit represents the type of the query. '0' denotes $update(s, t, x)$ and '1' denotes $find(s, t)$.

Output

For each $getSum$ query, print the sum in a line.

Example

Input

6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5


Output

-5
1
6
8

Solution (in CPP):

Solution:
#include <vector>
#include <functional>

#include <algorithm>
#include <iostream>
#include <utility>

// Segment tree with lazy propagation.
template <class Data, class Operator>
class LazySegmentTree
{
	int size_, height_;

	// (Data, F) is a monoid.
	std::vector<Data> data_;
	using F = std::function<Data(Data, Data)>;
	const F f_;
	const Data data_id_;

	// This is operation.
	using G = std::function<Data(Data, Operator)>;
	const G g_;

	// (Operator, H) is a monoid.
	std::vector<Operator> lazy_;
	using H = std::function<Operator(Operator, Operator)>;
	const H h_;
	const Operator operator_id_;

	void init(int num)
	{
		size_ = 1;
		height_ = 0;
		while (size_ < num)
		{
			size_ <<= 1;
			++height_;
		}
		data_.assign(size_ << 1, data_id_);
		lazy_.assign(size_ << 1, operator_id_);
	}

	inline Data reflect(int k)
	{
		if (lazy_[k] == operator_id_)
		{
			return data_[k];
		}
		else
		{
			return g_(data_[k], lazy_[k]);
		}
	}

	inline void eval(int k)
	{
		if (lazy_[k] == operator_id_)
			return;
		lazy_[(k << 1) | 0] = h_(lazy_[(k << 1) | 0], lazy_[k]);
		lazy_[(k << 1) | 1] = h_(lazy_[(k << 1) | 1], lazy_[k]);
		data_[k] = reflect(k);
		lazy_[k] = operator_id_;
	}

	inline void thrust(int k)
	{
		for (int i = height_; i > 0; --i)
		{
			eval(k >> i);
		}
	}

	inline void recalc(int k)
	{
		while (k >>= 1)
		{
			data_[k] = f_(reflect((k << 1) | 0), reflect((k << 1) | 1));
		}
	}

  public:
	LazySegmentTree(F f, G g, H h, Data data_id, Operator operator_id)
		: f_(f), data_id_(data_id), g_(g), h_(h), operator_id_(operator_id) {}

	void build(const std::vector<Data> &elements)
	{
		const int num = elements.size();
		init(num);
		for (int i = 0; i < num; ++i)
		{
			data_[size_ + i] = elements[i];
		}
		for (int i = size_ - 1; i > 0; --i)
		{
			data_[i] = f_(data_[(i << 1) | 0], data_[(i << 1) | 1]);
		}
	}

	void update(int a, int b, Operator x)
	{
		thrust(a += size_);
		thrust(b += size_ - 1);
		for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1)
		{
			if (l & 1)
			{
				lazy_[l] = h_(lazy_[l], x);
				++l;
			}
			if (r & 1)
			{
				--r;
				lazy_[r] = h_(lazy_[r], x);
			}
		}
		recalc(a);
		recalc(b);
	}

	void set(int a, Data x)
	{
		thrust(a += size_);
		data_[a] = x;
		lazy_[a] = operator_id_;
		recalc(a);
	}

	Data query(int a, int b)
	{
		thrust(a += size_);
		thrust(b += size_ - 1);
		Data vl = data_id_, vr = data_id_;
		for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1)
		{
			if (l & 1)
			{
				vl = f_(vl, reflect(l++));
			}
			if (r & 1)
			{
				vr = f_(reflect(--r), vr);
			}
		}
		return f_(vl, vr);
	}
};

int main()
{
	// range update, range sum
	int n, q;
	std::cin >> n >> q;
	using ll = long long;
	using P = std::pair<ll, ll>;
	auto f = [](P a, P b) {
		return P(a.first + b.first, a.second + b.second);
	};
	auto g = [](P a, ll b) {
		if (b == 1e12)
		{
			return P(a.first, a.second);
		}
		else
		{
			return P(b * a.second, a.second);
		}
	};
	auto h = [](ll a, ll b) { return b; };
	LazySegmentTree<P, ll> seg_tree(f, g, h, P(0, 0), 1e12);
	seg_tree.build(std::vector<P>(n, P(0, 1)));
	for (int i = 0; i < q; ++i)
	{
		int c, s, t;
		ll x;
		std::cin >> c;
		if (c)
		{
			std::cin >> s >> t;
			std::cout << seg_tree.query(s, t + 1).first << std::endl;
		}
		else
		{
			std::cin >> s >> t >> x;
			seg_tree.update(s, t + 1, x);
		}
	}
}