#include <bits/stdc++.h>   using namespace std;   class SegmentTree {    private:     vector<long long> tree;     vector<long long> lazy;     vector<long long> num;     long long build(long long ind, long long l, long long r) {       if (l == r) {         tree[ind] = num[l];         return tree[ind];       }       tree[ind] = min(build(2 * ind, l, (l + r) / 2),                       build(2 * ind + 1, (l + r) / 2 + 1, r));       return tree[ind];     }     long long rngq(long long ind, long long l, long long r, long long ql,                    long long qr) {       if (lazy[ind] != 0) {         tree[ind] += lazy[ind];         if (l != r) {           lazy[2 * ind + 1] += lazy[ind];           lazy[2 * ind] += lazy[ind];         }         lazy[ind] = 0;       }       if (ql > r || qr < l) return (long long)1e18;       if (ql <= l && qr >= r) {         return tree[ind];       }       return min(rngq(2 * ind, l, (l + r) / 2, ql, qr),                  rngq(2 * ind + 1, (l + r) / 2 + 1, r, ql, qr));     }     long long update(long long ind, long long l, long long r, long long ql,                      long long qr, long long val) {       if (lazy[ind] != 0) {         tree[ind] += lazy[ind];         if (l != r) {           lazy[2 * ind + 1] += lazy[ind];           lazy[2 * ind] += lazy[ind];         }         lazy[ind] = 0;       }       if (ql > r || qr < l) return tree[ind];       if (ql <= l && qr >= r) {         tree[ind] += val;         if (l != r) {           lazy[2 * ind + 1] += val;           lazy[2 * ind] += val;         }         return tree[ind];       }       return tree[ind] =                  min(update(2 * ind, l, (l + r) / 2, ql, qr, val),                      update(2 * ind + 1, (l + r) / 2 + 1, r, ql, qr, val));     }       public:     void buildTree(vector<long long> arr) {       long long n = arr.size();       tree.resize(4 * n);       lazy.resize(4 * n, 0);       num = arr;       build(1, 0, n - 1);     }     long long query(long long l, long long r) {       return rngq(1, 0, num.size() - 1, l, r);     }     void rngup(long long l, long long r, long long val) {       update(1, 0, num.size() - 1, l, r, val);     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     vector<long long> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     SegmentTree segtree;     segtree.buildTree(arr);     long long q;     cin >> q;     while (q--) {       long long l, r;       cin >> l >> r;       if (cin.peek() ==   n ) {         if (r < l) {           cout << min(segtree.query(l, n - 1), segtree.query(0, r)) << endl;         } else           cout << segtree.query(l, r) << endl;       } else {         long long val;         cin >> val;         if (r < l) {           segtree.rngup(l, n - 1, val);           segtree.rngup(0, r, val);         } else           segtree.rngup(l, r, val);       }     }     return 0;   }   