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>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct M {
  using T = array<lint, 3>; // min, max, sum
  using U = array<lint, 2>; // linear function
  static T op(const T& a, const T& b) { return T{min(a[0], b[0]), max(a[1], b[1]), a[2] + b[2]}; }
  static constexpr T e() { return T{numeric_limits<lint>::max(), numeric_limits<lint>::min(), 0}; }
  static void ap(T& a, const U& g, int k) { for (int i = 0; i < 3; i++) a[i] = g[0] * a[i] + (i == 2 ? k : 1) * g[1]; if (g[0] < 0) swap(a[0], a[1]); }
  static void ap(U& f, const U& g) { f[0] *= g[0]; f[1] = g[0] * f[1] + g[1]; }
  static constexpr U id() { return U{1, 0}; }
};

template<class M> struct ST {
  using T = typename M::T;
  using U = typename M::U;
  int n;
  V<T> t;
  V<U> u;
  V<> k;

  ST(int n) : n(n) {
    t.assign(2 * n, M::e());
    u.assign(n, M::id());
    k.assign(2 * n, 1);
    for (int i = n - 1; i; i--) k[i] = k[2 * i] + k[2 * i + 1];
  }

  void _ap(int i, const U& f) {
    M::ap(t[i], f, k[i]);
    if (i < n) M::ap(u[i], f);
  }

  void build() {
    for (int i = n - 1; i; i--) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }

  T get(int l, int r) {
    _push(l, r);
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = M::op(resl, t[l++]);
      if (r & 1) resr = M::op(t[--r], resr);
    }
    return M::op(resl, resr);
  }

  void push() {
    for (int i = 1; i < n; i++) {
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
    }
  }

  void _push(int l, int r) {
    for (int hl = 8 * sizeof(int) - __builtin_clz(l + n) - 1, hr = 8 * sizeof(int) - __builtin_clz(r - 1 + n) - 1; hr > 0; hl--, hr--) {
      int i = r - 1 + n >> hr;
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
      i = l + n >> hl;
      if (i == r - 1 + n >> hr or i >= n) continue;
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
    }
  }

  void set(int l, int r, const U& f) {
    _push(l, r);
    for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) {
      if (i & 1) _ap(i++, f);
      if (j & 1) _ap(--j, f);
    }
    for (l += n; !(l & 1);) l >>= 1;
    while (l >>= 1) t[l] = M::op(t[2 * l], t[2 * l + 1]);
    for (r += n; !(r & 1);) r >>= 1;
    while (r >>= 1) t[r] = M::op(t[2 * r], t[2 * r + 1]);
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int m = 20;
  int n, q; cin >> n >> q;
  ST<M> st(n);
  for (int i = 0; i < n; i++) st.t[i + n].fill(0);
  st.build();
  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    if (t) {
      int l, r; cin >> l >> r, r++;
      lint res = 0;
      for (int i = 0; i < m; i++) res += st.get(l, r)[0];
      cout << res / m << '\n';
    } else {
      int l, r, x; cin >> l >> r >> x, r++;
      for (int i = 0; i < m - 1; i++) st.set(l, r, M::U{1, 0});
      st.set(l, r, M::U{1, x});
    }
  }
}