malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   #pragma optimize( -O3 )       #define f first   #define s second   #define pb push_back   #define endl   n        map<vector<int>, int>ma;   map<vector<int>, bool>che;           int main() {    ios::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    queue<vector<int>>q;    vector<int>v;    int n;    cin>>n;        for(int i=1; i<=2*n; i++){     v.pb(i);    }    q.push(v);        ma[v]=0;    while(!q.empty()){     vector<int>u=q.front();     q.pop();     if(che[u]){      continue;     }     che[u]=1;     vector<int>v1;     vector<int>v2;     v1.resize(2*n);     v2.resize(2*n);     for(int i=0; i<u.size(); i++){      if(i%2==0){       v1[i+1]=u[i];      }      else{       v1[i-1]=u[i];      }     }     for(int i=0; i<n; i++){      v2[i+n]=u[i];     }     for(int i=n; i<2*n; i++){      v2[i-n]=u[i];     }          int d1=ma[u];     int d2=ma[v1];     int d3=ma[v2];     if(d2>1+d1 || !che[v1]){      ma[v1]=1+d1;      q.push(v1);     }     if(d3>1+d1 || !che[v2]){      ma[v2]=1+d1;      q.push(v2);     }         }    vector<int>vec;    for(int i=1; i<=2*n; i++){     int x;     cin>>x;     vec.pb(x);    }    if(!che[vec]){     cout<<-1;    }    else{     cout<<ma[vec];    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   int Power(int n, int x) {     int mul = n;     int res = 1;     while (x > 0) {       if (x & 1) res = 1ll * res * mul % MOD;       mul = 1ll * mul * mul % MOD;       x /= 2;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n + 1), pref(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(begin(a) + 1, end(a), greater<int>());     for (int i = 1; i <= n; i++) {       pref[i] = (a[i] + pref[i - 1]) % MOD;     }     vector<int> ans;     for (int k = 1; k <= n; k++) {       int res = 0;       for (int i = 0, j = 0; i <= n; i += k, j++) {         res = (res + (1ll * j * ((pref[min(i + k, n)] - pref[i]) % MOD) % MOD)) %               MOD;       }       ans.emplace_back(1ll * res * Power(n, MOD - 2) % MOD);     }     for (auto i : ans) {       if (i < 0) i += MOD;       cout << i <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool odd(int N) {     while (N < 0) {       N += 2;     }     return N % 2 == 1 ? true : false;   }   bool even(int N) {     while (N < 0) {       N += 2;     }     return N % 2 == 0 ? true : false;   }   int main() {     string s, t;     cin >> s >> t;     int N = s.size();     string result =   ;     int num = 0;     for (int i = 0; i != N; ++i) {       if (s[i] != t[i]) {         ++num;         if (num % 2) {           result += s[i];         } else {           result += t[i];         }       } else {         result += s[i];       }     }     if (even(num)) {       cout << result;     } else {       cout <<  impossible ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long x, y;   } A[100005];   int pos1[100005], pos2[100005], pos3[100005], pos4[100005];   int cmp1(int a, int b) { return A[a].x < A[b].x; }   int cmp2(int a, int b) { return A[a].x > A[b].x; }   int cmp3(int a, int b) { return A[a].y < A[b].y; }   int cmp4(int a, int b) { return A[a].y > A[b].y; }   int mark[100005];   int main() {     int i, n, k, p1, p2, p3, p4;     long long x1, x2, y1, y2;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; ++i) {       scanf( %lld%lld%lld%lld , &x1, &y1, &x2, &y2);       A[i].x = x1 + x2;       A[i].y = y1 + y2;       pos1[i] = pos2[i] = pos3[i] = pos4[i] = i;     }     sort(pos1 + 1, pos1 + n + 1, cmp1);     sort(pos2 + 1, pos2 + n + 1, cmp2);     sort(pos3 + 1, pos3 + n + 1, cmp3);     sort(pos4 + 1, pos4 + n + 1, cmp4);     int now = 0, tot;     long long ans = 1LL << 62;     for (p1 = 0; p1 <= k; ++p1) {       for (p2 = 0; p2 <= k; ++p2) {         for (p3 = 0; p3 <= k; ++p3) {           for (p4 = 0; p4 <= k; ++p4) {             now++;             tot = 0;             for (i = 1; i <= p1; ++i)               if (mark[pos1[i]] != now) mark[pos1[i]] = now, tot++;             for (i = 1; i <= p2; ++i)               if (mark[pos2[i]] != now) mark[pos2[i]] = now, tot++;             for (i = 1; i <= p3; ++i)               if (mark[pos3[i]] != now) mark[pos3[i]] = now, tot++;             for (i = 1; i <= p4; ++i)               if (mark[pos4[i]] != now) mark[pos4[i]] = now, tot++;             if (tot != k) continue;             long long max_x = -0x7fffffff, min_x = 0x7fffffff,                       max_y = -0x7fffffff, min_y = 0x7fffffff;             for (i = 1; i <= n; ++i)               if (mark[i] != now) {                 max_x = (max_x > A[i].x ? max_x : A[i].x);                 min_x = (min_x > A[i].x ? A[i].x : min_x);                 max_y = (max_y > A[i].y ? max_y : A[i].y);                 min_y = (min_y > A[i].y ? A[i].y : min_y);               }             long long x = max_x - min_x, y = max_y - min_y;             x = (2LL > x ? 2LL : x);             y = (2LL > y ? 2LL : y);             ans = (ans > x * y ? x * y : ans);           }         }       }     }     printf( %lld n , ans / 4);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using v2d = vector<vector<T> >;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   const int maxN = 1e3 + 10;   const int maxK = 1e3 + 10;   const long long mod = 998244353;   int n, k, a[maxN], lowbound[maxN], upbound[maxN];   long long dp[maxN][maxK], res = 0;   inline void normalize(long long &a) { a = (a % mod + mod) % mod; }   long long Try(int dist) {     long long r = 0;     for (int i = 1; i <= (int)(n); ++i) {       lowbound[i] = lowbound[i - 1];       while (a[i] - a[lowbound[i] + 1] >= dist) {         ++lowbound[i];       }       upbound[i] = upbound[i - 1];       while (a[i] - a[upbound[i] + 1] > dist) {         ++upbound[i];       }     }     for (int i = 1; i <= (int)(n); ++i) {       dp[i][1] = dp[i - 1][1] + 1;       for (int j = (int)(2); j <= (int)(k); ++j) {         dp[i][j] = dp[lowbound[i]][j - 1] + dp[i - 1][j];         if (dp[i][j] >= mod) {           dp[i][j] -= mod;         }       }     }     r = dp[n][k];     for (int i = 1; i <= (int)(n); ++i) {       dp[i][1] = dp[i - 1][1] + 1;       for (int j = (int)(2); j <= (int)(k); ++j) {         dp[i][j] = dp[upbound[i]][j - 1] + dp[i - 1][j];         if (dp[i][j] >= mod) {           dp[i][j] -= mod;         }       }     }     r -= dp[n][k];     if (r < 0) {       r += mod;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k;     for (int i = 1; i <= (int)(n); ++i) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= (int)(a[n] / (k - 1)); ++i) {       res += i * Try(i) % mod;       if (res >= mod) {         res -= mod;       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int maxn = 1e6 + 5;   const int mul = 9997;   long long h[maxn];   long long p[maxn];   string s;   vector<int> Z() {     int L = 0, R = 0;     vector<int> z(s.size());     z[0] = s.size();     for (int i = 1; i < s.size(); i++) {       if (i <= R) {         z[i] = z[i - L];       } else {         L = i;         if (i > R) {           R = i;         }         while (R < z[0] && s[R - L] == s[R]) R++;         z[i] = (R--) - L;       }     }     return z;   }   void go() {     int n, k;     cin >> n >> k;     cin >> s;     auto z = Z();     int f = 1;     int cnt = 0;     for (int i = 0; i < k; i++) {       int pos;       cin >> pos;       cnt += max(0, pos - f);       if (pos - f < 0 && z[z.size() - f + pos] < f - pos) {         cout << 0 <<   n ;         return;       }       f = pos + s.size();     }     cnt += n + 1 - f;     long long ans = 1;     for (int i = 0; i < cnt; i++) {       ans *= 26;       ans %= mod;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int c = 0;     int t;     if (!c) {       t = 1;     } else {       cin >> t;     }     while (t--) {       go();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     for (int u = 0; u < t; u++) {       long long int n;       cin >> n;       n = 2 * n;       long long int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       long long int b = a[(n / 2) - 1];       long long int c = a[(n / 2)];       cout << abs(b - c) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   const int D = 200 + 1;   int n;   pair<int, int> a[N];   int cn[N];   int cd[D];   long long sum, ans;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       cn[a[i].first]++;     }     for (int i = 0; i < n; i++) {       cin >> a[i].second;       sum += a[i].second;     }     sort(a, a + n);     int it = 0;     ans = (long long)1e18;     for (int i = 0; i < N && it < n; i++) {       if (a[it].first > i) continue;       int ln = 0;       long long ls = 0;       for (int j = 0; j < D; j++) {         int cnt = min(cd[j], max((it - ln) - cn[i] + 1, 0));         ln += cnt, ls += j * cnt;       }       while (it < n && a[it].first == i) {         sum -= a[it].second;         cd[a[it].second]++;         it++;       }       ans = min(ans, ls + sum);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v[100086];   int x, y;   int deg[100086], mxd;   int ans[100086 << 3][2], cnt;   void dfs(int i, int fa, int val) {     int x = deg[i] - (i != 1);     int fin = val - 1;     ans[++cnt][0] = i, ans[cnt][1] = val;     for (int j = 0; j < v[i].size(); j++) {       if (v[i][j] == fa) continue;       --x;       if (val + 1 > mxd) val = fin - x - 1, ans[++cnt][0] = i, ans[cnt][1] = val;       dfs(v[i][j], i, ++val);       ans[++cnt][0] = i, ans[cnt][1] = val;     }     if ((i ^ 1) && val != fin) ans[++cnt][0] = i, ans[cnt][1] = fin;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       v[x].push_back(y), v[y].push_back(x);       deg[x]++, deg[y]++;     }     for (int i = 1; i <= n; i++) mxd = max(mxd, deg[i]);     dfs(1, 0, 0);     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++) printf( %d %d n , ans[i][0], ans[i][1]);   }
#include <bits/stdc++.h>   using namespace std;   long long n, arr[100003], pre[100003], suf[100003];   int bitidx;   bool cmp(long long a, long long b) {     return ((a >> bitidx) & 1) < ((b >> bitidx) & 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     pre[0] = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       pre[i + 1] = pre[i] ^ arr[i];     }     suf[0] = 0;     for (int i = 0; i < n; i++) suf[i + 1] = suf[i] ^ arr[n - i - 1];     sort(suf, suf + n + 1);     long long mx = 0;     for (int k = 0; k <= n; k += 1) {       int st = 0, en = n;       for (int i = 40; i >= 0; i -= 1) {         int bit = (pre[k] >> i) & 1;         bitidx = i;         int pos = lower_bound(suf + st, suf + en + 1, (1LL << i), cmp) - suf;         if (pos > en) continue;         if (!bit)           st = pos;         else           en = pos - 1;       }       mx = max(mx, pre[k] ^ suf[st]);     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> gra[28];   char s[100005], re[100005];   int main() {     int i, l, j, st, l1;     while (scanf( %s , &s) == 1) {       l = strlen(s);       l1 = 0;       for (i = 0; i < 26; i++) gra[i].clear();       for (i = 0; i < l; i++) gra[s[i] -  a ].push_back(i);       st = -1;       for (i = 25; i >= 0; i--)         if (gra[i].size() > 0) {           for (j = 0; j < gra[i].size(); j++)             if (gra[i][j] > st) re[l1++] =  a  + i, st = gra[i][j];         }       re[l1] =   0 ;       printf( %s n , re);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int A[200], B[200], D[200];   map<int, vector<int>> MM;   set<int> S;   struct mat {     signed long long v[150][3] = {};   };   struct vec {     signed long long v[3] = {};   };   void print(mat a, int n) {     int x, y;     for (x = 0; x < n; x++) {       (void)printf( %d:  , x);       for (y = 0; y < n; y++)         (void)printf( %d , (a.v[x][y / 64] & (1LL << (y % 64))) != 0);       (void)printf(  n );     }   }   void print(vec a, int n) {     int i;     for (i = 0; i < n; i++)       (void)printf( %d , (a.v[i / 64] & (1LL << (i % 64))) != 0);     (void)printf(  n );   }   mat mult(mat a, mat b, int n) {     mat c, d;     int x, y, z;     for (x = 0; x < n; x++)       for (y = 0; y < n; y++)         if (b.v[y][x / 64] & (1LL << (x % 64))) c.v[x][y / 64] |= 1LL << (y % 64);     for (x = 0; x < n; x++)       for (y = 0; y < n; y++) {         signed long long v = 0;         for (z = 0; z < (n + 63) / 64; z++) v |= a.v[x][z] & c.v[y][z];         v = (v != 0);         d.v[x][y / 64] |= v << (y % 64);       }     return d;   }   mat init(int n) {     mat r;     int x;     for (x = 0; x < n; x++) r.v[x][x / 64] |= 1LL << (x % 64);     return r;   }   mat powm(mat a, int p, int n) {     mat r = init(n);     while (p) {       if (p % 2) r = mult(r, a, n);       a = mult(a, a, n);       p /= 2;     }     return r;   }   vec mult(mat a, vec b, int n) {     vec c;     int x, y;     for (x = 0; x < n; x++)       if (b.v[x / 64] & (1LL << (x % 64)))         for (y = 0; y < (n + 63) / 64; y++) c.v[y] |= a.v[x][y];     return c;   }   bool reachable(mat a, vec b) {     int x, y;     for (x = 0; x < 150; x++) {       vec c = mult(a, b, N);       b.v[0] |= c.v[0];       b.v[1] |= c.v[1];       b.v[2] |= c.v[2];     }     int n = N - 1;     return (b.v[n / 64] & (1LL << (n % 64))) != 0;   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> M;     for (i = 0; i < M; i++) {       cin >> A[i] >> B[i] >> D[i];       A[i]--;       B[i]--;       MM[D[i]].push_back(i);       S.insert(D[i]);     }     int cur = 0;     vec v;     mat m;     v.v[0] = 1;     for (auto& r : MM) {       v = mult(powm(m, r.first - cur, N), v, N);       cur = r.first;       for (auto& r2 : r.second) m.v[A[r2]][B[r2] / 64] |= 1LL << (B[r2] % 64);       if (reachable(m, v)) break;     }     if (!reachable(m, v)) return (void)printf( Impossible n );     int n = N - 1;     while ((v.v[n / 64] & (1LL << (n % 64))) == 0) {       v = mult(m, v, N);       cur++;       if (S.count(cur))         for (auto& r2 : MM[cur]) m.v[A[r2]][B[r2] / 64] |= 1LL << (B[r2] % 64);     }     cout << cur << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false);     for (i = 0; i < argc - 1; i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     long long int p = sqrt(n);     for (int i = 5; i <= p; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   string d2b(int n) {     string s;     for (int i = 31; i >= 0; i--) {       int k = n >> i;       if (k & 1)         s +=  1 ;       else         s +=  0 ;     }     return s;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int b2d(string n) {     string num = n;     long long int dec_value = 0;     long long int base = 1;     long long int len = num.length();     for (int i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test_case = 1;     cin >> test_case;     while (test_case--) {       int n, k;       cin >> n >> k;       int a[n];       for (long long i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       for (long long i = 1; i < n; i++) {         a[i] = k - a[i];       }       int temp = a[0];       for (long long i = 1; i < n; i++) {         a[i] = a[i] / temp;       }       int s = 0;       for (long long i = 1; i < n; i++) s += a[i];       cout << s << endl;     }   }
#include <bits/stdc++.h>   int *ej[100000], eo[100000];   long long *ew[100000];   void append(int i, int j, long long w) {     int o = eo[i]++;     if (o >= 2 && (o & o - 1) == 0) {       ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]);       ew[i] = (long long *)realloc(ew[i], o * 2 * sizeof *ew[i]);     }     ej[i][o] = j, ew[i][o] = w;   }   long long bb[60], b_;   int sz;   void add(long long b) {     int l;     b_ |= b;     for (l = 0; l < 60; l++)       if (b & 1LL << l) {         if (bb[l] & 1LL << l)           b ^= bb[l];         else {           bb[l] = b, sz++;           return;         }       }   }   long long xx[100000];   char visited[100000];   int kk[60], cnt;   void dfs(int p, int i, long long x) {     int o, l;     if (visited[i]) {       add(xx[i] ^ x);       return;     }     xx[i] = x, visited[i] = 1, cnt++;     for (l = 0; l < 60; l++)       if (x & 1LL << l) kk[l]++;     for (o = eo[i]; o--;) {       int j = ej[i][o];       long long w = ew[i][o];       if (j != p) dfs(i, j, x ^ w);     }   }   int main() {     int n, m, i, j, ans;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       ej[i] = (int *)malloc(2 * sizeof *ej[i]);       ew[i] = (long long *)malloc(2 * sizeof *ew[i]);     }     while (m--) {       long long w;       scanf( %d%d%lld , &i, &j, &w), i--, j--;       append(i, j, w), append(j, i, w);     }     ans = 0;     for (i = 0; i < n; i++)       if (!visited[i]) {         int l, p;         memset(bb, 0, 60 * sizeof *bb), b_ = 0, sz = 0;         memset(kk, 0, 60 * sizeof *kk);         cnt = 0;         dfs(-1, i, 0);         p = 1;         for (l = 0; l < 60; l++) {           int k;           if (b_ & 1LL << l)             k = (long long)cnt * (cnt - 1) / 2 % 1000000007 *                 ((1LL << sz - 1) % 1000000007) % 1000000007;           else             k = (long long)kk[l] * (cnt - kk[l]) % 1000000007 *                 ((1LL << sz) % 1000000007) % 1000000007;           ans = (ans + (long long)k * p) % 1000000007;           p = p * 2 % 1000000007;         }       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T min(T a, T b, T c, T d) {     return min(a, min(b, min(c, d)));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   T max(T a, T b, T c, T d) {     return max(a, max(b, max(c, d)));   }   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     return (a.first > b.first || (a.first == b.first && a.second >= b.second));   }   long long GCD(long long a, long long b) { return (a % b) ? GCD(b, a % b) : b; }   int f[7][100007];   int main() {     int n, a, b, c;     scanf( %d%d%d%d , &n, &a, &b, &c);     --n;     f[0][0] = 0;     f[1][0] = f[2][0] = 1000000000LL;     for (int i = (1); i <= (n); ++i) {       f[0][i] = min(f[2][i - 1] + b, f[1][i - 1] + a);       f[1][i] = min(f[2][i - 1] + c, f[0][i - 1] + a);       f[2][i] = min(f[1][i - 1] + c, f[0][i - 1] + b);     }     cout << min(f[0][n], f[1][n], f[2][n]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long tests = 1;     cin >> tests;     while (tests--) {       long long n, k;       cin >> n >> k;       map<pair<long long, long long>, long long> timers;       set<pair<long long, long long> > bombsx, bombsy;       for (long long i = 1; i <= n; ++i) {         long long x, y, t;         cin >> x >> y >> t;         bombsx.insert({x, y});         bombsy.insert({y, x});         timers[{x, y}] = t;       }       vector<long long> min_time;       queue<pair<long long, long long> > nodes;       while (bombsx.size()) {         auto itr = bombsx.begin();         long long min_timer = timers[{itr->first, itr->second}];         nodes.push({itr->first, itr->second});         bombsx.erase({itr->first, itr->second});         bombsy.erase({itr->second, itr->first});         while (nodes.size()) {           long long x = nodes.front().first, y = nodes.front().second;           nodes.pop();           itr = bombsx.lower_bound({x, y - k});           while (itr != bombsx.end() and itr->first == x and                  abs(itr->second - y) <= k) {             min_timer = min(min_timer, timers[{itr->first, itr->second}]);             auto aux = itr;             itr++;             nodes.push({aux->first, aux->second});             bombsx.erase({aux->first, aux->second});             bombsy.erase({aux->second, aux->first});           }           itr = bombsy.lower_bound({y, x - k});           while (itr != bombsy.end() and itr->first == y and                  abs(itr->second - x) <= k) {             min_timer = min(min_timer, timers[{itr->second, itr->first}]);             auto aux = itr;             itr++;             nodes.push({aux->second, aux->first});             bombsy.erase({aux->first, aux->second});             bombsx.erase({aux->second, aux->first});           }         }         min_time.push_back(min_timer);       }       sort(min_time.begin(), min_time.end());       long long ans = min_time.size() - 1;       n = min_time.size();       for (long long i = 0; i < n; ++i) {         ans = min(ans, max(min_time[i], n - 2ll - i));       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double PI = acos(-1.0);   const long long int mod = 1e9 + 7;   const int MAXN = 1e6 + 5;   void cp() {     int n, k;     string s;     cin >> n >> k >> s;     vector<pair<int, int> > group;     int l = 0, r = 0;     while (l < n) {       while (l < n && s[l] ==  L ) l++;       if (l >= n) break;       r = l;       while (r + 1 < n && s[r + 1] ==  W ) r++;       group.push_back({l, r});       l = r + 1;     }     vector<pair<int, int> > diff;     for (int i = 0; i < ((int)group.size()) - 1; i++) {       int d = group[i + 1].first - group[i].second - 1;       diff.push_back({d, i});     }     sort(diff.rbegin(), diff.rend());     while (k > 0 && !diff.empty()) {       pair<int, int> last = diff.back();       diff.pop_back();       int can = min(last.first, k);       k -= can;       for (int i = group[last.second].second + 1;            i < group[last.second + 1].first && can > 0; i++, can--)         s[i] =  W ;     }     if (k > 0) {       int pos = -2;       for (int i = 0; i < n; i++)         if (s[i] ==  W ) pos = i;       pos++;       if (pos >= 0 && pos < n)         for (int i = pos; i < n && k > 0; i++)           if (s[i] ==  L ) s[i] =  W , k--;     }     if (k > 0 && s[0] ==  L ) {       int pos = n;       for (int i = 0; i < n && pos == n; i++)         if (s[i] ==  W ) pos = i;       pos--;       if (pos >= 0) {         for (int i = pos; i >= 0 && k > 0; i--)           if (s[i] ==  L ) s[i] =  W , k--;       }     }     int score = 0;     for (int i = 0; i < n; i++) {       score += (s[i] ==  W );       if (i - 1 >= 0 && s[i] ==  W  && s[i - 1] ==  W ) score++;     }     cout << score <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     cin >> t;     while (t--) {       cp();     }     return 0;   }