#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const long long INF = 4e17;   const int mod = 1e9 + 7;   const double eps = 1e-9;   const int N = 2e5 + 10;   long long n, arr[N], tree[N << 2], lazy[N << 2];   void build(int node = 1, int L = 1, int R = n) {     if (L == R) {       tree[node] = arr[L];       lazy[node] = 0;       return;     }     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     build(lc, L, mid), build(rc, mid + 1, R);     tree[node] = tree[lc] + tree[rc];   }   void set0(int l, int r, int node = 1, int L = 1, int R = n) {     if (r < L || R < l || r < l) return;     if (l <= L && R <= r) {       tree[node] = 0;       lazy[node] = 1;       return;     }     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     if (lazy[node]) return;     set0(l, r, lc, L, mid), set0(l, r, rc, mid + 1, R);     tree[node] = tree[lc] + tree[rc];   }   void upd(int pos, int v, int node = 1, int L = 1, int R = n) {     if (L == R) {       tree[node] += v;       return;     }     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     if (pos <= mid)       upd(pos, v, lc, L, mid);     else       upd(pos, v, rc, mid + 1, R);     tree[node] = tree[lc] + tree[rc];   }   long long getsum(int l, int r, int node = 1, int L = 1, int R = n) {     if (r < L || R < l) return 0;     if (l <= L && R <= r) return tree[node];     if (lazy[node]) return 0;     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     return getsum(l, r, lc, L, mid) + getsum(l, r, rc, mid + 1, R);   }   long long getcap(int pos, int node = 1, int L = 1, int R = n) {     if (L == R) return tree[node];     if (lazy[node]) return 0;     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     if (pos <= mid) return getcap(pos, lc, L, mid);     return getcap(pos, rc, mid + 1, R);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     int m;     scanf( %d , &m);     build();     while (m--) {       long long t, x, p, k;       scanf( %lld , &t);       if (t == 1) {         scanf( %lld %lld , &p, &x);         long long cap = getcap(p);         if (cap > x) {           if (!1) cout <<  no overflow decrease   << x <<   from cap n ;           upd(p, -x);           if (!1) cout <<  at   << p <<   now   << getcap(p) <<   n ;         } else {           long long got = 0;           int lo = p, hi = n, pos = n + 1;           while (lo <= hi) {             int mid = (lo + hi) >> 1;             got = getsum(p, mid);             if (!1)               cout <<  from   << p <<   ->   << mid <<   sum   << got <<   n ;             if (got >= x)               hi = mid - 1, pos = mid;             else               lo = mid + 1;           }           long long usedup = getsum(p, pos - 1);           if (!1)             cout <<  overflow ends at   << pos <<   and used up   << usedup                  <<   out of   << x <<   n ;           upd(pos, usedup - x);           if (!1) cout <<  set 0 to all in   << p <<   ->   << pos - 1 <<   n ;           set0(p, pos - 1);         }       } else {         scanf( %lld , &k);         if (!1) cout <<  found   << getcap(k) <<   amount left n ;         printf( %lld n , arr[k] - getcap(k));       }     }     return 0;   }