malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int buf_size = 1e5 + 5;   char buf[buf_size], *S, *T;   inline char gc() {     if (S == T) T = (S = buf) + fread(buf, 1, buf_size, stdin);     return S != T ? *(S++) : EOF;   }   inline int in() {     int x = 0, f = 1;     char c = gc();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = gc();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c - 48, c = gc();     return x * f;   }   const int N = 2e6 + 5, mod = 1e9 + 7;   int q, x, y, n = 2000000, ans;   int inv[N], fac[N], finv[N];   int pri[N], pc, c[N];   int p[N];   bool inp[N];   int a[105], ac;   inline int add(const int &a, const int &b) {     return a + b >= mod ? a + b - mod : a + b;   }   inline int mul(const int &a, const int &b) { return 1ll * a * b % mod; }   inline int C(const int &a, const int &b) {     return mul(fac[a], mul(finv[b], finv[a - b]));   }   int main() {     inv[1] = fac[0] = fac[1] = finv[0] = finv[1] = 1;     for (int i = 2; i <= n; i++) {       inv[i] = mul(mod - mod / i, inv[mod % i]);       fac[i] = mul(fac[i - 1], i);       finv[i] = mul(finv[i - 1], inv[i]);     }     for (int i = 2; i <= n; i++) {       if (!inp[i]) pri[++pc] = i, c[i] = i;       for (int j = 1; j <= pc && i * pri[j] <= n; j++) {         inp[i * pri[j]] = 1;         c[i * pri[j]] = pri[j];         if (i % pri[j] == 0) break;       }     }     p[0] = 1;     for (int i = 1; i <= n; i++) p[i] = mul(p[i - 1], 2);     q = in();     while (q--) {       x = in(), y = in();       ac = 0, ans = 0;       int res = 1;       while (x > 1) {         a[++ac] = c[x];         x /= c[x];       }       for (int i = 1, j; i <= ac; i = j + 1) {         j = i;         while (j + 1 <= ac && a[j + 1] == a[i]) j++;         res = mul(res, C(j - i + y, y - 1));       }       ans = mul(res, p[y - 1]);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   char s[maxn], t[maxn];   int s_big[30], s_small[30], t_big[30], t_small[30];   int main() {     while (scanf( %s%s , s + 1, t + 1) != EOF) {       memset(s_big, 0, sizeof(s_big));       memset(s_small, 0, sizeof(s_small));       memset(t_big, 0, sizeof(t_big));       memset(t_small, 0, sizeof(t_small));       int len1 = strlen(s + 1);       int len2 = strlen(t + 1);       for (int i = 1; i <= len1; i++) {         if (s[i] >  Z ) {           s_small[s[i] -  a ]++;         } else {           s_big[s[i] -  A ]++;         }       }       for (int i = 1; i <= len2; i++) {         if (t[i] >  Z ) {           t_small[t[i] -  a ]++;         } else {           t_big[t[i] -  A ]++;         }       }       int ans1 = 0, ans2 = 0;       for (int i = 0; i < 26; i++) {         ans1 += min(s_small[i], t_small[i]);         ans1 += min(s_big[i], t_big[i]);         if (s_small[i] < t_small[i]) {           t_small[i] -= s_small[i];           s_small[i] = 0;         } else {           s_small[i] -= t_small[i];           t_small[i] = 0;         }         if (s_big[i] < t_big[i]) {           t_big[i] -= s_big[i];           s_big[i] = 0;         } else {           s_big[i] -= t_big[i];           t_big[i] = 0;         }       }       for (int i = 0; i < 26; i++) {         ans2 += min(s_small[i], t_big[i]);         ans2 += min(s_big[i], t_small[i]);       }       printf( %d %d n , ans1, ans2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> P;   bool used[111];   int pos;   bool ok(int T) {     if (T == pos) return true;     used[T] = true;     for (int i = 0; i < P.size(); i++) {       if (used[i] == false) {         if (P[T].first > P[i].first && P[T].first < P[i].second ||             P[T].second > P[i].first && P[T].second < P[i].second) {           used[i] = true;           if (ok(i)) return true;         }       }     }     return false;   }   string ans(int l, int r) {     pos = r;     for (int i = 0; i < 111; i++) used[i] = false;     if (ok(l)) return  YES ;     return  NO ;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int type;       cin >> type;       if (type == 1) {         int a, b;         cin >> a >> b;         P.push_back(make_pair(a, b));       } else {         int l, r;         cin >> l >> r;         l--;         r--;         cout << ans(l, r) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   int lcm(int x, int y) { return x / gcd(x, y) * y; }   int binpow(int a, int p) {     if (!p) return 1;     int g = binpow(a, p >> 1);     if (p % 2 == 0)       return (g * g) % 1000000007;     else       return (((g * g) % 1000000007) * a) % 1000000007;   }   int rev(int n) { return binpow(n, 1000000007 - 2); }   void solve();   int main() {     cout.setf(ios::fixed);     cout.precision(20);     cerr.setf(ios::fixed);     cerr.precision(3);     int n = 1;     for (int i = 0; i < n; ++i) solve();   }   long long a[100100];   long long n;   long long r[100100];   void solve() {     cin >> n;     int i;     for (i = 0; i < n; i++) cin >> a[i];     r[0] = a[0];     for (i = 1; i < n; i++) r[i] = max(r[i - 1], a[i]);     int m;     cin >> m;     long long len, sz;     for (i = 0; i < m; i++) {       cin >> len >> sz;       cout << max(r[0], r[len - 1]) << endl;       r[0] = max(r[0], r[len - 1]) + sz;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   const double EPS = 1e-8;   const double PI = acos(-1);   const int MAX_N = 400000;   struct SegSum {     int bit[MAX_N + 1];     int n;     void init(int _n) {       n = _n;       memset(bit, 0, sizeof(bit));     }     int sum(int i) {       int s = 0;       while (i > 0) {         s += bit[i];         i -= i & -i;       }       return s;     }     int sum(int a, int b) { return sum(b) - sum(a - 1); }     void add(int i, int x) {       while (i <= n) {         bit[i] += x;         i += i & -i;       }     }   } SegSum;   int a[300000];   int pos[300000];   int main() {     int n;     while (cin >> n) {       for (int i = 0; i < (int)n; ++i) {         scanf( %d , a + i);         a[i]--;         pos[a[i]] = i;       }       SegSum.init(n);       for (int i = 0; i < (int)n; ++i) {         if (a[i] == 0 || pos[a[i] - 1] > i) {           SegSum.add(a[i] + 1, 1);         }       }       int q;       cin >> q;       for (int i = 0; i < (int)q; ++i) {         int k, x, y;         scanf( %d%d%d , &k, &x, &y);         x--;         y--;         if (k == 1) {           int r = SegSum.sum(x + 1, y + 1);           if (SegSum.sum(x + 1, x + 1) == 0) r++;           cout << r << endl;         } else {           if (a[x] + 1 < n && pos[a[x] + 1] > x && pos[a[x] + 1] < y) {             SegSum.add(a[x] + 1 + 1, 1);           }           if (a[x] - 1 >= 0 && pos[a[x] - 1] > x && pos[a[x] - 1] < y) {             SegSum.add(a[x] + 1, -1);           }           if (a[y] + 1 < n && pos[a[y] + 1] >= x && pos[a[y] + 1] < y) {             SegSum.add(a[y] + 1 + 1, -1);           }           if (a[y] - 1 >= 0 && pos[a[y] - 1] >= x && pos[a[y] - 1] < y) {             SegSum.add(a[y] + 1, 1);           }           swap(a[x], a[y]);           swap(pos[a[x]], pos[a[y]]);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   int t, n;   long long x[maxn + 10], y[maxn + 10], z[maxn + 10];   long long l[4], r[4], tl[4], tr[4];   long long a[4];   void update(int p, long long a, long long b) {     l[p] = max(l[p], a - b);     r[p] = min(r[p], a + b);   }   bool calc() {     long long sum = 0;     for (int i = 0; i <= 3; ++i) {       tl[i] = l[i] & 1 ? (l[i] + 1) / 2 : l[i] / 2;       tr[i] = r[i] & 1 ? (r[i] - 1) / 2 : r[i] / 2;       if (tl[i] > tr[i]) return 0;       if (i) {         a[i] = tl[i];         sum += tl[i];       }     }     for (int i = 1; i <= 3; ++i) {       long long v = min(max(tl[0] - sum, 0ll), tr[i] - tl[i]);       a[i] += v;       sum += v;     }     return sum >= tl[0] && sum <= tr[0];   }   bool chk(long long v) {     memset(l, -0x3f, sizeof l);     memset(r, 0x3f, sizeof r);     for (int i = 1; i <= n; ++i) {       update(0, x[i] + y[i] + z[i], v);       update(1, x[i] + y[i] - z[i], v);       update(2, x[i] - y[i] + z[i], v);       update(3, -x[i] + y[i] + z[i], v);     }     if (calc()) {       for (int i = 1; i <= 3; ++i) a[i] *= 2;       return 1;     }     l[0] -= 3;     r[0] -= 3;     for (int i = 1; i <= 3; ++i) {       --l[i];       --r[i];     }     if (calc()) {       for (int i = 1; i <= 3; ++i) a[i] = a[i] * 2 + 1;       return 1;     }     return 0;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) scanf( %lld%lld%lld , &x[i], &y[i], &z[i]);       long long l = 0, r = 3e18;       while (l != r) {         long long mid = (l + r) >> 1;         if (chk(mid))           r = mid;         else           l = mid + 1;       }       chk(l);       printf( %lld %lld %lld n , (a[1] + a[2]) / 2, (a[1] + a[3]) / 2,              (a[2] + a[3]) / 2);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       n = n * k;       if (n % 2 == 1)         cout << n / 2 + 1;       else         cout << n / 2;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef pair<long long, long long> ll;   typedef vector<long long> vl;   typedef vector<ll> vll;   typedef vector<vl> vvl;   template <typename T>   ostream &operator<<(ostream &o, vector<T> v) {     if (v.size() > 0) o << v[0];     for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];     return o <<    ;   }   template <typename U, typename V>   ostream &operator<<(ostream &o, pair<U, V> p) {     return o <<  (  << p.first <<  ,   << p.second <<  )  ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (unsigned i = 0; i < v.size(); i++) in >> v[i];     return in;   }   template <typename T>   istream &operator>>(istream &in, pair<T, T> &p) {     in >> p.first;     in >> p.second;     return in;   }   template <typename T>   ostream &operator<<(ostream &o, set<T> v) {     for (auto &it : v) o << it <<    ;     return o <<   n ;   }   template <typename T, typename U>   ostream &operator<<(ostream &o, map<T, U> v) {     for (auto &it : v) o << it <<    ;     return o <<   n ;   }   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   int main(int argc, char *argv[]) {     long long n, d;     cin >> n >> d;     vl a(n);     cin >> a;     long long m;     cin >> m;     sort((a).begin(), (a).end());     if (m <= n) {       long long res = 0;       for (long long i = (0); i < (long long)m; i++) res += a[i];       cout << res;     } else {       long long sum = accumulate((a).begin(), (a).end(), 0LL);       cout << sum - (m - n) * d;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c;   int sisa(int x, int n) {     if (x >= 0)       return x % n;     else if (abs(x) % n == 0)       return 0;     else       return ((abs(x) / n) + 1) * n + x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> a >> b >> c;     b += c;     cout << (sisa(b, a) == 0 ? a : sisa(b, a)) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     int k;     cin >> k;     if (k == 0) {       if (n % 6 == 0 || n % 6 == 5)         cout << 0;       else if (n % 6 == 1 || n % 6 == 2)         cout << 1;       else         cout << 2;     } else if (k == 1) {       if (n % 3 == 0)         cout << 1;       else if (n % 3 == 1)         cout << 0;       else         cout << 2;     } else {       if (n % 6 == 0 || n % 6 == 1)         cout << 2;       else if (n % 6 == 2 || n % 6 == 3)         cout << 0;       else         cout << 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4, INF = 1e9;   int sub[N], par[N], nn, level[N];   set<int> adj[N];   vector<int> ar[N];   void dfs(int n, int p) {     for (auto i : ar[n])       if (i != p) level[i] = level[n] + 1, dfs(i, n);   }   void dfs1(int n, int p) {     nn++;     sub[n] = 1;     for (auto i : adj[n])       if (i != p) dfs1(i, n), sub[n] += sub[i];   }   int dfs2(int n, int p) {     for (auto i : adj[n])       if (i != p and sub[i] > nn / 2) return dfs2(i, n);     return n;   }   void decompos(int n, int p) {     nn = 0;     dfs1(n, n);     int centroid = dfs2(n, n);     if (p == -1) p = centroid;     par[centroid] = p;     for (auto i : adj[centroid]) adj[i].erase(centroid), decompos(i, centroid);     adj[centroid].clear();   }   int main() {     int n, m, i, j, a, b;     cin >> n;     for (i = 1; i < n; i++) cin >> a >> b, adj[a].insert(b), adj[b].insert(a);     decompos(1, -1);     for (i = 1; i <= n; i++) {       if (par[i] == i) {         j = i;         continue;       }       ar[i].push_back(par[i]);       ar[par[i]].push_back(i);     }     dfs(j, -1);     for (i = 1; i <= n; i++) cout << char(level[i] +  A ) <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000 + 10;   int n, m, k, t;   vector<pair<int, int> > w;   int main() {     cin >> n >> m >> k >> t;     for (int i = 0; i < k; i++) {       int f, s;       cin >> f >> s;       w.push_back(make_pair(f, s));     }     sort(w.begin(), w.end());     for (int i = 0; i < t; i++) {       int x, y;       cin >> x >> y;       pair<int, int> cell = make_pair(x, y);       int in = -2;       for (int j = 0; j < k; j++) {         if (cell == w[j]) {           in = -1;           break;         } else if (cell < w[j])           break;         else           in = j;       }       if (in == -1)         cout <<  Waste n ;       else {         int num = (x - 1) * m + (y - 1) - max(in + 1, 0);         if (num % 3 == 0)           cout <<  Carrots n ;         else if (num % 3 == 1)           cout <<  Kiwis n ;         else           cout <<  Grapes n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   int gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long a, b = 0, c = 0, t, lj = 0, k = 0, r = 0, l = 0, sum = 0, rr,                  mn = LLONG_MAX, mx = LLONG_MIN, w, y = 0, x = 0, d, neg = 0,                  pos = 0, ans = 0;     string s5 =   , s2 =   , s3 =   , s1 =   , s =   ;     map<char, long long> mp;     cin >> a >> b >> x >> y;     c = gcd(x, y);     while (c != 1) {       x /= c;       y /= c;       c = gcd(x, y);     }     cout << min(b / y, a / x);   }
#include <bits/stdc++.h>   using namespace std;   long long a[100010];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     int m;     scanf( %d , &m);     long long l = 0;     while (m--) {       long long w, h;       scanf( %lld%lld , &w, &h);       l = max(l, a[w - 1]);       printf( %lld n , l);       l += h;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int N = 3 + 1e5;   struct node {     int x, h, id;     bool operator<(const node& b) const { return x < b.x; }   } a[N];   struct {     int l, r, v;     bool flag;   } tr[1000000 * 4];   int n;   int b[N * 10], t;   int ans[N];   void up(int k) { tr[k].v = tr[(k << 1)].v + tr[(k << 1 | 1)].v; }   void down(int k) {     tr[(k << 1)].v = 0;     tr[(k << 1 | 1)].v = 0;     tr[(k << 1)].flag = tr[(k << 1 | 1)].flag = true;     tr[k].flag = false;   }   void build(int k, int l, int r) {     tr[k].l = l;     tr[k].r = r;     if (l == r) {       return;     }     int mid = l + r >> 1;     build((k << 1), l, mid);     build((k << 1 | 1), mid + 1, r);   }   void update1(int k, int l, int r) {     if (l <= tr[k].l && tr[k].r <= r) {       tr[k].v = 0;       tr[k].flag = true;       return;     }     int mid = tr[k].l + tr[k].r >> 1;     if (tr[k].flag) down(k);     if (l <= mid) update1((k << 1), l, r);     if (r > mid) update1((k << 1 | 1), l, r);     up(k);   }   void update2(int k, int p, int v) {     if (tr[k].l == tr[k].r) {       tr[k].v += v;       return;     }     int mid = tr[k].l + tr[k].r >> 1;     if (tr[k].flag) down(k);     if (p <= mid)       update2((k << 1), p, v);     else       update2((k << 1 | 1), p, v);     up(k);   }   int query(int k, int l, int r) {     if (l <= tr[k].l && tr[k].r <= r) return tr[k].v;     if (tr[k].flag) down(k);     int ans = 0, mid = tr[k].l + tr[k].r >> 1;     if (l <= mid) ans = query((k << 1), l, r);     if (r > mid) ans += query((k << 1 | 1), l, r);     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i].x >> a[i].h;       a[i].id = i;       b[++t] = a[i].x;       b[++t] = a[i].x + 1;       b[++t] = a[i].x + a[i].h - 1;     }     sort(b + 1, b + t + 1);     t = unique(b + 1, b + t + 1) - b - 1;     sort(a + 1, a + n + 1);     build(1, 1, t);     for (int i = n; i; --i) {       int p1 = lower_bound(b + 1, b + t + 1, a[i].x) - b;       int p2 = lower_bound(b + 1, b + t + 1, a[i].x + 1) - b;       int p3 = lower_bound(b + 1, b + t + 1, a[i].x + a[i].h - 1) - b;       int rec = query(1, p2, p3);       ans[a[i].id] = rec + 1;       update1(1, p2, p3);       update2(1, p1, rec + 1);     }     for (int i = 1; i <= n; ++i) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1005];   void Solve() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1;; ++i) {       for (int j = 2; j <= n; ++j) {         if (a[j] < a[j - 1]) goto fail;       }       printf( %d n , i - 1);       break;     fail:;       if (i & 1) {         for (int j = 1; j <= n; j += 2) {           if (j + 1 > n) continue;           if (a[j] > a[j + 1]) swap(a[j], a[j + 1]);         }       } else {         for (int j = 2; j <= n; j += 2) {           if (j + 1 > n) continue;           if (a[j] > a[j + 1]) swap(a[j], a[j + 1]);         }       }     }   }   int main() {     int T;     scanf( %d , &T);     while (T-- > 0) Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print(pair<int, int> v) {     if (v.first < 10) {       cout <<  0  << v.first <<  : ;     } else {       cout << v.first <<  : ;     }     if (v.second < 10) {       cout <<  0  << v.second;     } else {       cout << v.second;     }   }   int main() {     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int h, m;       char d;       cin >> h >> d >> m;       v.push_back({h, m});     }     sort(v.begin(), v.end());     v.push_back({v[0].first + 24, v[0].second});     int mans = -1;     for (int i = 0; i < v.size() - 1; i++) {       int m = 0;       m = (v[i + 1].first - v[i].first) * 60 + (v[i + 1].second - v[i].second) -           1;       mans = max(mans, m);     }     print({mans / 60, mans % 60});   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, z;     cin >> x >> y >> z;     long long ans1 = x / z + y / z, ans2 = 0;     x %= z;     y %= z;     if (x + y >= z) {       ans1++;       ans2 = min(z - x, z - y);     }     cout << ans1 <<     << ans2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   int main() {     long long pl, pr, vl, vr, k;     double ans = 0;     cin >> pl >> pr >> vl >> vr >> k;     for (int h = 1; h <= 9; h++) {       for (int i = 0; i < (1 << h); i++) {         int x = 0, y = 1;         for (int j = 0; j < h; j++) {           if (i & (1 << j)) {             x += 4 * y;           } else {             x += 7 * y;           }           y *= 10;         }         v.push_back(x);       }     }     v.push_back(0);     sort(v.begin(), v.end());     v.push_back(1e9 + 1);     double pt = 0;     for (int i = 0; i + k + 1 < v.size(); i++) {       ans += max(0ll, (min(v[i + 1], pr) - max(v[i] + 1, pl)) + 1) *              max(0ll, (min(v[i + k + 1] - 1, vr) - max(v[i + k], vl)) + 1);       ans += max(0ll, (min(v[i + 1], vr) - max(v[i] + 1, vl)) + 1) *              max(0ll, (min(v[i + k + 1] - 1, pr) - max(v[i + k], pl)) + 1);       if (pt != ans && k == 1) {         if (min(v[i + 1], pr) == max(v[i + k], vl) ||             max(v[i] + 1, vl) == min(v[i + k + 1] - 1, pr)) {           ans--;         }       }       pt = ans;     }     double all = ((pr - pl) + 1) * ((vr - vl) + 1);     cout << fixed << setprecision(12) << ans / all;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0.0);   long long int pow1(long long int n, long long int k) {     long long int ret = 1;     while (k) {       if (k % 2 == 1) ret = (ret * n) % 1000000007;       n = (n * n) % 1000000007;       k /= 2;     }     return ret;   }   string s, s1;   int n;   string q[100000];   long long int A[10], len[10];   int main() {     cin >> s;     cin >> n;     for (int i = 0; i < n; i++) cin >> q[i];     for (int i = 0; i < 10; i++) {       A[i] = i;       len[i] = 1;     }     for (int i = n - 1; i >= 0; i--) {       int idx = q[i][0] -  0 ;       long long int val = 0, val1 = 0;       for (int j = 3; j < q[i].size(); j++) {         int d = q[i][j] -  0 ;         val = (val * pow1(10, len[d])) % 1000000007;         val += A[d];         val %= 1000000007;         val1 += len[d];         val1 %= (1000000007 - 1);       }       A[idx] = val;       len[idx] = val1;     }     long long int ans = 0;     for (int i = 0; i < s.size(); i++) {       int d = s[i] -  0 ;       ans = (ans * pow1(10, len[d]) + A[d]) % 1000000007;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7, llinf = 1e18 + 123;   void xru() {     setlocale(LC_ALL,  rus );     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void dolitb(long long p, long long x, set<long long>& s, vector<long long>& a) {     if (s.empty() || s.lower_bound(p) == s.end()) {       return;     }     long long np = *s.lower_bound(p);     if (x > a[np]) {       x -= a[np];       a[np] = 0;       s.erase(s.find(np));       dolitb(np + 1, x, s, a);     } else {       a[np] -= x;     }   }   int main() {     xru();     long long n;     cin >> n;     vector<long long> a(n);     for (long long ghgh = 0; ghgh < a.size(); ghgh++) cin >> a[ghgh];     ;     vector<long long> cnt = a;     set<long long> s;     for (long long i = 0; i < n; i++) {       s.insert(i);     }     long long t;     cin >> t;     vector<long long> ans;     for (long long q = 0; q < t; q++) {       long long num;       cin >> num;       if (num == 1) {         long long p, x;         cin >> p >> x;         p--;         dolitb(p, x, s, a);       } else {         long long p;         cin >> p;         p--;         ans.push_back(cnt[p] - a[p]);       }     }     for (long long ghgha = 0; ghgha < ans.size(); ghgha++)       cout << ans[ghgha] << endl;     ;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   int sol(string a) {     int co = 0;     for (int i = 0; i < k; i++)       if (s[i] != a[i % 3]) co++;     int ans = co;     for (int i = 1; i <= n - k; i++) {       if (s[i - 1] != a[(i - 1) % 3]) co--;       if (s[i + k - 1] != a[(i + k - 1) % 3]) co++;       ans = min(ans, co);     }     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> k >> s;       cout << min(min(sol( RGB ), sol( GBR )), sol( BRG )) << endl;     }   }