You are given circular array a0, a1, ..., an - 1. There are two types of operations with it: 

  * inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v; 
  * rmq(lf, rg) — this operation returns minimal value on the segment [lf, rg] (inclusively). 



Assume segments to be circular, so if n = 5 and lf = 3, rg = 1, it means the index sequence: 3, 4, 0, 1.

Write program to process given sequence of operations.

Input

The first line contains integer n (1 ≤ n ≤ 200000). The next line contains initial state of the array: a0, a1, ..., an - 1 ( - 106 ≤ ai ≤ 106), ai are integer. The third line contains integer m (0 ≤ m ≤ 200000), m — the number of operartons. Next m lines contain one operation each. If line contains two integer lf, rg (0 ≤ lf, rg ≤ n - 1) it means rmq operation, it contains three integers lf, rg, v (0 ≤ lf, rg ≤ n - 1; - 106 ≤ v ≤ 106) — inc operation.

Output

For each rmq operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples

Input

4
1 2 3 4
4
3 0
3 0 -1
0 1
2 1


Output

1
0
0
#include <bits/stdc++.h>
class SegmentTree {
  static const int64_t inf = 1LL << 61;
  size_t n;
  std::vector<int64_t> tree, oft, num;
  auto pow2_least(size_t n) -> size_t {
    size_t m;
    for (m = 1; m <= n; m <<= 1) {
    }
    return m;
  }
  void modify(size_t l, size_t r, int64_t x, size_t i, size_t a, size_t b) {
    if (r <= a || b <= l) return;
    if (l <= a && b <= r) {
      oft[i] += x;
      return;
    }
    size_t c = (a + b) >> 1;
    modify(l, r, x, i << 1 | 0, a, c);
    modify(l, r, x, i << 1 | 1, c, b);
    int64_t lch = oft[i << 1 | 0] + tree[i << 1 | 0];
    int64_t rch = oft[i << 1 | 1] + tree[i << 1 | 1];
    if (lch < rch) {
      num[i] = num[i << 1 | 0];
      tree[i] = lch;
    } else if (lch > rch) {
      num[i] = num[i << 1 | 1];
      tree[i] = rch;
    } else {
      num[i] = num[i << 1 | 0] + num[i << 1 | 1];
      tree[i] = lch;
    }
  }
  std::pair<int64_t, int> query(size_t l, size_t r, size_t i, size_t a,
                                size_t b) {
    if (r <= a || b <= l) return {inf, 0};
    if (l <= a && b <= r) return {oft[i] + tree[i], num[i]};
    size_t c = (a + b) >> 1;
    auto lch = query(l, r, i << 1 | 0, a, c);
    auto rch = query(l, r, i << 1 | 1, c, b);
    if (lch.first < rch.first) {
      lch.first += oft[i];
      return lch;
    } else if (lch.first > rch.first) {
      rch.first += oft[i];
      return rch;
    } else {
      lch.first += oft[i];
      lch.second += rch.second;
      return lch;
    }
  }

 public:
  SegmentTree(size_t m)
      : n(pow2_least(m)), tree(n << 1), oft(n << 1), num(n << 1, 1) {}
  void modify(size_t l, size_t r, int64_t x) { modify(l, r, x, 1, 0, n); }
  std::pair<int64_t, int> query(size_t l, size_t r) {
    return query(l, r, 1, 0, n);
  }
};
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  size_t n;
  std::cin >> n;
  SegmentTree tree(n);
  for (size_t i = 0; i < n; ++i) {
    int64_t a;
    std::cin >> a;
    tree.modify(i, i + 1, a);
  }
  int m;
  std::cin >> m;
  std::cin.ignore();
  for (int i = 0; i < m; ++i) {
    std::string buf;
    std::getline(std::cin, buf);
    std::stringstream ss(buf);
    size_t lf, rg;
    int64_t v;
    if (std::count(buf.begin(), buf.end(), ' ') < 2) {
      ss >> lf >> rg;
      if (lf <= rg) {
        std::cout << tree.query(lf, rg + 1).first << "\n";
      } else if (rg + 1 == lf) {
        std::cout << tree.query(0, n).first << "\n";
      } else {
        int64_t l = tree.query(lf, n).first;
        int64_t r = tree.query(0, rg + 1).first;
        std::cout << std::min(l, r) << "\n";
      }
    } else {
      ss >> lf >> rg >> v;
      if (lf <= rg) {
        tree.modify(lf, rg + 1, v);
      } else if (rg + 1 == lf) {
        tree.modify(0, n, v);
      } else {
        tree.modify(lf, n, v);
        tree.modify(0, rg + 1, v);
      }
    }
  }
  return 0;
}
