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

* $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$.
* $find(s, t)$ : report the minimum value in $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 $add(s, t, x)$ and '1' denotes $find(s, t)$.

Output

For each $find$ query, print the minimum value.

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

-2
0
1
-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
template<typename DATA_TYPE, typename LAZY_TYPE, typename F, typename G, typename H, typename P>
class SegmentTree {
  private:
	size_t size;

	F f;
	G g;
	H h;
	P p;

	std::vector<DATA_TYPE> data;
	std::vector<LAZY_TYPE> lazy;
	DATA_TYPE data_init;
	LAZY_TYPE lazy_init;

	vector<bool> use_lazy_flag;

	SegmentTree() : size(0) {}

	void eval(int length, size_t index) {
		if (!use_lazy_flag[index]) return;
		if (index * 2 + 1 < size * 2 - 1) {
			use_lazy_flag[index * 2 + 1] = use_lazy_flag[index * 2 + 2] = true;
			lazy[index * 2 + 1] = h(lazy[index * 2 + 1], lazy[index]);
			lazy[index * 2 + 2] = h(lazy[index * 2 + 2], lazy[index]);
		}
		data[index] = g(data[index], p(lazy[index], length));
		lazy[index] = lazy_init;
		use_lazy_flag[index] = false;
	}

	void update(size_t begin, size_t end, LAZY_TYPE update_value, size_t index, size_t left, size_t right) {
		eval(right - left, index);
		if (right <= begin || end <= left) return;
		if (begin <= left && right <= end) {
			lazy[index] = h(lazy[index], update_value);
			use_lazy_flag[index] = true;
			eval(right - left, index);
		}
		else {
			update(begin, end, update_value, index * 2 + 1, left, (left + right) / 2);
			update(begin, end, update_value, index * 2 + 2, (left + right) / 2, right);
			data[index] = f(data[2 * index + 1], data[2 * index + 2]);
		}
	}

	DATA_TYPE query(size_t begin, size_t end, size_t index, size_t left, size_t right) {
		eval(right - left, index);
		if (right <= begin || end <= left) return data_init;
		if (begin <= left && right <= end) return data[index];
		return f(query(begin, end, index * 2 + 1, left, (left + right) / 2), query(begin, end, index * 2 + 2, (left + right) / 2, right));
	}

  public:
	SegmentTree(size_t data_size, F f, G g, H h, P p, DATA_TYPE data_init, LAZY_TYPE lazy_init) : f(f), g(g), h(h), p(p), data_init(data_init), lazy_init(lazy_init) {
		size = 1;
		while (size < data_size) size <<= 1U;
		data.resize(2 * size - 1, data_init);
		lazy.resize(2 * size - 1, lazy_init);
		use_lazy_flag.resize(2 * size - 1, false);
	}

	void update(size_t begin, size_t end, LAZY_TYPE update_value) {
		update(begin, end, update_value, 0, 0, size);
	}

	DATA_TYPE query(size_t begin, size_t end) {
		return query(begin, end, 0, 0, size);
	}

    void build(std::vector<DATA_TYPE> input_data) {
        if (input_data.size() > size) {
            std::cerr << "segment tree::build : input oversize data\n";
            exit(-1);
        }
        for (int i = 0; i < input_data.size(); ++i) {
            data[i + size - 1] = input_data[i];
        }
        for (int i = size - 2; i >= 0; --i) {
            data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }
};
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
    auto f = [](int a, int b) { return min(a, b); };
    auto g = [](int a, int b) { return a + b; };
    auto h = [](int a, int b) { return a + b; };
    auto p = [](int a, size_t b) { return a; };
	int n, q;
	cin >> n >> q;
	SegmentTree<int, int, decltype(f), decltype(g), decltype(h), decltype(p)> segTree(n, f, g, h, p, 10000000000007LL, 0);
	segTree.build(vector<int>(n,0));
	rep(i, q) {
		int qt;
		cin >> qt;
		if (qt) {
			int s, t;
			cin >> s >> t;
			cout << segTree.query(s, t + 1) << endl;
		}
		else {
			int s, t, x;
			cin >> s >> t >> x;
			segTree.update(s, t + 1, x);
		}
	}
}