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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<class T1,class T2,class BiOp1,class BiOp2,class BiOp3>
struct LazySegmentTree {
	//BiOp1:T1×T1->T1
	//BiOp2:T2×T2->T2
	//BiOp3:T1×T2->T1
	vector<T1> data;
	vector<T2> lazy;
	T1 e1;
	T2 e2;
	BiOp1 op1;
	BiOp2 op2;
	BiOp3 op3;
	int size;
	LazySegmentTree(int n, T1 e1, T2 e2, BiOp1 op1, BiOp2 op2, BiOp3 op3) :e1(e1), e2(e2), op1(op1), op2(op2), op3(op3) {
		size = 1;
		while (size < n) size *= 2;
		data.resize(size * 2 - 1);
		lazy.resize(size * 2 - 1);
		for (int i = 0; i < size * 2 - 1; i++) {
			data[i] = e1;
			lazy[i] = e2;
		}
	}
	LazySegmentTree(int n, vector<T1> &v, T1 e1, T2 e2, BiOp1 op1, BiOp2 op2, BiOp3 op3) :e1(e1), e2(e2), op1(op1), op2(op2), op3(op3) {
		size = 1;
		while (size < n) size *= 2;
		data.resize(size * 2 - 1);
		lazy.resize(size * 2 - 1);
		for (int i = 0; i < size * 2 - 1; i++) {
			data[i] = e1;
			lazy[i] = e2;
		}
		for (int i = n - 1 + (size - 1); i >= 0; i--) {
			if (i >= size - 1) {
				data[i] = v[i - (size - 1)];
			}
			else {
				data[i] = op1(data[i * 2 + 1], data[i * 2 + 2]);
			}
		}
	}
	void push(int k) {
		if (lazy[k] == e2) return;
		if (k < size) {
			lazy[k * 2 + 1] = op2(lazy[k * 2 + 1], lazy[k]);
			lazy[k * 2 + 2] = op2(lazy[k * 2 + 2], lazy[k]);
		}
		data[k] = op3(data[k], lazy[k]);
		lazy[k] = e2;
	}
	T1 query(int a, int b, int k, int l, int r) {
		if (b <= l || r <= a) return e1;
		if (a <= l && r <= b) return op3(data[k], lazy[k]);
		push(k);
		return op1(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
	}
	void update(int a, int b, T2 v, int k, int l, int r) {
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = op2(lazy[k], v);
			return;
		}
		push(k);
		update(a, b, v, k * 2 + 1, l, (l + r) / 2);
		update(a, b, v, k * 2 + 2, (l + r) / 2, r);
		data[k] = op1(op3(data[k * 2 + 1], lazy[k * 2 + 1]), op3(data[k * 2 + 2], lazy[k * 2 + 2]));
	}
};
struct Add {
	int operator()(int a, int b) const {
		return a + b;
	}
};
struct Min {
	int operator()(int a, int b) const {
		return min(a, b);
	}
};
struct Apply {
	int operator()(int a, int b) const {
		return a + b;
	}
};
int main() {
	int n, q;
	cin >> n >> q;
	vector<int> data(n, 0);
	LazySegmentTree<int, int, Min, Add, Apply> S(n, data, 1 << 30, 0, Min(), Add(), Apply());
	for (int i = 0; i < q; i++) {
		int type;
		int s, t, x;
		cin >> type;
		if (type == 0) {
			cin >> s >> t >> x;
			t++;
			S.update(s, t, x, 0, 0, S.size);
		}
		else {
			cin >> s >> t;
			t++;
			cout << S.query(s, t, 0, 0, S.size) << endl;
		}
	}

}