import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.io.PrintWriter import java.util.* class LazySegTree(private val n: Int) : Iterable { private var d: MutableList private var lz: MutableList private var size = 1 private var log = 0 private val e = Long.MAX_VALUE private val id = 0L init { while (size < n) { size *= 2 log++ } d = MutableList(2 * size) { e } lz = MutableList(size) { id } } constructor(n: Int, a: Array) : this(n) { for (i in 0 until n) { d[size + i] = a[i] } for (i in size - 1 downTo 1) { update(i) } } operator fun set(p: Int, x: Long) { if (p !in 0 until n) { throw Exception() } val p1 = p + size for (i in log downTo 1) { push(p1 shr i) } d[p1] = x for (i in 1..log) { update(p1 shr i) } } operator fun get(p: Int): Long { if (p !in 0 until n) { throw Exception() } val p1 = p + size for (i in log downTo 1) { push(p1 shr i) } return d[p1] } fun prod(l: Int, r: Int): Long { if (l !in 0..r || r !in l..n) { throw Exception() } if (l == r) return e var l1 = l + size var r1 = r + size for (i in log downTo 1) { if ((l1 shr i) shl i != l1) push(l1 shr i) if ((r1 shr i) shl i != r1) push(r1 shr i) } var sml = e var smr = e while (l1 < r1) { if (l1 and 1 != 0) sml = minOf(sml, d[l1++]) if (r1 and 1 != 0) smr = minOf(d[--r1], smr) l1 /= 2 r1 /= 2 } return minOf(sml, smr) } fun allProd(): Long { return d[1] } fun apply(p: Int, f: Long) { if (p !in 0 until n) { throw Exception() } val p1 = p + size for (i in log downTo 1) { push(p1 shr i) } d[p1] = f + d[p1] for (i in 1..log) { update(p1 shr i) } } fun apply(l: Int, r: Int, f: Long) { if (l !in 0..r || r !in l..n) { throw Exception() } if (l == r) return var l1 = l + size var r1 = r + size for (i in log downTo 1) { if ((l1 shr i) shl i != l1) push(l1 shr i) if ((r1 shr i) shl i != r1) push((r1 - 1) shr i) } val l2 = l1 val r2 = r1 while (l1 < r1) { if (l1 and 1 != 0) allApply(l1++, f) if (r1 and 1 != 0) allApply(--r1, f) l1 /= 2 r1 /= 2 } l1 = l2 r1 = r2 for (i in 1..log) { if ((l1 shr i) shl i != l1) update(l1 shr i) if ((r1 shr i) shl i != r1) update((r1 - 1) shr i) } } private fun update(k: Int) { d[k] = minOf(d[2 * k], d[2 * k + 1]) } private fun allApply (k: Int, f: Long) { d[k] = f + d[k] if (k < size) { lz[k] = f + lz[k] } } private fun push(k: Int) { allApply(2 * k, lz[k]) allApply(2 * k + 1, lz[k]) lz[k] = id } override fun iterator(): Iterator { return (0 until n).map { this[it] }.iterator() } } fun PrintWriter.solve(sc: FastScanner) { val n = sc.nextInt() val a = Array(n) { sc.nextLong() } val seg = LazySegTree(n, a) val q = sc.nextInt() for (_i in 0 until q) { val k = sc.nextInt() val l = sc.nextInt() - 1 val r = sc.nextInt() val c = sc.nextLong() if (k == 1) { seg.apply(l, r, c) } else { println(seg.prod(l, r)) } } } fun main() { val writer = PrintWriter(System.out, false) writer.solve(FastScanner(System.`in`)) writer.flush() } class FastScanner(s: InputStream) { private var st = StringTokenizer("") private val br = BufferedReader(InputStreamReader(s)) fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() fun ready() = br.ready() }