malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   bool mysort(pair<long long, long long> A, pair<long long, long long> B) {     return A.second > B.second;   }   long long moduloMultiplication(long long a, long long b, long long mod) {     long long res = 0;     a %= mod;     while (b) {       if (b & 1) res = (res + a) % mod;       a = (2 * a) % mod;       b >>= 1;     }     return res;   }   void solve() {     long long n, k, i, j;     cin >> n >> k;     if (k == 0) {       if (n % 2 == 0)         cout <<  0 n ;       else         cout <<  1 n ;     } else {       if (k <= n) {         if (n == 1)           cout << n - k <<   n ;         else {           if ((n + k) % 2 == 0) {             cout <<  0 n ;           } else {             cout <<  1 n ;           }         }       } else {         cout << k - n <<   n ;       }     }   }   int32_t main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       auto start = high_resolution_clock::now();       solve();       auto stop = high_resolution_clock::now();       auto duration = duration_cast<seconds>(stop - start);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, a, b, v, nr = 0;     cin >> k >> a >> b >> v;     while (a > 0) {       ++nr;       if (b + 1 >= k) {         b = b + 1 - k;         a = a - k * v;       } else {         a = a - (b + 1) * v;         b = 0;       }     }     cout << nr;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m;   char s[15];   int ans[1005];   bool num[15];   bool dfs(int suml, int sumr, int cot, int pre) {     if (cot == m + 1) return true;     if (cot & 1) {       for (int i = 1; i <= 10; i++)         if (num[i] && i != pre && suml + i > sumr) {           ans[cot] = i;           if (dfs(suml + i, sumr, cot + 1, i)) return true;         }     } else {       for (int i = 1; i <= 10; i++) {         if (num[i] && i != pre && sumr + i > suml) {           ans[cot] = i;           if (dfs(suml, sumr + i, cot + 1, i)) return true;         }       }     }     return false;   }   int main() {     scanf( %s , s + 1);     for (int i = 1; i <= 10; i++)       if (s[i] ==  1 ) num[i] = 1;     scanf( %d , &m);     if (!dfs(0, 0, 1, 0))       printf( NO n );     else {       printf( YES n );       for (int i = 1; i <= m; i++) printf( %d  , ans[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   inline int qpow(int a, int p) {     int ans = 1;     while (p) {       if (p & 1) ans = (long long)ans * a % MOD;       a = (long long)a * a % MOD;       p >>= 1;     }     return ans;   }   inline int add(const int& x, const int& y) {     return x + y >= MOD ? x + y - MOD : x + y;   }   inline int dec(const int& x, const int& y) {     return x < y ? x - y + MOD : x - y;   }   int rt[2][24], r[262144], l, lim;   inline void init() {     lim = 1 << l;     for (int i = 0; i < lim; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));   }   inline void NTT(int* a, int type) {     for (int i = 0; i < lim; i++)       if (i < r[i]) swap(a[i], a[r[i]]);     for (int L = 0; L < l; L++) {       int mid = 1 << L, len = mid << 1;       long long Wn = rt[type][L + 1];       for (int s = 0; s < lim; s += len)         for (int k = 0, w = 1; k < mid; k++, w = w * Wn % MOD) {           int x = a[s + k], y = (long long)w * a[s + mid + k] % MOD;           a[s + k] = add(x, y), a[s + mid + k] = dec(x, y);         }     }     if (type) {       int t = qpow(lim, MOD - 2);       for (int i = 0; i < lim; i++) a[i] = (long long)a[i] * t % MOD;     }   }   int fac[262144], finv[262144];   int f[262144], g[262144], t[262144];   void solve(int n) {     if (n == 0) return (void)(f[0] = 1);     int m = n >> 1;     solve(m);     for (l = 0; (1 << l) <= (m << 1); l++)       ;     init();     for (int i = 0; i <= m; i++)       t[i] = f[i], f[i] = (long long)f[i] * fac[i] % MOD;     g[m] = 1;     for (int i = m - 1; i >= 0; i--) g[i] = (long long)g[i + 1] * m % MOD;     for (int i = 0; i <= m; i++) g[i] = (long long)g[i] * finv[m - i] % MOD;     for (int i = m + 1; i < lim; i++) g[i] = 0;     NTT(f, 0), NTT(g, 0);     for (int i = 0; i < lim; i++) g[i] = (long long)f[i] * g[i] % MOD;     NTT(g, 1);     for (int i = 0; i <= m; i++) g[i] = (long long)g[i + m] * finv[i] % MOD;     for (int i = m + 1; i < lim; i++) g[i] = 0;     for (int i = 0; i <= m; i++) f[i] = t[i];     for (int i = m + 1; i < lim; i++) f[i] = 0;     NTT(f, 0), NTT(g, 0);     for (int i = 0; i < lim; i++) f[i] = (long long)f[i] * g[i] % MOD;     NTT(f, 1);     if (n & 1) {       for (int i = n; i >= 1; i--) f[i] = ((n - 1ll) * f[i] + f[i - 1]) % MOD;       f[0] = (n - 1ll) * f[0] % MOD;     }   }   int main() {     rt[0][23] = qpow(3, 119), rt[1][23] = qpow(rt[0][23], MOD - 2);     for (int i = 22; i >= 0; i--) {       rt[0][i] = (long long)rt[0][i + 1] * rt[0][i + 1] % MOD;       rt[1][i] = (long long)rt[1][i + 1] * rt[1][i + 1] % MOD;     }     int n, a, b;     scanf( %d%d%d , &n, &a, &b);     --n, --a, --b;     if (a < 0 || b < 0 || n < a + b) return puts( 0 ), 0;     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (long long)fac[i - 1] * i % MOD;     finv[n] = qpow(fac[n], MOD - 2);     for (int i = n - 1; i >= 0; i--)       finv[i] = (long long)finv[i + 1] * (i + 1) % MOD;     solve(n);     int ans =         (long long)f[a + b] * fac[a + b] % MOD * finv[a] % MOD * finv[b] % MOD;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[600010];   int a[600010];   int main() {     int n;     cin >> n >> s + 1;     for (int i = n + 1; i < 2 * n; i++) s[i] = s[i - n];     for (int i = 1; i < 2 * n; i++) {       a[i] = a[i - 1] + (s[i] ==  (  ? 1 : -1);     }     if (a[n] != 0) {       cout << 0 << endl;       cout <<  1 1  << endl;       return 0;     }     int cnt = 0, minn = 0;     for (int i = 1; i <= n; i++) {       minn = min(minn, a[i]);     }     int now = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == minn) cnt++, now = i;     }     int ans = cnt;     int l = 1, r = 1;     int nowl = now, tmp = 0;     for (int i = now; i <= now + n - 1; i++) {       if (a[i] < minn + 2) {         if (cnt + tmp > ans) {           ans = tmp + cnt;           l = (nowl + 1 + n - 1) % n + 1, r = (i + n - 1) % n + 1;         }         nowl = i, tmp = 0;       } else if (a[i] == minn + 2)         tmp++;     }     tmp = 0, nowl = now;     for (int i = now; i <= now + n; i++) {       if (i == now + n || a[i] == minn) {         if (tmp > ans) {           ans = tmp;           l = (nowl + 1 + n - 1) % n + 1, r = (i + n - 1) % n + 1;         }         nowl = i, tmp = 0;       } else if (a[i] == minn + 1)         tmp++;     }     cout << ans << endl;     cout << l <<     << r << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline const char nl =   n ;   inline const long long MOD = 1000000007;   inline const long double pi = 3.141592653589793238;   struct query {     int a, b;   } q[105];   bool vis[105];   int n, cnt;   void dfs(int x) {     vis[x] = 1;     for (int i = 1; i <= cnt; i++) {       query y = q[i];       if (vis[i]) continue;       if ((y.a < q[x].a && q[x].a < y.b) || (y.a < q[x].b && q[x].b < y.b))         dfs(i);     }   }   int main() {     cin >> n;     while (n--) {       int op, x, y;       cin >> op >> x >> y;       if (op == 1) q[++cnt].a = x, q[cnt].b = y;       if (op == 2) {         for (int i = 1; i <= 100; i++) vis[i] = 0;         dfs(x);         if (vis[y])           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream inp( inp.txt );   ofstream out( out.txt );   const int N = 1e5 + 5;   const long long B = 73;   int builtin_popcount(int &mask) {     int kol = 0;     for (int bit = 0; bit < 20; bit++) kol += int(bool(mask & (1 << bit)));     return kol;   }   signed main() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string a;     cin >> a;     int up = (1 << 20);     vector<int> dp(up, 0);     vector<int> masks;     for (int i = 0; i < ((int)a.size()); i++) {       int mask = 0;       for (int j = i; j < min(((int)a.size()), i + 20); j++) {         int bit = a[j] -  a ;         if (mask & (1 << bit)) break;         mask |= (1 << bit);         masks.push_back(mask);         dp[mask] = builtin_popcount(mask);       }     }     for (int mask = 1; mask < up; mask++)       for (int bit = 0; bit < 20; bit++)         if (mask & (1 << bit)) dp[mask] = max(dp[mask], dp[mask ^ (1 << bit)]);     int ans = 0;     for (auto &mask : masks)       ans = max(ans, builtin_popcount(mask) + dp[mask ^ (up - 1)]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500 + 10;   const int pN = 1e6;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   void add(long long &x, long long y) {     x += y;     x %= MOD;   }   int u, v, n, m;   void Solve(int x, int y, int z) {     int row = n, cul = m;     int nx, ny;     for (int i = 1; i <= x; i++) {       nx = v;       ny = row - u + 1;       u = nx;       v = ny;       swap(row, cul);     }     for (int i = 1; i <= y; i++) {       nx = u;       ny = cul - v + 1;       u = nx;       v = ny;     }     for (int i = 1; i <= z; i++) {       nx = cul - v + 1;       ny = u;       u = nx;       v = ny;       swap(row, cul);     }     cout << u <<     << v << endl;   }   int main() {     int x, y, z, p;     cin >> n >> m >> x >> y >> z >> p;     x %= 4;     y %= 2;     z %= 4;     for (int i = 0; i < p; i++) {       cin >> u >> v;       Solve(x, y, z);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238462643383;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int Ceil(long long int a, long long int b) {     if (a % b == 0)       return a / b;     else       return a / b + 1;   }   const int MAX = 400009;   const int MOD = 1e9 + 7;   const int inf = 1e9 + 10;   long long int deg[MAX], vis[MAX], dep[MAX];   vector<long long int> adj[MAX];   void dfs(int i, int d) {     vis[i] = 1;     dep[i] = d++;     for (int j = 0; j < ((int)((adj[i]).size())); ++j) {       int u = adj[i][j];       if (!vis[u]) dfs(u, d);     }   }   priority_queue<pair<long long int, pair<long long int, long long int> > > pq;   set<pair<long long int, pair<long long int, long long int> > > st;   vector<long long int> ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < (n); ++i) {       int p;       cin >> p;       p--;       if (p == -1) continue;       adj[i].push_back(p), adj[p].push_back(i);       deg[i]++, deg[p]++;     }     dfs(0, 1);     (memset((vis), 0, sizeof(vis)));     for (int i = 0; i < (n); ++i)       if (deg[i] % 2 == 0)         pq.push((make_pair((dep[i]), ((make_pair((i), (deg[i])))))));     long long int cnt = 0;     while (!pq.empty()) {       pair<long long int, pair<long long int, long long int> > c = pq.top();       pq.pop();       if (st.find(c) != st.end()) {         st.erase(c);         continue;       }       int i = c.second.first;       vis[i] = 1;       cnt++;       ans.push_back(i);       for (int j = 0; j < ((int)((adj[i]).size())); ++j) {         int u = adj[i][j];         if (vis[u]) continue;         deg[u]--;         if (deg[u] % 2 == 0)           pq.push((make_pair((dep[u]), ((make_pair((u), (deg[u])))))));         else           st.insert((make_pair((dep[u]), ((make_pair((u), (deg[u] + 1)))))));       }     }     if (cnt == n) {       cout <<  YES n ;       for (auto&(it) : (ans)) cout << it + 1 <<   n ;     } else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, m, a, b, ar[200][200], ans;   long arp[10000], fl, l;   void dfs(long v, long par) {     arp[v] = 1;     l++;     for (int i = 1; i <= n; i++)       if (ar[v][i] == 1) {         if (i == par) continue;         if (arp[i] == 1) {           fl = 1;           return;         }         dfs(i, v);       }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       ar[a][b] = ar[b][a] = 1;     }     for (int i = 1; i <= n; i++)       if (arp[i] == 0) {         fl = 0;         l = 0;         dfs(i, -1);         if (fl)           if (l % 2) ++ans;       }     n -= ans;     if (n % 2) ++ans;     cout << ans << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   int read() {     int r = 0, t = 1, c = getchar();     while (c <  0  || c >  9 ) {       t = c ==  -  ? -1 : 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       r = (r << 3) + (r << 1) + (c ^ 48);       c = getchar();     }     return r * t;   }   const int N = 200010;   int n;   int c1, c2;   std::vector<int> e[N];   int dfs(int u, int f) {     int c = 0;     for (auto v : e[u])       if (v != f) c += dfs(v, u);     if (c) {       c1++;       c2 += c;       return 0;     } else       return 1;   }   int main() {     for (int T = (1), end_T = (read()); T <= end_T; T++) {       n = read();       c1 = c2 = 0;       for (int i = (1), end_i = (n); i <= end_i; i++) e[i].clear();       for (int i = (1), end_i = (n - 1); i <= end_i; i++) {         int u = read(), v = read();         e[u].push_back(v);         e[v].push_back(u);       }       dfs(1, 0);       printf( %d n , c2 - (c1 - 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     vector<pair<long long, char> > v;     vector<long long> freq(27, 0);     string s2(s.length(),  1 );     vector<long long> vis(s.length() + 1, 0);     for (long long i = 0; i < s.length(); i++) {       freq[s[i] -  a ]++;     }     for (long long i = 0; i < 27; i++) {       char c = i +  a ;       if (freq[i] > 0) v.push_back({freq[i], c});     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long n = s.length();     long long cnt = 0;     for (long long i = 2; i <= n; i += 2) {       vis[i] = 1;       cnt++;     }     for (long long i = 2; i <= n; i += 1) {       bool add = false;       if (!vis[i])         for (long long j = i; j <= n; j += i) {           if (vis[j]) add = true;         }       if (!add) continue;       for (long long j = i; j <= n; j += i) {         if (!vis[j]) cnt++;         vis[j] = 1;       }     }     if (v[0].first < (cnt)) {       cout <<  NO ;       return 0;     }     long long i;     for (i = 2; i <= n; i++) {       if (!vis[i]) continue;       s2[i - 1] = v[0].second;       v[0].first--;       vis[i] = 1;     }     long long k = 0;     for (i = 1; i <= n; i++) {       if (!vis[i]) {         if (v[k].first == 0) {           k++;         }         s2[i - 1] = v[k].second;         v[k].first--;       }     }     cout <<  YES n ;     cout << s2;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 405;   int a[MAXN], v[MAXN];   int n;   void work(int x) {     memset(v, 0, sizeof(v));     for (int i = 1; x != 0; i++) {       v[i] = x / a[i];       x %= a[i];     }   }   int work2(int x) {     int res = 0;     for (int i = 1; x != 0; i++) {       res += x / a[i];       x %= a[i];     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int ans = -1;     for (int i = 1; i < n; i++) {       work(a[i] - 1);       for (int j = i + 1; j <= n; j++) {         int s = 0, m = 0;         for (int k = i; k < j; k++) {           s += v[k] * a[k];           m += v[k];         }         s += (v[j] + 1) * a[j];         m += (v[j] + 1);         if (work2(s) > m) {           if (ans == -1 || s < ans) ans = s;         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef int arr32[5000010];   arr32 x, rk, l, r;   int n;   long long ans;   bool cmp(const int &a, const int &b) { return x[a] < x[b]; }   void erase(int x) { r[l[x]] = r[x], l[r[x]] = l[x]; }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %d , x + i);       rk[i] = i, l[i] = i - 1, r[i] = i + 1;     }     sort(rk + 1, rk + n + 1, cmp);     for (int i = 1; i <= n - 2; ++i) {       int p = rk[i];       if (l[p] == 0)         ans += x[p], erase(p);       else if (r[p] == n + 1)         ans += x[p], erase(p);       else         ans += min(x[l[p]], x[r[p]]), erase(p);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   int main() {     int ss, x, y, flag = 0, kk, flag2 = 1;     scanf( %d%d%d , &ss, &x, &y);     if (x == 1 || x == ss) flag++;     if (y == 1 || y == ss) flag++;     if (x >= ss / 2 && x <= ss / 2 + 1 && y >= ss / 2 && y <= ss / 2 + 1)       flag2 = 0;     if (flag == 0) kk = 9;     if (flag == 1) kk = 6;     if (flag == 2) kk = 4;     printf( %s n , (ss * ss >= kk * 2 && flag2) ?  YES  :  NO );   }
#include <bits/stdc++.h>   using namespace std;   long long ans, n, k, a, b;   int main() {     scanf( %I64d %I64d  , &n, &k);     scanf( %I64d %I64d , &a, &b);     long long t = n - 1;     t *= a;     if (k == 1) {       printf( %I64d , t);       return 0;     }     while (n > 1) {       if (n % k == 0)         ans += min(b, a * (n - (n / k))), n /= k;       else {         if (n - (n % k) > 0)           ans += (a * (n % k));         else           ans += (a * ((n % k) - 1));         n -= (n % k);       }     }     ans = min(ans, t);     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 60 + 5;   char a[N][N];   int l[N][N];   int r[N][N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int m, n;       cin >> n >> m;       for (int i = 1; i <= n; i++) cin >> (a[i] + 1);       int f1 = 0, f2 = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (a[i][j] ==  A ) f1 = 1;           if (a[i][j] ==  P ) f2 = 1;         }       }       if (!f2) {         printf( 0 n );         continue;       }       if (!f1) {         printf( MORTAL n );         continue;       }       int visl = 0, visb = 0, visj = 0;       if (a[1][1] ==  A  || a[1][m] ==  A  || a[n][1] ==  A  || a[n][m] ==  A )         visj = 1;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (i == 1 || j == 1 || i == n || j == m) {             if (a[i][j] ==  A ) visb = 1;           }           if (a[i][j] ==  A ) l[i][j] = l[i][j - 1] + 1;         }         if (l[i][m] == m) visl = 1;       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (a[i][j] ==  A ) r[i][j] = r[i - 1][j] + 1;           if (r[n][j] == n) visl = 1;         }       }       int visjl = 0;       if (r[n][m] == n || l[n][m] == m || r[n][1] == n || l[1][m] == m) visjl = 1;       if (visjl)         printf( 1 n );       else if (visj)         printf( 2 n );       else if (visl && visb)         printf( 2 n );       else if (visb)         printf( 3 n );       else         printf( 4 n );       memset(l, 0, sizeof l);       memset(r, 0, sizeof r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   unsigned long long h[N];   int p[N];   bool ed[N], flg[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());     unordered_map<unsigned long long, int> mp;     int n, m = 0, i, j, k;     unsigned long long tot = 0;     cin >> n;     for (i = 2; i <= n; i++) {       if (!ed[i]) p[m++] = i, h[i] = rnd();       for (j = 0; j < m && (k = i * p[j]) <= n; j++) {         ed[k] = 1;         h[k] = h[i] ^ h[p[j]];         if (i % p[j] == 0) break;       }       if (1 ^ n - i & 1) tot ^= h[i];     }     for (i = 3; i <= n; i++) h[i] ^= h[i - 1];     fill(flg + 1, flg + n + 1, 1);     if (tot == 0) goto out;     for (i = 1; i <= n; i++)       if (tot == h[i]) {         flg[i] = 0;         goto out;       }     for (i = 1; i <= n; i++) {       auto it = mp.find(tot ^ h[i]);       if (it != mp.end()) {         flg[i] = flg[it->second] = 0;         goto out;       }       mp[h[i]] = i;     }     flg[n >> 1] = flg[2] = flg[n] = 0;   out:     cout << accumulate(flg + 1, flg + n + 1, 0) <<   n ;     for (int i = 1; i <= n; i++)       if (flg[i]) cout << i <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long a, b;     cin >> a >> b;     while (a != 0 && b != 0) {       if (a >= 2 * b) {         a = a % (2 * b);       } else if (b >= 2 * a) {         b = b % (a * 2);       } else         break;     }     cout << a <<     << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433;   const int mod = 1000000007;   const long long inf = 3e18;   long long n, m, k;   long long dp[5001][5001];   vector<long long> v;   long long mkc(long long i, long long j) {     if (j == 0 or i >= v.size()) {       return 0;     }     if (dp[i][j] != -1) return dp[i][j];     long long ans = 0;     ans = max(mkc(i + 1, j), v[i] + mkc(i + m, j - 1));     return dp[i][j] = ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     memset(dp, -1, sizeof(dp));     cin >> n >> m >> k;     vector<long long> a(n), pre(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     pre[0] = a[0];     for (long long i = 1; i < n; i++) {       pre[i] = pre[i - 1] + a[i];     }     for (long long i = n - 1; i >= m; i--) {       pre[i] = pre[i] - pre[i - m];     }     for (long long i = m - 1; i < n; i++) {       v.push_back(pre[i]);     }     cout << mkc(0, k);   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long x, y, n;       cin >> x >> y >> n;       long long rem = n % x;       long long ans = n - rem;       if (ans + y <= n) {         cout << ans + y <<   n ;       } else {         ans -= (x - y);         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   int INF = 2147483647;   double INFD = 2147483647;   double PI = 3.14159265359;   using namespace std;   struct Child {     Child(long long v_, long long d_, long long p_) {       gone = false;       v = v_;       d = d_;       p = p_;     }     bool gone;     long long v;     long long d;     long long p;   };   int Enter(vector<Child>& kids, int base) {     long long v = kids[base].v, deduction = 0;     int gone_kid = -1;     kids[base].gone = true;     base++;     while (deduction < v && base < kids.size()) {       if (!kids[base].gone) {         kids[base].p -= v - deduction;         if (kids[base].p < 0 && gone_kid == -1) {           gone_kid = base;         }         deduction++;       }       base++;     }     return gone_kid;   }   void print(vector<Child>& kids) {     int i = 0;     while (i < kids.size()) {       Child c = kids[i];       cout << i + 1 <<  :   << c.v <<     << c.d <<     << c.p;       if (c.gone) {         cout <<   -------- ;       }       cout << endl;       i++;     }   }   void Deduce(vector<Child>& kids, int base) {     long long deduction = 0;     int i = base;     while (i < kids.size()) {       if (!kids[i].gone) {         kids[i].p -= deduction;         if (kids[i].p < 0) {           kids[i].gone = true;           deduction += kids[i].d;         }       }       i++;     }   }   int main() {     int n = 0;     cin >> n;     vector<Child> kids(n, Child(0, 0, 0));     vector<int> entered;     int i = 0;     while (i < n) {       cin >> kids[i].v >> kids[i].d >> kids[i].p;       i++;     }     i = 0;     while (i < n) {       if (!kids[i].gone) {         entered.push_back(i);         int gone_kid = Enter(kids, i);         if (gone_kid != -1) {           Deduce(kids, gone_kid);         }       }       i++;     }     cout << entered.size() << endl;     i = 0;     while (i < entered.size()) {       if (i) {         cout <<    ;       }       cout << entered[i] + 1;       i++;     }     cout << endl;     return 0;   }