malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 7 + 1e9;   const int inf = 1e9 + 5;   const long long INF = (long long)1e18 + 5;   const int N = 100 + 5;   int a[N];   int fr[10000];   int main() {     int n;     string s;     getline(cin, s);     sscanf(s.c_str(),  %d , &n);     for (int i = 0; i < (int)(n); i++) {       getline(cin, s);       int h = 0, m = 0;       char c;       sscanf(s.c_str(),  [%d:%d %c.m.]: , &h, &m, &c);       a[i] = h * 60 + m;       if (h == 12 && c ==  a ) a[i] = m;       if (c ==  p ) {         if (h != 12) a[i] += (12 * 60);       }     }     int ans = 1;     fr[a[0]] = 1;     for (int i = 1; i < n; ++i) {       if (a[i] == a[i - 1]) {         fr[a[i]]++;         if (fr[a[i]] > 10) {           ans++;           fr[a[i]] = 1;         }       } else {         fr[a[i - 1]] = 0;         fr[a[i]] = 1;       }       if (a[i] < a[i - 1] || (a[i] < 60 && a[i - 1] >= 60)) {         ans++;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool near(long long A, long long B, long long X, long long Y, long long T) {     if ((X - Y * T) < 0) return (0);     if ((A - B * T) * Y != (X - Y * T) * B)       return ((A - B * T) * Y > (X - Y * T) * B);     return (B < Y);   }   int main() {     int t1, t2, x1, x2, t0;     scanf( %d %d %d %d %d , &t1, &t2, &x1, &x2, &t0);     if (t1 == t0 || t2 == t0) {       int a1 = x1 * (t1 == t0);       int a2 = x2 * (t2 == t0);       printf( %d %d n , a1, a2);       return (0);     }     int dmin = t2 - t0;     int ret1 = 0, ret2 = x2;     for (int i = 1; i <= x1; i++) {       long long y = ((long long)(t0 - t1) * i) / (t2 - t0);       int y2 = min(y, (long long)x2);       for (int j = max(0, y2 - 1); j <= min(x2, y2 + 1); j++) {         if (near((long long)t1 * ret1 + (long long)t2 * ret2, ret1 + ret2,                  (long long)t1 * i + (long long)t2 * j, i + j, t0)) {           ret1 = i;           ret2 = j;         }       }     }     printf( %d %d n , ret1, ret2);     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     double p;     cin >> n >> p >> t;     vector<vector<double> > dp(2010, vector<double>(2010, 0));     vector<vector<double> > now(2010, vector<double>(2010, 0));     dp[0][0] = 1;     for (int i = 0; i < t; i++) {       for (int j = 0; j < n + 1; j++) {         if (j == n) {           dp[i + 1][j] += dp[i][j];           continue;         }         dp[i + 1][j + 1] += dp[i][j] * p;         dp[i + 1][j] += dp[i][j] * (1 - p);       }     }     double fa = 0;     for (int i = 0; i < n + 1; i++) fa += dp[t][i] * i;     cout << setprecision(20) << fa;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     long long amt = 0;     cin >> n;     vector<pair<int, int> > a;     vector<int> p(n);     vector<long long> count(6, 0);     for (int i(0); i < (n); i++) {       cin >> p[i];     }     for (int i(0); i < (5); i++) {       cin >> x;       a.push_back(make_pair(x, i + 1));     }     sort((a).begin(), (a).end());     for (int i(0); i < (n); i++) {       amt += p[i];       for (int j(4); j >= (0); j--) {         if (a[j].first <= amt) {           count[a[j].second] += amt / a[j].first;           amt -= a[j].first * (amt / a[j].first);         }       }     }     for (int i(1); i < (6); i++) {       cout << count[i] <<    ;     }     cout <<   n  << amt;     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-15;   const int N = 10000 + 10;   struct node {     double x, y, z;     node() {}     node(double _x, double _y, double _z) {       x = _x;       y = _y;       z = _z;     }   };   node a[N], st;   int n;   double Time[N], len[N], v1, v2;   double sqr(double x) { return x * x; }   bool eq(double x, double y) { return fabs(x - y) <= eps; }   double D(node i, node j) {     return sqrt(sqr(i.x - j.x) + sqr(i.y - j.y) + sqr(i.z - j.z));   }   int main() {     scanf( %d , &n);     for (int i = 0; i <= n; ++i) scanf( %lf%lf%lf , &a[i].x, &a[i].y, &a[i].z);     scanf( %lf%lf , &v1, &v2);     scanf( %lf%lf%lf , &st.x, &st.y, &st.z);     if (eq(st.x, a[0].x) && eq(st.y, a[0].y) && eq(st.z, a[0].z)) {       puts( YES );       puts( 0 );       printf( %.10f %.10f %.10f n , a[0].x, a[0].y, a[0].z);     } else {       Time[0] = 0;       for (int i = 1; i <= n; ++i) {         len[i] = D(a[i - 1], a[i]);         Time[i] = Time[i - 1] + len[i] / v2 + eps;       }       int idx = -1;       for (int i = 1; i <= n; ++i)         if (D(st, a[i]) <= Time[i] * v1 + eps) {           idx = i;           break;         }       if (idx == -1)         puts( NO );       else {         puts( YES );         double L = len[idx] / v2;         double dx = a[idx - 1].x - a[idx].x, dy = a[idx - 1].y - a[idx].y,                dz = a[idx - 1].z - a[idx].z;         double l = 0, r = len[idx] / v2, mid;         for (int i = 0; i < 100; ++i) {           mid = (l + r) / 2;           if (D(node(a[idx].x + dx * mid / L + eps, a[idx].y + dy * mid / L + eps,                      a[idx].z + dz * mid / L + eps),                 st) <= v1 * (Time[idx] - mid) + eps)             l = mid;           else             r = mid;         }         printf( %.10f n , Time[idx] - l);         printf( %.10f %.10f %.10f n , a[idx].x + dx * l / L + eps,                a[idx].y + dy * l / L + eps, a[idx].z + dz * l / L + eps);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s.size() == 1) {       int a = s[0] - 48;       if (a % 4 == 0)         cout << 4;       else         cout << 0;     } else {       int a = (s[s.size() - 2] - 48) * 10 + (s[s.size() - 1] - 48);       if (a % 4 == 0)         cout << 4;       else         cout << 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 400000 + 10;   struct Point {     long long x, y;     Point operator+(const Point &A) { return (Point){x + A.x, y + A.y}; }     Point operator-(const Point &A) { return (Point){x - A.x, y - A.y}; }   } P[Maxn];   int n, A[Maxn], cnt;   long long sum[Maxn];   double CalCJ(Point A, Point B) { return A.x * B.y - A.y * B.x; }   bool OnLeft(Point P, Point A, Point B) { return CalCJ(B - A, P - A) > 0; }   bool OnRight(Point P, Point A, Point B) { return CalCJ(B - A, P - A) < 0; }   void solve() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (long long)A[i];     long long ans = 0, tot;     for (int i = 1; i <= n; i++) ans += (long long)A[i] * (long long)i;     tot = ans;     P[++cnt] = (Point){1, sum[0]};     for (int i = 2; i <= n; i++) {       Point C = (Point){1ll, (long long)A[i]};       int l = 2, r = cnt + 1;       P[cnt + 1] = (Point){n + 1, (0x3f3f3f3f) * 10ll};       while (l < r) {         int mid = ((l + r) >> 1);         if (!OnRight(C + P[mid - 1], P[mid - 1], P[mid]))           l = mid + 1;         else           r = mid;       }       l--;       long long nans = tot - (long long)A[i] * (long long)i + sum[i - 1] +                        P[l].x * (long long)A[i] - P[l].y;       ans = ((ans) > (nans) ? (ans) : (nans));       Point Q = (Point){(long long)i, sum[i - 1]};       while (cnt > 1 && !OnLeft(Q, P[cnt - 1], P[cnt])) cnt--;       P[++cnt] = Q;     }     P[cnt = 1] = (Point){n, sum[n]};     for (int i = n - 1; i; i--) {       Point C = (Point){1ll, (long long)A[i]};       int l = 2, r = cnt + 1;       P[cnt + 1] = (Point){0, (-0x3f3f3f3f) * 10ll};       while (l < r) {         int mid = ((l + r) >> 1);         if (!OnLeft(P[mid - 1] - C, P[mid - 1], P[mid]))           l = mid + 1;         else           r = mid;       }       l--;       long long nans = tot + sum[i] - (long long)A[i] * (long long)i - P[l].y +                        P[l].x * (long long)A[i];       ans = ((ans) > (nans) ? (ans) : (nans));       Point Q = (Point){(long long)i, sum[i]};       while (cnt > 1 && !OnRight(Q, P[cnt - 1], P[cnt])) cnt--;       P[++cnt] = Q;     }     printf( %I64d n , ans);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 6;   const int inf = 0x3f3f3f3f;   long long a[M], sum[M];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, p, k;       scanf( %d%d%d , &n, &p, &k);       for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);       sort(a + 1, a + 1 + n);       for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];       int ans = 0;       for (int i = 0; i < k; i++) {         long long now = sum[i];         int num = i;         if (now > p) {           num--;           ans = max(ans, num);           break;         }         for (int j = i + k; j <= n; j += k) {           now += a[j];           num += k;           if (now > p) {             num -= k;             break;           }         }         ans = max(ans, num);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using vi = vector<int>;   using vll = vector<ll>;   const string ALPHA =  abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ;   string NAME[3] = { Kuro ,  Shiro ,  Katie };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(20);     ll N;     while (cin >> N) {       vector<string> S(3);       vll ma(3);       for (int(a) = (0); (a) < (int)(3); ++(a)) {         cin >> S[a];         for (char b : ALPHA) {           ll x = 0;           for (auto &(c) : (S[a])) {             if (b == c) x++;           }           if (N > (int)(S[a]).size() - x) {             ll p = N - (int)(S[a]).size() + x;             if (p == 1 && x == (int)(S[a]).size())               (ma[a]) = max((ma[a]), ((int)(S[a]).size() - p));             else               (ma[a]) = max((ma[a]), ((ll)(int)(S[a]).size()));           } else {             (ma[a]) = max((ma[a]), (N + x));           }         }       }       ll m = -1, cnt = 0, cat = -1;       for (int(a) = (0); (a) < (int)(3); ++(a)) {         if (m < ma[a]) {           cat = a;           m = ma[a];         }       }       for (int(a) = (0); (a) < (int)(3); ++(a))         if (m == ma[a]) cnt++;       if (cnt > 1)         cout <<  Draw  << endl;       else         cout << NAME[cat] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, sum = 0;     vector<long long> A;     int n;     cin >> n;     A.resize(n);     for (int i = 0; i < n; i++) {       cin >> a;       sum += a;       A[i] = sum;     }     b = sum / 2 + (sum % 2);     a = 0;     while (A[a] < b) a++;     cout << a + 1;   }
#include <bits/stdc++.h>   int main() {     int n, c = 0, i, s = 0, j, k = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       for (j = 1; j <= i; j++) {         s = s + j;         if (s > n) {           k = 1;           break;         }       }       c = c + 1;       if (k == 1) {         c--;         break;       }     }     printf( %d , c);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int awsl[maxn];   int main() {     int n;     scanf( %d , &n);     string s;     cin >> s;     vector<int> sum(n);     vector<int> m(n);     for (int i = 0; i < n; ++i) {       if (s[i] ==  ( )         awsl[i] = 1;       else         awsl[i] = -1;     }     sum[0] = awsl[0];     for (int i = 1; i < n; ++i) {       sum[i] = sum[i - 1] + awsl[i];     }     m.back() = sum.back();     for (int i = n - 2; i >= 0; i--) {       m[i] = min(sum[i], m[i + 1]);     }     int cnt = 0;     for (int i = 0; i < n; ++i) {       int v = 2 * awsl[i];       if (m[i] - v >= 0 && sum.back() - v == 0) cnt++;       if (sum[i] < 0) break;     }     cout << cnt <<   n ;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int d[100005];   int pr[100005];   int cnt[100005];   int a[100005];   vector<int> g[100005];   int b[100005];   int main() {     int n, i, j;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ++cnt[a[i]];     }     for (i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       d[a[i]] += x;       g[a[i]].push_back(x);     }     for (i = 100000; i > 0; --i) {       pr[i] = pr[i + 1] + d[i];     }     int tot = 0;     int ans = 1000000000;     for (i = 1; i <= 100000; ++i) {       if (cnt[i] == 0) continue;       int cost = pr[i + 1];       int need = tot + cnt[i] - (cnt[i] * 2 - 1);       for (j = 1; j <= 200; ++j) {         if (need <= 0) break;         if (need - b[j] >= 0) {           need -= b[j];           cost += j * b[j];         } else {           cost += need * j;           need = 0;           break;         }       }       if (cost < ans) {         ans = cost;       }       for (j = 0; j < g[i].size(); ++j) {         ++b[g[i][j]];       }       tot += cnt[i];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int n, m, cnt, a[300002];   int32_t main() {     ios_base ::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++)       if (a[i] <= a[i + 1]) cnt++;     if (cnt == n - 1) return cout << 0, 0;     int l = 0, r = m;     while (r - l > 1) {       int cur = 0, mid = (l + r) / 2;       bool ctrl = true;       for (int i = 1; i <= n && ctrl; i++) {         int mn = m, mx = 0;         if (a[i] + mid >= m)           mn = 0;         else           mn = a[i];         if (a[i] + mid >= m - 1)           mx = m - 1;         else           mx = a[i] + mid;         if (mx < cur) {           ctrl = false;         } else if (a[i] > cur && mn == 0 && ((a[i] + mid) % m) < cur)           cur = a[i];         else if (a[i] > cur && mn != 0)           cur = a[i];       }       if (ctrl)         r = mid;       else         l = mid;     }     cout << r;   }
#include <bits/stdc++.h>   using namespace std;   long long inf = 1e18 + 42;   const double eps = 1e-8;   const int M = 1e9 + 7;   const int MN = 1e9;   int main() {     vector<int> In;     for (int i = 1; i <= 4; i++) {       cout <<  ?   << i <<     << i + 1 << endl;       int x;       cin >> x;       In.push_back(x);     }     vector<int> v = {4, 8, 15, 16, 23, 42};     do {       vector<int> res;       for (int i = 1; i <= 4; i++) {         res.push_back(v[i - 1] * v[i]);       }       if (res == In) {         cout <<  !  ;         for (int x : v) cout << x <<    ;         cout << endl;         return 0;       }     } while (next_permutation(v.begin(), v.end()));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) {       long long n, i, j;       string s, a, b;       cin >> n >> s;       a = b =   ;       bool flag = true;       ;       a +=  1 , b +=  1 ;       for (i = 1; i < n; i++) {         if (s[i] ==  0 ) {           a +=  0 , b +=  0 ;         } else if (s[i] ==  1 ) {           if (flag) {             a +=  1 ;             b +=  0 ;             flag = false;           } else {             a +=  0 ;             b +=  1 ;           }         } else if (s[i] ==  2 ) {           if (flag) {             a +=  1 , b +=  1 ;           } else {             a +=  0 , b +=  2 ;           }         }       }       cout << a <<   n  << b <<   n ;     }     return 0;   }
#include<bits/stdc++.h>   #define rep(i,a,b) for(long long i=a;i<b;i++)   #define pb push_back   #define f first   #define s second   #define is insert   #define vector_int vector<int>   #define ll long long   #define pqi priority_queue<int>   #define all(x) x.begin(),x.end()   #define mem(x,y) memset(x,y,sizeof(x))   #define sz(x) (int)x.size()   #define pii pair<int,int>   #define pll pair<ll,ll>   #define INF 1e9   #define INFL 1e18   #define mod 1000000007   #define fast ios::sync_with_stdio(false);cin.tie(0);   using namespace std;      int equalPartition(int n, vector<int> arr)       {           int sum = 0;       int i, j;           // Calculate sum of all elements       for (i = 0; i < n; i++)           sum += arr[i];           if (sum % 2 != 0)           return false;           bool part[sum / 2 + 1][n + 1];           // initialize top row as true       for (i = 0; i <= n; i++)           part[0][i] = true;           // initialize leftmost column,       // except part[0][0], as 0       for (i = 1; i <= sum / 2; i++)           part[i][0] = false;           // Fill the partition table in bottom up manner       for (i = 1; i <= sum / 2; i++) {           for (j = 1; j <= n; j++) {               part[i][j] = part[i][j - 1];               if (i >= arr[j - 1])                   part[i][j] = part[i][j]                                || part[i - arr[j - 1]][j - 1];           }       }           /* // uncomment this part to print table       for (i = 0; i <= sum/2; i++)       {       for (j = 0; j <= n; j++)           cout<<part[i][j];       cout<<endl;       } */           return part[sum / 2][n];       }      void solve(){       ll n=0;cin>>n;       vector<int> arr;       for(int i=0;i<n;i++) {           int x;           cin>>x;           arr.pb(x);       }       if(equalPartition( n,arr)==0) cout<<0<<endl;       else {           for(int i=0;i<n;i++){               int x=arr[i];               arr[i]=0;               if(equalPartition(n,arr)==0) {                   cout<<1<<endl<<i+1<<endl;                   break;               }               else{                   arr[i]=x;               }           }       }   }       int main() {                  solve();              return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int arr[2 * n], maxi[2 * n], c = 1;       vector<long long int> v;       for (int i = 0; i < 2 * n; i++) {         cin >> arr[i];         if (!i)           maxi[i] = arr[i];         else           maxi[i] = max(maxi[i - 1], arr[i]);       }       for (int i = 1; i < 2 * n; i++) {         if (maxi[i] != maxi[i - 1])           v.push_back(c), c = 1;         else           c++;       }       v.push_back(c);       long long int dp[v.size()][n + 1];       for (int i = 0; i < v.size(); i++) {         for (int j = 0; j <= n; j++) dp[i][j] = 0;       }       dp[0][v[0]] = 1;       for (int i = 1; i < v.size(); i++) {         for (int j = 0; j <= n; j++) dp[i][j] = dp[i - 1][j];         for (int j = v[i]; j <= n; j++) {           if (dp[i - 1][j - v[i]]) dp[i][j] = 1;         }       }       if (dp[v.size() - 1][n])         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct proc {     string name;     string var[10];   };   struct vari {     string name;     string x;   };   string s, t, name, varr[10];   proc a[1005];   vari b[1005];   int res, n, m, k, para[1005], p;   bool check;   int main() {     if (0) {       freopen( a.inp ,  r , stdin);     };     scanf( %d n , &n);     size_t found;     for (int i = 0; i < n; i++) {       getline(cin, s);       found = s.find( void );       s.erase(0, int(found) + 4);       while (s[0] ==    ) s.erase(0, 1);       for (int j = 0; j < s.length(); j++) {         if (s[j] ==     || s[j] ==  ( ) break;         a[i].name += s[j];       }       t =   ;       found = s.find( ( );       for (int j = int(found) + 1; s[j] !=  ) ; j++) {         if (s[j] ==  ,  || s[j] ==    ) continue;         while (s[j] !=  ,  && s[j] !=     && s[j] !=  ) ) t += s[j], j++;         para[i]++;         a[i].var[para[i]] = t;         t =   ;         if (s[j] ==  ) ) break;       }     }     scanf( %d n , &m);     for (int i = 0; i < m; i++) {       getline(cin, s);       int j = 0;       t =   ;       while (s[j] ==    ) j++;       while (s[j] !=    ) t += s[j], j++;       b[i].x = t;       t =   ;       while (s[j] ==    ) j++;       while (j < s.length() && s[j] !=    ) t += s[j], j++;       b[i].name = t;     }     scanf( %d n , &k);     for (int i = 0; i < k; i++) {       getline(cin, s);       int j = 0;       while (s[j] ==    ) j++;       t =   ;       while (s[j] !=     && s[j] !=  ( ) t += s[j], j++;       name = t;       while (s[j] !=  ( ) j++;       j++;       t =   ;       p = 0;       for (; s[j] !=  ) ; j++) {         if (s[j] ==     || s[j] ==  , ) continue;         while (s[j] !=     && s[j] !=  ,  && s[j] !=  ) ) t += s[j], j++;         check = false;         for (int x = 0; x < m; x++)           if (b[x].name == t) {             t = b[x].x;             check = true;             break;           }         if (!check) break;         p++;         varr[p] = t;         t =   ;         if (s[j] ==  ) ) break;       }       if (!check) {         printf( 0 n );         continue;       }       res = 0;       for (int x = 0; x < n; x++) {         if (para[x] != p || a[x].name != name) continue;         check = true;         for (int y = 1; y <= p; y++) {           if (a[x].var[y][0] ==  T ) continue;           if (a[x].var[y][0] != varr[y][0]) {             check = false;             break;           }         }         if (check) res++;       }       printf( %d n , res);     }   }
#include <bits/stdc++.h>   using namespace std;   int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};   const int N = 1e2 + 5, M = (1 << 17) + 5, inf = 1e7;   int a[N], dp[N][M], bit[N], n;   bool ip(int i) {     for (int it = 2; it * it <= i; it++) {       if (i % it == 0) return false;     }     return true;   }   int rec(int idx, int mask) {     int &res = dp[idx][mask];     if (idx == n) return res = 0;     if (~res) return res;     res = inf;     for (long long i = (1); i <= (60); ++i) {       if (bit[i] & mask) continue;       res = min(res, rec(idx + 1, mask | bit[i]) + abs(a[idx] - (int)i));     }     return res;   }   void print(int idx, int mask) {     if (idx == n) return;     for (long long i = (1); i <= (60); ++i) {       if ((bit[i] & mask) == 0 &&           dp[idx][mask] == (dp[idx + 1][mask | bit[i]] + abs(a[idx] - i))) {         cout << i <<    ;         print(idx + 1, mask | bit[i]);         break;       }     }   }   int main() {     memset(dp, -1, sizeof dp);     ;     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     int idx = 0;     for (long long i = (2); i <= (60); ++i) {       if (ip(i)) {         for (int j = i; j <= 60; j += i) {           bit[j] |= (1 << idx);         }         idx++;       }     }     rec(0, 0);     print(0, 0);   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());   long long inf = 1e18, MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int ti = 1;     while (ti--) {       int n;       cin >> n;       vector<long long> in(n + 1), cnt(n + 1, 0);       map<pair<long long, long long>, long long> ma;       for (int i = 1; i <= n; i++) cin >> in[i];       long long ans = accumulate(in.begin(), in.end(), 0ll);       int q;       cin >> q;       while (q--) {         long long s, t, u;         cin >> s >> t >> u;         long long prev = ma[make_pair(s, t)];         if (prev != 0) {           if (cnt[prev] <= in[prev]) ans++;           cnt[prev]--;         }         if (u != 0) {           if (cnt[u] < in[u]) ans--;           cnt[u]++;         }         ma[make_pair(s, t)] = u;         cout << ans << endl;       }     }     return 0;   }