#include using namespace std; template class LazySegmentTree { private: int N, size, log; vector D; vector L; void apply(int k) { D.at(k) = op(D.at(2 * k), D.at(2 * k + 1)); } void update_all(int k, F f) { D.at(k) = mapp(f, D.at(k)); if (k < size) L.at(k) = comp(f, L.at(k)); } void push(int k) { update_all(2 * k, L.at(k)); update_all(2 * k + 1, L.at(k)); L.at(k) = id(); } int ceil_pow(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } public: LazySegmentTree() : LazySegmentTree(0) {} LazySegmentTree(int n) : LazySegmentTree(vector(n, el())) {} LazySegmentTree(const vector& v) : N(int(v.size())) { log = ceil_pow(N); size = 1 << log; D = vector(2 * size, el()); L = vector(size, id()); for (int i = 0; i < N; i++) D.at(size + i) = v.at(i); for (int i = size - 1; i >= 1; i--) apply(i); } void set(int p, S x) { p += size; for (int i = log; i >= 1; i--) push(p >> i); D.at(p) = x; for (int i = 1; i <= log; i++) apply(p >> i); } S get(int p) { p += size; for (int i = log; i >= 1; i--) push(p >> i); return D.at(p); } S query(int l, int r) { r++; if (l == r) return el(); l += size, r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push(r >> i); } S sml = el(), smr = el(); while (l < r) { if (l & 1) sml = op(sml, D.at(l++)); if (r & 1) smr = op(D.at(--r), smr); l >>= 1, r >>= 1; } return op(sml, smr); } S query_all() { return D.at(1); } void update(int p, F f) { p += size; for (int i = log; i >= 1; i--) push(p >> i); D.at(p) = mapp(f, D.at(p)); for (int i = 1; i <= log; i++) apply(p >> i); } void update(int l, int r, F f) { r++; if (l == r) return; l += size, r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) update_all(l++, f); if (r & 1) update_all(--r, f); l >>= 1, r >>= 1; } l = l2, r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) apply(l >> i); if (((r >> i) << i) != r) apply((r - 1) >> i); } } template int max_right(int l) { return max_right(l, [](S x) { return g(x); }); } template int max_right(int l, G g) { if (l == N) return N; l += size; for (int i = log; i >= 1; i--) push(l >> i); S sm = el(); do { while (l % 2 == 0) l >>= 1; if (!g(op(sm, D.at(l)))) { while (l < size) { push(l); l = (2 * l); if (g(op(sm, D.at(l)))) sm = op(sm, D.at(l++)); } return l - size; } sm = op(sm, D.at(l++)); } while ((l & -l) != l); return N; } template int min_left(int r) { return min_left(r, [](S x) { return g(x); }); } template int min_left(int r, G g) { if (r == 0) return 0; r += size; for (int i = log; i >= 1; i--) push((r - 1) >> i); S sm = el(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!g(op(D.at(r), sm))) { while (r < size) { push(r); r = (2 * r + 1); if (g(op(D.at(r), sm))) sm = op(D.at(r--), sm); } return r + 1 - size; } sm = op(D.at(r), sm); } while ((r & -r) != r); return 0; } }; using S = long; using F = long; S op(S a, S b) { return min(a, b); } S el() { return LONG_MAX; } S mapp(F f, S s) { return f + s; } F comp(F a, F b) { return a + b; } F id() { return 0; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A.at(i); LazySegmentTree ST(A); int Q; cin >> Q; while (Q--) { int k, l, r, c; cin >> k >> l >> r >> c, l--, r--; if (k == 1) { ST.update(l, r, c); } else { cout << ST.query(l, r) << "\n"; } } }