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 <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using std::min;
using std::vector;
using std::cin;
using std::cout;
using std::endl;


const static int neutral = 1000000000;
		

struct Node {
	size_t l;
	size_t r;
	Node* left;
	Node* right;
	int minimum;
	int add;

	Node (size_t l, size_t r, int minimum = neutral) {
		this->l = l;
		this->r = r;
		this->left = nullptr;
		this->right = nullptr;
		this->minimum = minimum;
		this->add = 0;
	}

	void push ();
} *root;

void Node::push () {
	if (left)
		left->add += add;
	
	if (right)
		right->add += add;

	minimum += add;
	add = 0;
}


/////////////////////////////////////////////////


class SegmentTree {
	private:

		int build (Node*, const vector<int>&);
	
	public:
		SegmentTree (const vector<int>&);
		int RMQ (size_t, size_t, Node*);
		void RAQ (size_t, size_t, int, Node*);
};

SegmentTree::SegmentTree (const vector<int> &array) {
	root = new Node(0, array.size() - 1);
	build(root, array);
}

int SegmentTree::build (Node *node, const vector<int> &array) {
	if (node->l != node->r) {
		size_t half = node->l + (node->r - node->l) / 2;
		node->left = new Node(node->l, half);
		node->right = new Node(half + 1, node->r);
		int left_min = build(node->left, array);
		int right_min = build(node->right, array);
		return node->minimum = min(left_min, right_min);
	}
	
	else {
		node->left = nullptr;
		node->right = nullptr;
		return node->minimum = array[node->l];
	}
}

int SegmentTree::RMQ (size_t l, size_t r, Node *node = nullptr) {
	if (!node)
		node = root;

	node->push();

	if (l <= node->l && node->r <= r)
		return node->minimum;

	if (node->r < l || r < node->l)
		return neutral;

	return min<int>(RMQ(l, r, node->left), RMQ(l, r, node->right));
}

void SegmentTree::RAQ (size_t l, size_t r, int add, Node *node = nullptr) {
	if (!node)
		node = root;

	node->push();

	if (l <= node->l && node->r <= r) {
		node->add += add;
		node->push();
		return;
	}

	else if (node->r < l || r < node->l)
		return;

	else {
		RAQ(l, r, add, node->left);
		RAQ(l, r, add, node->right);
		node->minimum = min<int>(node->left->minimum, node->right->minimum);
	}
}


/////////////////////////////////////////////////


int main () {
	int n, q;
	cin >> n >> q;
	vector<int> array(n, 0);

	SegmentTree segmentTree(array);

	for (int i = 0; i < q; i ++) {
		int type;
		cin >> type;

		if (type == 0) {
			size_t l, r;
			int add;
			cin >> l >> r >> add;
			segmentTree.RAQ(l, r, add);
		}

		else {
			size_t l, r;
			cin >> l >> r;
			cout << segmentTree.RMQ(l, r) << endl;
		}
	}

	return 0;
}