malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   unsigned long long get_idx(int p) {     int idx = 1;     while (idx < p) idx *= 2;     return idx;   }   void update(vector<unsigned long long> &tree, unsigned long long idx,               unsigned long long val) {     tree[idx] = val;     idx /= 2;     while (idx) {       tree[idx] = tree[idx * 2] | tree[idx * 2 + 1];       idx /= 2;     }   }   int main() {     unsigned long long n, k, x, a = 1;     unsigned long long ans = 0;     cin >> n >> k >> x;     vector<unsigned long long> data(n);     for (int i = 0; i < k; i++) a *= x;     for (int i = 0; i < n; i++) cin >> data[i];     unsigned long long idx = get_idx(n);     vector<unsigned long long> tree(idx * 2);     for (int i = idx; i < idx + n; i++) update(tree, i, data[i - idx]);     for (int i = 0; i < n; i++) {       update(tree, i + idx, data[i] * a);       ans = max(tree[1], ans);       update(tree, i + idx, data[i]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, j, k = 0, x = 0, y = 0, i, c = 0;     cin >> m;     int a[500001] = {0};     int ans[1000][1000] = {0};     while (m--) {       cin >> n >> x >> y;       if (n == 1) {         a[x] += y;         for (i = 1; i < 1000; i++) ans[i][x % i] += y;       } else {         if (x < 1000) {           cout << ans[x][y] << endl;         } else {           c = 0;           for (i = y; i < 500001; i += x) c += a[i];           cout << c << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAX_N = 1e5 + 9;   int ans[MAX_N];   void sieve(int n) {     int nw = 1;     for (int i = 2; i <= n; i++) ans[i] = INT_MAX;     for (ll i = 2; i <= n; i++) {       if (ans[i] != INT_MAX) continue;       for (ll j = i; j <= n; j += i) ans[j] = min(ans[j], nw);       nw++;     }   }   int main() {     int n;     cin >> n;     sieve(n);     for (int i = 2; i <= n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int m[1000][1000];   int main() {     m[0][0] = 1;     m[0][1] = 2;     m[1][0] = 2;     m[1][1] = 3;     m[2][0] = 3;     m[2][1] = 1;     int n;     scanf( %d , &n);     int g = 4;     int d = 2;     int cur = 0;     while (g <= n) {       m[cur][d] = g;       ++g;       if (cur == d) {         ++d;         for (int i = 0; i < d; ++i) {           m[d][i] = m[i][d - 1];         }         cur = 0;       } else         ++cur;     }     printf( %d n , d + 1);     for (int i = 0; i <= d; ++i) {       for (int j = 0; j < d; ++j) {         printf( %d  , m[i][j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, string> mp;   int main() {     string a, b;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a >> b;       mp[b] = a;     }     for (int i = 0; i < m; i++) {       cin >> a >> b;       b.pop_back();       cout << a <<     << b <<  ; #  << mp[b] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   stack<int> s[100005];   int n, m, k, from, to, d[100005], f[100005], t[100005], c[100005],       before[100005], cnt = 0;   bool vis[100005] = {false};   void swap(int &a, int &b) {     int t = a;     a = b;     b = t;   }   void qsort(int l, int r) {     int i = l, j = r, x = d[(l + r) >> 1];     do {       while (d[i] < x) i++;       while (d[j] > x) j--;       if (i <= j) {         swap(d[i], d[j]);         swap(f[i], f[j]);         swap(t[i], t[j]);         swap(c[i], c[j]);         i++;         j--;       }     } while (i <= j);     if (l < j) qsort(l, j);     if (i < r) qsort(i, r);   }   int max(int a, int b) {     if (a > b) return a;     return b;   }   int min(int a, int b) {     if (a < b) return a;     return b;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     from = 0x3f3f3f3f;     to = 0;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%d , &d[i], &f[i], &t[i], &c[i]);       from = min(from, d[i]);       to = max(to, d[i]);     }     qsort(1, m);     for (int i = 1; i <= n; i++) before[i] = 1000005;     for (int i = m; i > 0; i--) {       if (f[i] == 0) {         int top;         if (!s[t[i]].empty()) top = s[t[i]].top();         if (s[t[i]].empty() || c[top] > c[i]) s[t[i]].push(i);       }     }     int now = 1, now2 = 1;     bool flag = true;     for (int i = 1; i <= n; i++)       if (s[i].empty()) {         flag = false;         break;       }     if (!flag) {       printf( -1 n );       return 0;     }     long long ans, val = 0, qwq;     for (int i = 1; i <= n; i++) {       val += 1000005;       int top = s[i].top();       val += c[top];     }     qwq = 20000000000000;     ans = qwq;     for (int start = from - 1; start <= to + 1; start++) {       if (!flag) break;       int end = start + k;       while (now <= m && d[now] < start) {         if (t[now] == 0) {           val -= before[f[now]];           before[f[now]] = min(before[f[now]], c[now]);           val += before[f[now]];           if (!vis[f[now]]) cnt++;           vis[f[now]] = true;         }         now++;       }       while (now2 <= m && d[now2] < end) {         if (f[now2] == 0) {           if (s[t[now2]].empty()) {             flag = false;             break;           }           int top = s[t[now2]].top();           if (d[top] < end) {             val -= c[top];             s[t[now2]].pop();             if (!s[t[now2]].empty()) val += c[s[t[now2]].top()];           }           if (s[t[now2]].empty()) flag = false;         }         now2++;       }       if (!flag) break;       if (cnt == n) ans = min(ans, val);     }     if (ans == qwq)       printf( -1 n );     else       printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2002;   int n, k;   long long a[MAXN];   int dp[MAXN];   int abs1(int a) { return a >= 0 ? a : -a; }   int min1(int a, int b) { return a > b ? b : a; }   bool find(long long mid) {     for (int i = 1; i <= n + 1; i++) dp[i] = i - 1;     dp[1] = 0;     for (int i = 2; i <= n; i++)       for (int j = 1; j < i; j++)         if (abs1(a[i] - a[j]) <= (i - j) * mid)           dp[i] = min1(dp[i], dp[j] + (i - j - 1));     for (int i = 1; i <= n; i++) dp[n + 1] = min1(dp[n + 1], n - i + dp[i]);     if (dp[n + 1] <= k) return true;     return false;   }   int main() {     int i;     long long mid, L, R;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     L = 0;     R = 2000000001;     while (L <= R) {       mid = (L + R) >> 1;       if (find(mid))         R = mid - 1;       else         L = mid + 1;     }     printf( %lld n , R + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc;     cin >> tc;     int z;     for (int t = 1; t <= tc; t++) {       cin >> z;       int a, s, d = 0;       s = 0;       a = 0;       int x;       for (int q = 1; q <= z; q++) {         cin >> x;         if (x % 3 == 0)           a++;         else if (x % 3 == 1)           s++;         else           d++;       }       int total = a + (min(s, d));       int temp = min(s, d);       s -= temp;       d -= temp;       total += (s / 3);       total += (d / 3);       cout << total << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int N[5];   int K;   int getChoice(int choice) {     if (N[choice]) return choice;     for (int i = 1; true; i++) {       if (choice + i < 5 && N[choice + i]) return choice + i;       if (choice - i >= 0 && N[choice - i]) return choice - i;     }   }   int main() {     for (int i = 0; i < 5; i++) cin >> N[i];     cin >> K;     map<string, int> strToInt;     strToInt[ S ] = 0;     strToInt[ M ] = 1;     strToInt[ L ] = 2;     strToInt[ XL ] = 3;     strToInt[ XXL ] = 4;     map<int, string> intToStr;     intToStr[0] =  S ;     intToStr[1] =  M ;     intToStr[2] =  L ;     intToStr[3] =  XL ;     intToStr[4] =  XXL ;     string temp;     for (int i = 0; i < K; i++) {       cin.ignore(5,   n );       cin >> temp;       int choice = strToInt[temp];       int willGet = getChoice(choice);       N[willGet]--;       cout << intToStr[willGet] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, s1, s2, s3, s4;     cin >> a >> b >> c;     s1 = a + c + b;     s2 = a + a + b + b;     s3 = a + c + c + a;     s4 = b + c + c + b;     cout << min(s1, (min(s2, min(s3, s4))));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<long long> v(n);       for (int i = 0; i < n; i++) {         string s;         cin >> s;         long long a = 0;         for (int j = 0; j < m; j++) {           if (s[j] ==  1 ) {             a += (1LL << (m - 1 - j));           }         }         v[i] = a;       }       sort(v.begin(), v.end());       long long mid = (1LL << (m - 1)) - 1;       long long x = (1 << m);       for (int i = 0; i < n; i++) {         if (v[i] < mid) {           if (x % 2 == 0) mid++;           x--;         } else if (v[i] == mid) {           if (x % 2 == 0) {             mid++;             x--;           } else {             long long q = mid - 1;             int y;             while (1) {               y = 0;               for (int j = 0; j < n; j++) {                 if (q == v[j]) {                   q--;                   y = 1;                   break;                 }               }               if (!y) break;             }             mid = q;             x--;           }         } else {           if (x % 2) {             long long q = mid - 1;             int y;             while (1) {               y = 0;               for (int j = 0; j < n; j++) {                 if (q == v[j]) {                   q--;                   y = 1;                   break;                 }               }               if (!y) break;             }             mid = q;           }           x--;         }       }       for (int j = m - 1; j >= 0; j--) {         if (mid & (1LL << j)) {           cout << 1;         } else           cout << 0;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int LIM = 100005;   long long power(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) {         res = res * x % mod;       }       x = x * x % mod;       n >>= 1;     }     return (res % mod);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 0;     cin >> t;     while (t--) {       long long n = 0, x = 0, y = 0;       cin >> n >> x >> y;       vector<long long> v;       long long dif = y - x;       long long c = n - 1;       long long d = 0;       for (c = n - 1; c >= 1; c--) {         if (dif % c == 0) {           d = dif / c;           break;         }       }       for (long long i = x; i <= y; i += d) {         v.push_back(i);         n--;       }       long long now = x - d;       for (; n > 0;) {         if (now <= 0)           break;         else {           v.push_back(now);           now -= d;           n--;         }       }       now = y + d;       for (; n > 0;) {         if (now <= 0)           break;         else {           v.push_back(now);           now += d;           n--;         }       }       sort(v.begin(), v.end());       for (long long i = 0; i < v.size(); i++) {         cout << v[i] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, s, x, k, ans = 0, ch = 0;     cin >> n >> s;     s = 8 * s;     vector<long long int> vec(n);     vector<pair<long long int, long long int>> dat;     for (long long int i = 0; i < n; i++) cin >> vec[i];     sort(vec.begin(), vec.end());     dat.push_back(make_pair(vec[0], 1));     x = vec[0];     for (long long int i = 1; i < n; i++) {       if (vec[i] != x) {         dat.push_back(make_pair(vec[i], 1));         x = vec[i];       } else {         dat[dat.size() - 1].second++;       }     }     while (1) {       k = 0;       while (pow(2, k) < dat.size() - ch) k++;       k = n * k;       if (k <= s) break;       ch++;     }     x = 0;     for (long long int i = 0; i < ch; i++) x = x + dat[i].second;     ans = x;     for (long long int i = 0; i < ch; i++) {       x = x - dat[ch - i - 1].second + dat[dat.size() - i - 1].second;       if (x < ans) ans = x;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e6;   const int inf = (1ll << 31) - 1;   int p[maxn], l[maxn];   int n;   pair<pair<int, int>, int> e[maxn];   pair<int, int> st[maxn];   int sum[maxn], answer[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &p[i], &l[i]);     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; ++i) {       int l, r;       scanf( %d%d , &l, &r);       l--;       r--;       e[i] = make_pair(make_pair(l, r), i);     }     sort(e, e + m);     reverse(e, e + m);     int ei = 0, stn = 0;     for (int i = n - 1; i >= 0; --i) {       int end = p[i] + l[i];       while (stn > 0 && st[stn - 1].first <= p[i] + l[i]) {         end = max(end, st[stn - 1].second);         --stn;       }       st[stn++] = make_pair(p[i], end);       sum[stn - 1] = 0;       if (stn > 1) sum[stn - 1] += sum[stn - 2] + st[stn - 2].first - end;       while (ei < m && e[ei].first.first == i) {         int pos = lower_bound(st, st + stn, make_pair(p[e[ei].first.second], inf),                               greater<pair<int, int> >()) -                   st;         answer[e[ei].second] = sum[stn - 1] - sum[pos];         ei++;       }     }     for (int i = 0; i < m; ++i) printf( %d n , answer[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int cmp(double x, double y = 0, double tol = 1e-9) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   int main() {     int n;     double a, d, t0, vm, t_vm, def, last = 0;     scanf( %d %lf %lf , &n, &a, &d);     def = sqrt(2 * d / a);     for (int i = 0; i < n; ++i) {       scanf( %lf %lf , &t0, &vm);       t_vm = vm / a;       if (t_vm < def)         t_vm += (d - .5 * a * t_vm * t_vm) / vm;       else         t_vm = def;       last = max(t_vm + t0, last);       printf( %.10lf n , last);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double pa[2020], pb[2020], pab[2020];   int n, a, b;   double dp[2020];   int opt[2020];   pair<int, int> solve(double mida, double midb) {     dp[0] = 0;     opt[0] = 0;     for (int i = 1; i <= n; i++) {       double& d = dp[i];       int& o = opt[i];       d = dp[i - 1];       o = 0;       if (d < dp[i - 1] + pa[i] - mida) {         d = dp[i - 1] + pa[i] - mida;         o = 1;       }       if (d < dp[i - 1] + pb[i] - midb) {         d = dp[i - 1] + pb[i] - midb;         o = 2;       }       if (d < dp[i - 1] + pab[i] - mida - midb) {         d = dp[i - 1] + pab[i] - mida - midb;         o = 3;       }     }     pair<int, int> ans = make_pair(0, 0);     for (int i = 1; i <= n; i++) {       if (opt[i] & 1) {         ans.first++;       }       if (opt[i] > 1) {         ans.second++;       }     }     return ans;   }   int main() {     scanf( %d %d %d , &n, &a, &b);     for (int i = 1; i <= n; i++) {       scanf( %lf , &pa[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %lf , &pb[i]);     }     for (int i = 1; i <= n; i++) {       pab[i] = pa[i] + pb[i] - pa[i] * pb[i];     }     double lowa = 0, higha = 1;     double lowb = 0, highb = 1;     for (int it = 0; it < 100; it++) {       double mida = (lowa + higha) / 2;       lowb = 0;       highb = 1;       for (int itb = 0; itb < 100; itb++) {         double midb = (lowb + highb) / 2;         auto ans = solve(mida, midb);         if (ans.second > b) {           lowb = midb;         } else {           highb = midb;         }       }       auto ans = solve(mida, highb);       if (ans.first > a) {         lowa = mida;       } else {         higha = mida;       }     }     auto ret = solve(higha, highb);     printf( %.10lf n , dp[n] + lowa * a + lowb * b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char IO;   inline long long rd() {     long long res = 0, f = 1;     while (IO = getchar(), IO < 48 || IO > 57)       if (IO ==  - ) f = 0;     do res = (res << 3) + (res << 1) + (IO ^ 48);     while (IO = getchar(), IO >= 48 && IO <= 57);     if (f) return res;     return -res;   }   const long long P = 1e9 + 7, M = 1e5 + 5;   long long fac[M], pw[M], inv[M];   char str[M];   long long Pow(long long a, long long b) {     long long res = 1;     for (; b; b >>= 1, a = a * a % P)       if (b & 1) res = res * a % P;     return res;   }   void init() {     fac[0] = pw[0] = 1;     for (long long i = 1, iend = M - 5; i <= iend; ++i) {       fac[i] = fac[i - 1] * i % P;       pw[i] = pw[i - 1] * 10 % P;     }     inv[M - 5] = Pow(fac[M - 5], P - 2);     for (long long i = M - 5, iend = 1; i >= iend; --i)       inv[i - 1] = inv[i] * i % P;   }   long long C(long long n, long long m) {     if (n < 0 || m < 0 || n < m) return 0;     return fac[n] * inv[m] % P * inv[n - m] % P;   }   int main() {     init();     long long n = rd(), m = rd(), s = 0, ans = 0;     scanf( %s , str + 1);     for (long long i = n, iend = 1; i >= iend; --i) {       ans = (ans + (s + C(i - 1, m) * pw[n - i]) * (str[i] -  0 ) % P) % P;       s = (s + C(i - 2, m - 1) * pw[n - i] % P);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int n, q[N], top1, top2;   struct ky {     int x, y;     long long w, val;     bool operator<(const ky& p) const { return x < p.x; }   } a[N];   long long f[N], ans;   inline double slope(const int x, const int y) {     return a[x].x == a[y].x ? 1e18                             : (double)(1.0 * (f[x] - f[y])) / (a[x].x - a[y].x);   }   inline long long cal(const int x, const int y) {     return f[y] - (0ll + a[y].x) * a[x].y + a[x].val;   }   template <class I>   inline void ckMax(I& p, I q) {     p = (p > q ? p : q);   }   int main() {     scanf( %d , &n);     register int i;     for (i = 1; i <= n; ++i)       scanf( %d%d%lld , &a[i].x, &a[i].y, &a[i].w),           a[i].val = (0ll + a[i].x) * a[i].y - a[i].w;     std::sort(a + 1, a + 1 + n), f[1] = a[1].val, q[top1 = top2 = 1] = 0;     for (i = 1; i <= n; ++i) {       while (top1 < top2 && slope(q[top1], q[top1 + 1]) >= a[i].y) ++top1;       f[i] = cal(i, q[top1]), ckMax(ans, f[i]);       while (top1 < top2 && slope(q[top2 - 1], q[top2]) < slope(q[top2], i))         --top2;       q[++top2] = i;     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int lim = 10;   char ch[11];   int i, j, k, n, m, a[21], t;   int main() {     scanf( %d , &n);     memset(a, 0, sizeof(a));     for (i = 1; i <= n; i++) {       scanf( %s%d , ch, &k);       if (ch[0] ==  & ) {         for (j = 0; j < lim; j++) {           t = ((k >> j) & 1);           if (!t) a[j] = 2;         }       }       if (ch[0] ==  | ) {         for (j = 0; j < lim; j++) {           t = ((k >> j) & 1);           if (t) a[j] = 3;         }       }       if (ch[0] ==  ^ ) {         for (j = 0; j < lim; j++) {           t = ((k >> j) & 1);           if (t) a[j] ^= 1;         }       }     }     puts( 3 );     for (k = i = 0; i < lim; i++) k += ((a[i] & 1) << i);     printf( ^ %d n , k);     for (k = i = 0; i < lim; i++)       if (a[i] != 2) k += (1 << i);     printf( & %d n , k);     for (k = i = 0; i < lim; i++)       if (a[i] == 3) k += (1 << i);     printf( | %d n , k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     int fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     x *= fl;   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   const int N = 200005;   int T, n, m;   vector<int> edge[N];   int main() {     for (read(T); T; T--) {       read(n, m);       for (int i = 1; i <= n; i++) edge[i].clear();       vector<int> deg(n + 1), level(n + 1, 1);       for (int i = 1; i <= m; i++) {         int u, v;         read(u, v);         edge[u].emplace_back(v);         deg[v]++;       }       vector<int> ans;       for (int i = 1; i <= n; i++) {         if (level[i] == 3) {           ans.emplace_back(i);           continue;         }         for (auto &to : edge[i]) level[to] = max(level[to], level[i] + 1);       }       printf( %d n , (int)ans.size());       for (auto &k : ans) printf( %d  , k);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   template <typename T>   void scan(T &x) {     x = 0;     bool _ = 0;     T c = getchar();     _ = c == 45;     c = _ ? getchar() : c;     while (c < 48 || c > 57) c = getchar();     for (; c < 48 || c > 57; c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);     x = _ ? -x : x;   }   template <typename T>   void printn(T n) {     bool _ = 0;     _ = n < 0;     n = _ ? -n : n;     char snum[65];     int i = 0;     do {       snum[i++] = n % 10 + 48;       n /= 10;     } while (n);     --i;     if (_) putchar(45);     while (i >= 0) putchar(snum[i--]);   }   template <typename First, typename... Ints>   void scan(First &arg, Ints &...rest) {     scan(arg);     scan(rest...);   }   template <typename T>   void print(T n) {     printn(n);     putchar(10);   }   template <typename First, typename... Ints>   void print(First arg, Ints... rest) {     printn(arg);     putchar(32);     print(rest...);   }   using namespace std;   using ll = long long;   const int MM = 505;   int n;   ll a[MM], ans;   int main() {     scan(n);     for (int i = 0; i < n; i++) {       scan(a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j <= i; j++) {         for (int k = 0; k <= j; k++) {           ans = max(ans, a[i] | a[j] | a[k]);         }       }     }     print(ans);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void tk_input(vector<T> &arr) {     for (T &i : arr) cin >> i;   }   void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pq;     int sc = 0, ls = 0, ls_i = 0, f_i = n, l_i = -1;     for (int i = 0; i <= n - 1; i++) {       if (s[i] ==  W ) {         if ((ls > 0) && (f_i != n)) pq.push(pair<int, int>(ls, ls_i));         f_i = min(f_i, i);         l_i = max(l_i, i);         ls_i = i + 1;         ls = 0;       } else {         ls++;       }     }     while ((!pq.empty()) && (k > 0)) {       auto tp = pq.top();       pq.pop();       for (int i = tp.second; i <= tp.first + tp.second - 1; i++) {         if (k == 0) break;         s[i] =  W ;         k--;       }     }     for (int i = f_i - 1; i >= 0; i--) {       if (k == 0) break;       s[i] =  W ;       k--;     }     if (l_i != -1) {       for (int i = l_i + 1; i <= n - 1; i++) {         if (k == 0) break;         s[i] =  W ;         k--;       }     }     sc += (s[0] ==  W );     for (int i = 1; i <= n - 1; i++) {       sc += ((s[i] ==  W ) * (1 + (s[i - 1] ==  W )));     }     cout << sc <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int _t;     cin >> _t;     while (_t--) solve();   }