malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const long long MOD = 1000000007;   int N, K;   long long a[5002], FUL[5001];   long long inv[5001];   long long O;   long long POWER(long long a, long long b) {     long long r = 1;     for (; b; b >>= 1) {       if (b & 1) r = r * a % MOD;       a = a * a % MOD;     }     return r;   }   int main() {     scanf( %d%d , &N, &K);     if (N == 1) {       printf( %lld n , K % MOD);       return 0;     }     FUL[0] = 1;     for (int i = 1; i <= N; i++) {       scanf( %lld , a + i);       FUL[i] = 0;       for (int j = i; j; j--) FUL[j] = (FUL[j] * a[i] - FUL[j - 1] + MOD) % MOD;       FUL[0] = FUL[0] * a[i] % MOD;     }     inv[1] = 1;     for (int i = 2; i <= N; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;     for (int i = 1; i <= N; i++) {       static long long pol[5000];       pol[N - 1] = (MOD - FUL[N]) % MOD;       for (int j = N - 2; ~j; j--)         pol[j] = (pol[j + 1] * a[i] - FUL[j + 1] + MOD) % MOD;       long long TPW = 1;       for (int a = 0; a < N && a < K; a++) {         TPW = TPW * inv[N] % MOD * (K - a) % MOD;         O = (O + pol[a] % MOD * inv[a + 1] % MOD * TPW) % MOD;       }     }     printf( %lld n , O);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ld = long double;   template <class T>   inline T gcd(T a, T b) {     return !a ? b : gcd(b % a, a);   }   template <class T>   inline T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   mt19937 rnd(time(0));   const int INF = 1e9;   const long long LLINF = 1e15;   void solve() {     int n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     int ans = 0;     vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] = max(0, max(dp[i - 1][j], dp[i][j - 1]) - 1);         if (a[i - 1] == b[j - 1]) {           dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);         }         ans = max(ans, dp[i][j]);       }     }     cout << ans <<   n ;     return;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t = 1;     while (t-- > 0) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void solve() {     long long int l, r;     cin >> l >> r;     long long int mposs = (r - 1) >> 1;     if (r - mposs >= l)       cout << mposs <<   n ;     else       cout << r % l <<   n ;   }   signed main() {     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int ans, sum, pro;   string s, str;   long long int solve(int st, int end, string z) {     long long int sum2 = 0, pro2 = 1;     for (int i = st; i <= end; i++) {       if (z[i] ==  + ) {         sum2 += pro2;         pro2 = 1;       } else if (i % 2 == 0)         pro2 *= s[i] -  0 ;     }     return sum2 + pro2;   }   int main() {     cin >> s;     str =  1* ;     str += s;     str +=  *1 ;     s = str;     for (int i = 1; i < s.size(); i += 2) {       if (s[i] ==  + ) continue;       for (int j = i + 2; j < s.size(); j += 2) {         if (s[j] ==  * ) {           sum = 0, pro = 1;           for (int k = 0; k < s.size(); k++) {             if (k == i)               pro *= solve(i + 1, j - 1, s);             else if (k >= i && k <= j)               continue;             else if (s[k] ==  + ) {               sum += pro;               pro = 1;             } else if (k % 2 == 0)               pro *= s[k] -  0 ;           }           sum += pro;           ans = max(ans, sum);         }       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool bad[105];   string A[105];   bool check(string a, string b) {     if ((int)a.size() != (int)b.size()) return false;     for (int i = 0; i < (int)a.size(); i++)       if (tolower(a[i]) != tolower(b[i])) return false;     return true;   }   int main() {     int n, i, j, k;     char c, c2;     string s;     cin >> n;     for (i = 0; i < n; i++) cin >> A[i];     cin >> s >> c;     for (i = 0; i < n; i++) {       for (j = 0; j < (int)s.size(); j++)         if (check(s.substr(j, (int)A[i].size()), A[i]))           for (k = j; k < j + (int)A[i].size(); k++) bad[k] = true;     }     for (i = 0; i < (int)s.size(); i++)       if (bad[i]) {         if (isupper(s[i]))           c2 = toupper(c);         else           c2 = tolower(c);         if (s[i] == c2) {           if (isupper(s[i])) {             for (c2 =  A ; c2 <=  Z ; c2++)               if (c2 != s[i]) {                 s[i] = c2;                 break;               }           } else {             for (c2 =  a ; c2 <=  z ; c2++)               if (c2 != s[i]) {                 s[i] = c2;                 break;               }           }         } else           s[i] = c2;       }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using std ::vector;   template <typename T>   T max(T x, T y) {     return (x > y) ? x : y;   }   template <typename T>   T min(T x, T y) {     return (x < y) ? x : y;   }   template <typename T>   bool chkmax(T &x, T y) {     return (x >= y) ? 0 : (x = y, 1);   }   template <typename T>   bool chkmin(T &x, T y) {     return (x <= y) ? 0 : (x = y, 1);   }   template <typename T>   T read(T &in) {     in = 0;     char ch;     T f = 1;     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) in = in * 10 + ch -  0 , ch = getchar();     return in *= f;   }   static const int max1 = 100000 + 11;   static const int BIT = 16;   bool vis[max1];   vector<int> fac[max1];   struct Node {     Node *ch[2];     int v;     Node() { ch[0] = ch[1] = NULL, v = 100001; }   };   struct Trie {     Node *root;     Trie() { root = new Node; }     void Insert(int x) {       Node *o = root;       chkmin(o->v, x);       for (int i = (BIT), ir = (0); i >= (ir); --i) {         int c = x >> i & 1;         if (!o->ch[c]) o->ch[c] = new Node;         o = o->ch[c];         chkmin(o->v, x);       }     }   } T[max1];   void Init(int n = 100000) {     for (int i = 1; i <= n; ++i)       for (int j = i; j <= n; j += i) fac[j].push_back(i);   }   void Modify(int x) {     if (vis[x]) return;     vis[x] = 1;     for (vector<int>::iterator i = fac[x].begin(); i != fac[x].end(); ++i)       T[*i].Insert(x);   }   int Query(int x, int k, int s) {     if (x % k) return -1;     s -= x;     int c = 0;     Node *o = T[k].root;     if (o->v > s) return -1;     for (int i = (BIT), ir = (0); i >= (ir); --i) {       int w = x >> i & 1;       if (s < (1 << i) || o->ch[1] && o->ch[1]->v > s)         o = o->ch[0];       else if (!o->ch[0])         o = o->ch[1], c += 1 << i;       else if (!o->ch[1])         o = o->ch[0];       else if (w)         o = o->ch[0];       else         o = o->ch[1], c += 1 << i;     }     return c;   }   int main() {     int q;     read(q);     Init();     while (q--) {       int o, x, k, s;       read(o), read(x);       if (o == 1) {         Modify(x);       } else {         read(k), read(s);         printf( %d n , Query(x, k, s));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans, n, a[10005], cnt, f, i, j, vis[10005];   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     ans = 0;     f = 0;     cnt = 0;     memset(vis, 0, sizeof vis);     for (i = 0; i < n; i++) {       if (!f) {         for (j = 0; j < n; j++) {           if (cnt >= a[j] && !vis[j]) {             vis[j] = 1;             cnt++;           }         }       } else {         for (j = n - 1; j >= 0; j--) {           if (cnt >= a[j] && !vis[j]) {             vis[j] = 1;             cnt++;           }         }       }       if (cnt == n) {         break;       } else {         ans++;       }       f = 1 - f;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], ans = 0, maxi = 0;     for (int i = 0; i < 7; i++) {       cin >> a[i];       maxi += a[i];     }     int t;     if (maxi >= n)       t = 1;     else if (n % maxi == 0) {       t = n / maxi;     } else {       t = n / maxi + 1;     }     while (t--) {       for (int i = 0; i < 7; i++) {         n -= a[i];         if (n <= 0) {           ans = i + 1;           break;         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   int b[500][100005], c[500];   int main() {     srand(time(0));     int n, m, i, j, k;     scanf( %d %d , &n, &m);     map<int, vector<int> > a;     for (i = 0; i < n; i++) {       scanf( %d , &k);       if (k <= n) a[k].push_back(i + 1);     }     vector<int> v;     map<int, vector<int> >::iterator it;     for (it = a.begin(); it != a.end(); it++)       if (it->first > it->second.size()) v.push_back(it->first);     for (i = 0; i < v.size(); i++) a.erase(v[i]);     k = 0;     for (it = a.begin(); it != a.end(); it++) {       c[k] = it->first;       for (i = 0; i < it->second.size(); i++) b[k][it->second[i]] = 1;       for (i = 1; i <= n; i++) b[k][i] += b[k][i - 1];       k++;     }     while (m--) {       scanf( %d %d , &i, &j);       int cnt = 0;       for (n = 0; n < k; n++)         if (c[n] == b[n][j] - b[n][i - 1]) cnt++;       printf( %d n , cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int num[26];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       string s, t;       cin >> n >> s >> t;       int rev = 0, flg = 0;       memset(num, 0, sizeof(num));       for (int i = 0; i < n; i++) {         for (int j = s[i] -  a  + 1; j < 26; j++) {           rev += num[j];         }         num[s[i] -  a ]++;       }       for (int i = 0; i < 26; i++) {         if (num[i] >= 2) flg = 1;       }       memset(num, 0, sizeof(num));       for (int i = 0; i < n; i++) {         for (int j = t[i] -  a  + 1; j < 26; j++) {           rev += num[j];         }         num[t[i] -  a ]++;       }       for (int i = 0; i < 26; i++) {         if (num[i] >= 2) flg = 1;       }       sort(s.begin(), s.end());       sort(t.begin(), t.end());       if (s != t || (rev % 2 != 0 && !flg))         puts( NO );       else         puts( YES );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dr[] = {-1, 1, 0, 0, -1, 1, -1, 1};   long long dc[] = {0, 0, -1, 1, -1, -1, 1, 1};   int main() {     long long T;     cin >> T;     while (T--) {       string a, b;       cin >> a >> b;       if (a < b) {         cout << a <<   n ;         continue;       }       bool f = 0;       long long sz = min(a.size(), b.size());       long long loop = 0;       for (long long i = 0; i < sz; i++) {         if (a[i] < b[i]) {           f = 1;           break;         } else {           long long indx = -1;           char mn = b[i];           for (long long j = i + 1; j < a.size(); j++) {             if (a[j] <= mn) {               mn = a[j];               indx = j;             }           }           if (indx == -1 and a[i] > b[i]) {             break;           } else if (indx == -1 and a[i] == b[i]) {             continue;           }           if (a[i] == a[indx]) continue;           swap(a[i], a[indx]);           loop++;           if (a < b) {             f = 1;           }           break;         }       }       if (f == 1) {         cout << a <<   n ;       } else {         cout <<  ---               <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> p1[1005];   pair<long long, long long> p2[1005];   vector<long long> v;   int main() {     long long i, j, n, x, y, a, b;     cin >> n;     for (i = 0; i < n; i++) cin >> p1[i].first >> p1[i].second;     for (i = 0; i < n; i++) cin >> p2[i].first >> p2[i].second;     sort(p1, p1 + n);     sort(p2, p2 + n);     cout << p1[0].first + p2[n - 1].first <<              << p1[0].second + p2[n - 1].second;   }
#include <bits/stdc++.h>   using namespace std;   long long inf = 2147483647;   const long long ll = 9223372036854775807, ninf = 1000000000;   const double eps = 1e-6;   const long long nll = 1000000000000000000;   vector<int> node[200005];   vector<int> num;   int deg[200005] = {};   void dfs(int x) {     for (int i = 0; i < node[x].size(); i++) {       dfs(node[x][i]);     }     num.push_back(x);   }   int A[200005] = {};   int main() {     int a;     while (cin >> a) {       int r = 1;       for (int i = 1; i <= a; i++) {         cin >> A[i];         deg[A[i]]++;         if (A[i]) {           deg[i]++;           node[A[i]].push_back(i);         } else {           r = i;         }       }       if (a % 2 == 0) {         cout <<  NO  <<   n ;         continue;       }       dfs(r);       vector<int> ans1, ans2;       cout <<  YES  <<   n ;       for (int i = 0; i < num.size(); i++) {         int now = num[i];         if (deg[now] % 2 == 0) {           ans2.push_back(now);           deg[A[now]]--;         } else {           ans1.push_back(now);         }       }       for (int i = 0; i < ans2.size(); i++) {         cout << ans2[i] <<   n ;       }       reverse(ans1.begin(), ans1.end());       for (int i = 0; i < ans1.size(); i++) {         cout << ans1[i] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int fa[2][maxn << 1];   int cost[2][maxn][maxn];   int dd[2][maxn];   int n;   int sz[2];   int dp[maxn];   void init(int t) {     cin >> sz[t];     for (int i = (2); i <= (sz[t]); ++i) cin >> fa[t][i];     for (int i = (1); i <= (n); ++i) cin >> dd[t][i];   }   void cal(int t) {     for (int l = (1); l <= (n); ++l) {       vector<int> sons(sz[t] + 1, 0);       for (int i = (1); i <= (sz[t]); ++i) sons[fa[t][i]]++;       for (int r = (l); r <= (n); ++r) {         int now = dd[t][r];         int val = 0;         while (now != 1 && sons[now] == 0)           val++, sons[fa[t][now]]--, now = fa[t][now];         cost[t][l][r] = cost[t][l][r - 1] + val;       }     }   }   void solve() {     for (int i = (1); i <= (n); ++i) {       int& ans = dp[i];       for (int j = (0); j < (i); ++j)         ans = max(ans, dp[j] + max(cost[1][j + 1][i], cost[0][j + 1][i]));     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = (0); i < (2); ++i) init(i);     for (int i = (0); i < (2); ++i) cal(i);     solve();     cout << dp[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T SQR(T x) {     return x * x;   }   template <class T>   inline string TOSTR(const T &x) {     stringstream ss;     ss << x;     return ss.str();   }   template <class T>   void UPDATE_MIN(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UPDATE_MAX(T &x, T y) {     if (x < y) {       x = y;     }   }   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   long long powmod(long long a, long long p, long long m) {     long long r = 1;     while (p) {       if (p & 1) r = r * a % m;       p >>= 1;       a = a * a % m;     }     return r;   }   const int MOD = 1000 * 1000 * 1000 + 7;   const double PI = 3.1415926535897932384626433832795l;   long long n, m, k;   long long p10[10000];   long long p9_10[10000];   long long counts_a[100] = {};   long long counts_b[100] = {};   long long *counts, *counts2;   int main() {     cin >> n >> k >> m;     long long a10 = 1, a9_10 = 1;     for (int(i) = 0; (i) < (int)(n); (i)++) {       p10[i] = a10;       p9_10[i] = a9_10;       a10 = (a10 * 10LL) % k;       a9_10 = (a9_10 * ((i == 0) ? 9LL : 10LL)) % m;     }     counts = counts_a;     counts2 = counts_b;     counts[0] = 1;     long long res = 0;     for (int(i) = 0; (i) < (int)(n); (i)++) {       for (int(j) = 0; (j) < (int)(k); (j)++) counts2[j] = 0;       for (int(r) = 0; (r) < (int)(k); (r)++) {         int mind = ((i == n) ? 1 : 0);         for (int(d) = mind; (d) < (int)(10); (d)++) {           long long r2 = (d * p10[i] + r) % k;           counts2[r2] = (counts2[r2] + counts[r]) % m;         }       }       res += (counts2[0] - 1) * p9_10[n - i - 1];       res %= m;       while (res < 0) res += m;       counts2[0] = 1;       {         __typeof(counts) tmp = counts;         counts = counts2;         counts2 = tmp;       };     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<char, long long int> cou;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     while (n--) {       string s;       cin >> s;       cou[s[0]]++;     }     long long int ans = 0;     for (map<char, long long int>::iterator it = cou.begin(); it != cou.end();          it++) {       long long int req = it->second;       long long int f = (req + 1) / 2;       long long int s = req / 2;       ans = ans + (f * (f - 1)) / 2 + (s * (s - 1)) / 2;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mark[1 << 22];   int is[1 << 22];   int a[1 << 22];   int n, m;   int tot;   void dfs(int x) {     if (mark[x]) return;     mark[x] = 1;     if (is[x]) dfs(tot ^ x);     for (int j = 0; j < n; j++) {       if (x >> j & 1) {         dfs(x ^ (1 << j));       }     }   }   signed main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &a[i]);       is[a[i]] = 1;     }     tot = (1 << n) - 1;     int ans = 0;     for (int i = 1; i <= m; i++) {       if (mark[a[i]]) continue;       mark[a[i]] = 1;       ans++;       dfs(tot ^ a[i]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 7;   const long long INF = 1e17 + 7;   long long h[N], t[N], f[N][2], pos[N], w[N];   long long n, num = 0;   struct edge {     long long v, next;   } e[N * 2];   struct pir {     long long a, b;   } p[N];   bool cmp(pir x, pir y) { return (x.b - x.a) < (y.b - y.a); }   void add(long long x, long long y) {     e[num] = (edge){y, pos[x]};     pos[x] = num++;   }   void dfs(long long x, long long fa) {     long long cnt = 0, s1 = 0, s0 = 0, hh = 0, ss = 0;     for (long long i = pos[x]; ~i; i = e[i].next) {       if (e[i].v == fa) continue;       hh = 1;       dfs(e[i].v, x);       if (h[e[i].v] > h[x]) s1++, ss += f[e[i].v][1];       if (h[e[i].v] < h[x]) s0++, ss += f[e[i].v][0];     }     if (!hh) {       f[x][0] = f[x][1] = t[x];       return;     }     w[0] = 0;     for (long long i = pos[x]; ~i; i = e[i].next) {       if (e[i].v != fa && h[e[i].v] == h[x]) {         w[0] += f[e[i].v][0];         p[++cnt] = (pir){f[e[i].v][0], f[e[i].v][1]};       }     }     sort(p + 1, p + cnt + 1, cmp);     for (long long i = 1; i <= cnt; i++) w[i] = w[i - 1] + p[i].b - p[i].a;     f[x][0] = f[x][1] = INF;     for (long long i = 0; i <= cnt + 1 - 1; i++) {       f[x][0] =           min(f[x][0], w[i] + max(cnt - i + s0, i + s1 + (x != 1)) * t[x] + ss);       f[x][1] =           min(f[x][1], w[i] + max(cnt - i + s0 + (x != 1), i + s1) * t[x] + ss);     }   }   int main() {     scanf( %I64d , &n);     memset(pos, -1, sizeof(pos));     for (long long i = 1; i <= n; i++) scanf( %I64d , &t[i]);     for (long long i = 1; i <= n; i++) scanf( %I64d , &h[i]);     for (long long i = 1; i <= n - 1; i++) {       long long x, y;       scanf( %I64d%I64d , &x, &y);       add(x, y);       add(y, x);     }     dfs(1, 0);     printf( %I64d n , f[1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0;     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<int> ans;     int n;     int m;     cin >> n >> m;     int a[110];     int b[20];     memset(a, 0, sizeof a);     memset(b, 0, sizeof b);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       int t;       cin >> t;       b[t] = 1;     }     for (int i = 0; i < n; i++) {       if (b[a[i]] == 1) ans.push_back(a[i]);     }     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string t(int a) {     int i, tmp = 1;     for (i = 1; i <= a; i *= 3) {     }     string s;     for (; i >= 1; i /= 3) {       if (a / i == 2)         s +=  2 , a %= i;       else if (a / i == 1)         s +=  1 , a %= i;       else         s +=  0 ;     }     return s;   }   int main() {     int i, a, b = 0, c;     cin >> a >> c;     string s1, s2, s3;     s1 = t(a), s2 = t(c);     int t = max(((int)s1.size()), ((int)s2.size()));     for (i = 0; i < t; i++) {       if (((int)s1.size()) - t + i >= 0)         a = s1[((int)s1.size()) - t + i] -  0 ;       else         a = 0;       if (((int)s2.size()) - t + i >= 0)         c = s2[((int)s2.size()) - t + i] -  0 ;       else         c = 0;       s3 += ((c - a + 3) % 3 +  0 );     }     reverse(s3.begin(), s3.end());     for (i = 0; i < ((int)s3.size()); i++) {       t = 1;       for (int j = 0; j < i; j++) t *= 3;       b += (s3[i] -  0 ) * t;     }     cout << b << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, vet[202020], cap[202020];   set<long long> s;   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) scanf( %lld , &cap[i]), s.insert(i);     scanf( %lld , &m);     long long op, x, p, k;     while (m--) {       scanf( %lld , &op);       if (op == 1) {         scanf( %lld %lld , &p, &x);         for (auto it = s.lower_bound(p); it != s.end() && x; it = s.erase(it)) {           long long id = *it;           if (cap[id] - vet[id] > x) {             vet[id] += x;             break;           }           x -= cap[id] - vet[id];           vet[id] = cap[id];         }       } else {         scanf( %lld , &k);         printf( %lld n , vet[k]);       }     }   }