malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, ans, flag;   int a[100005], b[100005], xb[100005];   void solve() {     int i, j, ma;     ans = -1;     b[1] = xb[1] = 0;     for (i = 2; i <= n; i++) {       ma = 0;       flag = 0;       j = i - 1;       while (a[j] < a[i] && j) {         if (!b[j]) {           flag = 1;           break;         }         if (b[j] > ma) ma = b[j];         j = xb[j];       }       if (!flag)         b[i] = ma + 1;       else         b[i] = 0;       xb[i] = j;     }     for (i = 1; i <= n; i++) {       if (ans < b[i]) ans = b[i];     }   }   int main() {     int i, j;     while (~scanf( %d , &n)) {       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       solve();       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1 << 20;   int INF = 1000000001;   int a[SIZE], ops[SIZE];   int h, g;   int qq[24], qn;   int pull(int id) {     int tmp = a[id];     a[id] = 0;     qn = 0;     qq[qn++] = id;     while (id * 2 < (1 << h) && a[id] < max(a[id << 1], a[(id << 1) | 1])) {       if (a[id << 1] > a[(id << 1) | 1]) {         swap(a[id << 1], a[id]);         id <<= 1;       } else {         swap(a[(id << 1) | 1], a[id]);         id = (id << 1) | 1;       }       qq[qn++] = id;     }     if (id < (1 << g)) {       for (int i = qn - 1; i > 0; i--) {         a[qq[i]] = a[qq[i - 1]];       }       a[qq[0]] = tmp;       return 0;     }     return tmp;   }   void solve() {     scanf( %d%d , &h, &g);     long long an = 0;     for (int i = 1; i < (1 << h); i++) {       scanf( %d , &a[i]);       an += a[i];     }     int need = 0;     for (int i = 1; i < (1 << g); i++) {       while (1) {         int v = pull(i);         if (v) {           an -= v;           ops[need++] = i;         } else           break;       }     }     printf( %lld n , an);     for (int i = 0; i < need; i++) printf( %d%c , ops[i],    n [i == need - 1]);   }   int main() {     int T;     scanf( %d , &T);     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mox = 1e6 + 9;   long long ha[mox];   long long mod = 1e9 + 7;   long long d[mox];   bool visit[mox];   long long ma[mox];   bool visit2[mox];   long long ta(long long a, long long b) {     long long ans = 1;     long long c = a;     while (b) {       if (b % 2) {         ans = (ans * c) % mod;       }       c = (c * c) % mod;       b /= 2;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     string t;     cin >> t;     d[0] = 1;     for (long long i = 0; i < t.size(); i++) {       long long x = (d[i] * (t[i] -  a  + 1)) % mod;       ha[i] = (ha[i - 1] + x) % mod;       d[i + 1] = (d[i] * 27) % mod;     }     long long ans = 0;     for (long long i = t.size() - 1; i >= 1; i--) {       long long x = (ha[t.size() - 1] - ha[i - 1] + mod) % mod;       long long y = ta(d[i], mod - 2);       x = (x * y) % mod;       if (x == ha[t.size() - 1 - i]) {         visit[i] = 1;       }     }     for (long long i = 0; i < m; i++) {       cin >> ma[i];       visit2[ma[i]] = 1;     }     for (long long i = 1; i < m; i++) {       if (ma[i] - ma[i - 1] < t.size()) {         if (visit[ma[i] - ma[i - 1]] == 0) {           cout << 0;           exit(0);         }       }     }     long long x = 0;     long long o = 0;     for (long long i = 1; i <= n; i++) {       if (visit2[i] == 1) {         x = i + t.size() - 1;       }       if (i > x) {         o += 1;       }     }     long long w = 1;     for (long long i = 0; i < o; i++) {       w = (w * 26) % mod;     }     cout << w;   }
#include <bits/stdc++.h>   using namespace std;   void solve_test() {     string s;     cin >> s;     int n = int(s.length());     int total = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  + )         total++;       else         total--;       if (total < 0) {         total++;         ans += i + 1;       }     }     cout << ans + n <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1;     cin >> tests;     while (tests--) solve_test();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int sum[maxn], op[maxn];   int main() {     int n, l = 0, r = 0, ans = 0, minn = 100;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  ( ) {         op[i + 1] = 1;         sum[i + 1] = sum[i] + 1;         l++;       } else {         op[i + 1] = 0;         sum[i + 1] = sum[i] - 1;         r++;       }     }     if (n & 1 == 1 || (abs(l - r) > 2) || (sum[n] == 0) ||         (*min_element(sum + 1, sum + 1 + n) < -2) ||         (*min_element(sum + 1, sum + 1 + n) < 0 && sum[n] != -2)) {       printf( 0 n );       exit(0);     }     if (sum[n] == -2) {       for (int i = 1; i <= n; i++) {         if (op[i] == 0 && sum[i] < 0) {           ans++;           break;         } else if (op[i] == 0 && sum[i] >= 0)           ans++;       }     }     if (sum[n] == 2) {       for (int i = n; i >= 1; i--) {         if (sum[i] >= 2)           minn = i;         else           break;       }       minn = max(minn, 2);       for (int i = minn; i <= n; i++) {         if (op[i] == 1) ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int fr[200002];   int arr[200002];   bool check(int cati) {     int qq = 0;     for (int i = 1; i <= 200000; ++i) qq += fr[i] / cati;     if (qq >= k) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> arr[i], fr[arr[i]]++;     int b = 1;     int e = n;     int ans = 1;     while (b <= e) {       int mid = (b + e) / 2;       if (check(mid))         ans = mid, b = mid + 1;       else         e = mid - 1;     }     int qa = 0;     for (int i = 1; i <= 200000; ++i) {       if (qa == k) return 0;       while (fr[i] >= ans && qa < k) cout << i <<    , ++qa, fr[i] -= ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v;   map<int, long long> dp;   long long power(int a, long long b) {     long long res = 1, base = a;     while (b > 0) {       if (b % 2) {         res *= base;         res %= (1000 * 1000 * 1000 + 7);       }       base *= base;       base %= (1000 * 1000 * 1000 + 7);       b /= 2;     }     return res;   }   long long compute(int g) {     if (g == 1) {       return 1;     }     if (dp.find(g) != dp.end()) {       return dp[g];     }     long long val = power(2, g - 1);     int i;     for (i = 0; i < v.size(); i++) {       if (v[i] >= g) {         break;       }       if (g % v[i] == 0) val -= compute(v[i]);     }     dp[g] = val;     dp[g] %= (1000 * 1000 * 1000 + 7);     dp[g] += (1000 * 1000 * 1000 + 7);     dp[g] %= (1000 * 1000 * 1000 + 7);     return dp[g];   }   int main() {     std::ios::sync_with_stdio(false);     int x, y, val1, i;     cin >> x >> y;     if (y % x) {       cout << 0 << endl;     } else {       y /= x;       for (i = 1; i * i <= y; i++) {         if (y % i == 0) {           v.push_back(i);           if (y / i != i) v.push_back(y / i);         }       }       sort(v.begin(), v.end());       cout << compute(y);     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int n, m;   vector<int> v[4000000];   char g[4000000];   int inline make(int i, int j) { return i * m + j; }   void solve() {     cin >> n >> m;     int cnt = 0;     for (int i = 0; i < n; i++) {       char buf[2001];       cin >> buf;       for (int j = 0; j < m; j++) {         g[make(i, j)] = buf[j];         if (g[make(i, j)] ==  . ) {           cnt++;           if (i > 0 && g[make(i - 1, j)] ==  . ) {             v[make(i, j)].push_back(make(i - 1, j));             v[make(i - 1, j)].push_back(make(i, j));           }           if (j > 0 && g[make(i, j - 1)] ==  . ) {             v[make(i, j)].push_back(make(i, j - 1));             v[make(i, j - 1)].push_back(make(i, j));           }         }       }     }     queue<int> q;     for (int i = 0; i < n * m; i++)       if (int((v[i]).size()) == 1) q.push(i);     while (!q.empty()) {       int i = q.front();       q.pop();       if (int((v[i]).size()) == 1) {         int j = v[i][0], x = ((i) > (j) ? (j) : (i)), y = ((i) > (j) ? (i) : (j));         if (x / m == y / m) {           g[x] =  < ;           g[y] =  > ;         } else {           g[x] =  ^ ;           g[y] =  v ;         }         for (int k = 0; k < int((v[j]).size()); k++) {           int l = v[j][k];           for (int h = 0; h < int((v[l]).size()); h++) {             if (v[l][h] == j) {               v[l].erase(v[l].begin() + h);               break;             }           }           if (int((v[l]).size()) == 1) q.push(l);         }         v[i].clear();         v[j].clear();         cnt -= 2;       }     }     if (cnt) {       cout <<  Not unique ;       return;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << g[make(i, j)];       cout <<   n ;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683};     vector<int> vis;     for (int i = 0; i < (1 << 10); i++) {       int sum = 0;       for (int j = 0; j < 10; j++) {         if (i & (1 << j)) {           sum += v[j];         }       }       vis.push_back(sum);     }     sort(vis.begin(), vis.end());     int q;     cin >> q;     while (q--) {       int x;       cin >> x;       cout << *lower_bound(vis.begin(), vis.end(), x) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   int main() {     int T;     scanf( %d , &T);     while (T--) {       int l, r;       scanf( %d%d , &l, &r);       if (l * 2 > r) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, a[100000], b[1000000], i, s, j, x, y;   int main() {     cin >> n >> m;     if (n == m) {       cout <<  0  << endl;       return 0;     }     while (n > 0) {       a[i] = n % 2;       n = n / 2;       i++;     }     while (m > 0) {       b[x] = m % 2;       m = m / 2;       x++;     }     while (a[x] == b[x]) {       x--;     }     y = 1;     for (j = 0; j <= x; j++) {       y *= 2;     }     cout << y - 1 << endl;   }
#include<bits/stdc++.h>   #define LL long long   using namespace std;   int n,m,edge_t=0,sum=0,rt_t=0;      bool tyl_jyy=0;      LL t,ans=0;   int rt[200002]={};   vector<int> vec[200002];   set<int> s;   struct aaa   {    int x,y,val,u;   }e[200002];   template<class T>void read(T &x)   {    x=0;int f=0;char ch=getchar();    while(ch< 0  || ch> 9 )f|=(ch== - ),ch=getchar();    while(ch>= 0  && ch<= 9 )x=(x<<3)+(x<<1)+(ch^48),ch=getchar();    x=f? -x:x;return ;   }   inline bool cmp(aaa a,aaa b)   {    return a.val<b.val? 1:0;   }   inline void add_edge(int x,int y,int z,int i)   {    e[i]=(aaa){x,y,z,0},vec[x].push_back(y),vec[y].push_back(x);   }   inline void dfs(int x,int y)   {    int i,j;s.erase(x),rt[x]=y;    set<int>::iterator it;    for(int i=1;;++i)    {     it=s.lower_bound(i);     if(it==s.end())return ;     i=(*it),j=lower_bound(vec[x].begin(),vec[x].end(),i)-vec[x].begin();     if(j==vec[x].size() || vec[x][j]>i)dfs(i,y);    }    /*for(set<int>::iterator it=s.begin();;)    {     v=(*it),ok=((++it)==s.end()),i=lower_bound(vec[x].begin(),vec[x].end(),v)-vec[x].begin();     if(i==vec[x].size() || vec[x][i]>v)dfs(v,y);if(ok)return ;    }*/   }   inline void getroot(int x)   {    if(x==rt[x])return ;    getroot(rt[x]),rt[x]=rt[rt[x]];   }   int main()   {    read(n),read(m),t=(1LL*n*(n-1))/2-m;        //if(n==200000 && m==200000)tyl_jyy=1;        for(int i=1,x,y,z;i<=m;++i)read(x),read(y),read(z),sum^=z,add_edge(x,y,z,i);    for(int i=1;i<=n;++i)s.insert(i),sort(vec[i].begin(),vec[i].end());        //if(tyl_jyy)return 0&puts( ok );        for(int i=1;i<=n;++i)if(!rt[i])++rt_t,dfs(i,i);    sort(e+1,e+m+1,cmp);    for(int i=1,x,y;i<=m;++i)    {     x=e[i].x,y=e[i].y,getroot(x),getroot(y);     if(rt[x]==rt[y])continue;     rt[rt[x]]=rt[y],ans+=e[i].val,e[i].u=1;    }    if(n-rt_t==t)    {     for(int i=1;i<=n;++i)rt[i]=i;     for(int i=1,x,y;i<=m;++i)if(e[i].u)x=e[i].x,y=e[i].y,getroot(x),getroot(y),rt[rt[x]]=rt[y];     for(int i=1,x,y;i<=m;++i)      if(!e[i].u)      {       x=e[i].x,y=e[i].y,getroot(x),getroot(y);       if(rt[x]==rt[y])continue;       sum=min(sum,e[i].val);break;      }    }    else sum=0;    printf( %lld ,ans+sum);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   long int a[5001], b[5001];   long long ans[5001];   int main(void) {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] -= i;       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         ans[j] += abs(a[i] - b[j]);         if (j > 1) ans[j] = min(ans[j], ans[j - 1]);       }     cout << ans[n];   }
#include <bits/stdc++.h>   int main() {     long n, a, b;     scanf( %ld %ld %ld , &n, &a, &b);     std::vector<long> v(n, 1);     long current(1), sum(1);     for (long p = 1; p < n; p++) {       if (b > 0) {         current = sum + 1;         --b;       } else if ((p > 1) && (a > 0)) {         ++current, --a;       }       v[p] = current;       sum += current;     }     if ((a > 0) || (b > 0)) {       puts( -1 );     } else {       for (long p = 0; p < n; p++) {         printf( %ld  , v[p]);       };       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   long long ln, lk, lm;   long long dp[35][1005], tmp[1005];   int cnt = 0;   void init() {     dp[0][0] = 1;     tmp[0] = 1;     for (int i = 1; i <= 30; i++) {       dp[i][0] = 1;       for (int j = 1; j <= 1000; j++) {         for (int k = 0; k < j; k++) {           dp[i][j] += (tmp[k] * tmp[j - k - 1]) % 7340033;           dp[i][j] %= 7340033;         }       }       for (int j = 1; j <= 1000; j++) tmp[j] = 0;       tmp[0] = 1;       for (int j = 1; j <= 1000; j++) {         for (int k = 0; k <= j; k++) {           tmp[j] += (dp[i][k] * dp[i][j - k]) % 7340033;           tmp[j] %= 7340033;         }       }     }   }   int main() {     init();     int q;     scanf( %d , &q);     while (q--) {       scanf( %d%d , &n, &k);       if (k == 0)         puts( 1 );       else {         int id = 0;         while ((n & 1) && n > 1) {           n >>= 1;           id++;         }         printf( %lld n , dp[id][k]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       if (a[0] + a[1] <= a[n - 1]) {         cout <<  1 2   << n << endl;       } else         cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   void ask(int r1, int c1, int r2, int c2) {     cout <<  ?   << r1 <<     << c1 <<     << r2 <<     << c2 <<   n ;     cout.flush();   }   bool ans() {     string ans;     cin >> ans;     return ans ==  YES ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int steps = 0;     int rx = 1, ry = 1;     string pre =   ;     while (steps < n - 1) {       ask(rx + 1, ry, n, n);       bool sol = ans();       if (sol) {         pre +=  D ;         rx++;       } else {         pre +=  R ;         ry++;       }       steps++;     }     string suf =   ;     steps = 0;     rx = n, ry = n;     while (steps < n - 1) {       ask(1, 1, rx, ry - 1);       bool sol = ans();       if (sol) {         suf +=  R ;         ry--;       } else {         suf +=  D ;         rx--;       }       steps++;     }     reverse(suf.begin(), suf.end());     cout <<  !   << (pre + suf) <<   n ;     cout.flush();   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, n, m, t, kk, tt = 0, l[5007], r[5007], fa[5007], type[5007],                                   ind[5007];   int y[5007] = {0}, qw[5007], tree[1000007], a1[5007], a2[5007], a3[5007],       a4[5007];   vector<int> q[5007];   vector<short> w[5007];   void get(int x1, int l, int r, int tl, int tr, int k) {     if (tree[k] == tt) return;     if (l >= tl && r <= tr) {       tree[k] = tt;       for (int i = l; i <= r; i++) w[x1].push_back(i);       return;     }     int m = (l + r) / 2;     if (tl <= m) get(x1, l, m, tl, tr, k << 1);     if (tr > m) get(x1, m + 1, r, tl, tr, (k << 1) + 1);   }   int sou(int x1) {     t = 0;     if (type[x1] == 0)       for (int j = 1; j <= q[x1].size(); j++) w[x1].push_back(q[x1][j - 1]);     else       get(x1, 1, m, q[x1][0], q[x1][1], 1);     for (int j = 1; j <= w[x1].size(); j++)       if (!qw[fa[w[x1][j - 1]]]) {         qw[fa[w[x1][j - 1]]] = 1;         if (y[fa[w[x1][j - 1]]] == 0 || sou(y[fa[w[x1][j - 1]]])) {           y[fa[w[x1][j - 1]]] = x1;           w[x1].clear();           return 1;         }       }     w[x1].clear();     return 0;   }   int main() {     scanf( %d%d , &n, &m);     kk = 1;     for (int i = 1; i <= m; i++) fa[i] = i;     int ans = 0, t3 = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &type[kk]);       if (type[kk] == 0) {         scanf( %d , &b);         for (int j = 1; j <= b; j++) {           scanf( %d , &c);           q[kk].push_back(c);         }         ind[kk] = i;         kk++;       } else if (type[kk] == 1) {         scanf( %d%d , &b, &c);         ind[kk] = i;         q[kk].push_back(b);         q[kk++].push_back(c);       } else {         scanf( %d%d%d , &b, &c, &d);         fa[c] = b;         fa[d] = b;         ans += 2;         a1[++t3] = b, a2[t3] = c, a3[t3] = d, a4[t3] = i;       }     }     for (int i = 1; i <= kk - 1; i++) {       tt++;       for (int j = 1; j <= m; j++) qw[j] = 0;       if (sou(i)) ans++;     }     printf( %d n , ans);     for (int i = 1; i <= t3; i++) {       fa[a1[i]] = 0;       fa[a2[i]] = 0;       fa[a3[i]] = 0;       int g = 0;       if (y[a1[i]] == 0) {         printf( %d %d n , a4[i], a1[i]);         printf( %d %d n , a4[i], a2[i]);         continue;       } else if (type[y[a1[i]]] == 0)         for (int j = 1; j <= q[y[a1[i]]].size(); j++) {           if (q[y[a1[i]]][j - 1] == a1[i]) g = 1;           if (q[y[a1[i]]][j - 1] == a2[i]) g = 2;           if (q[y[a1[i]]][j - 1] == a3[i]) g = 3;         }       else         for (int j = q[y[a1[i]]][0]; j <= q[y[a1[i]]][1]; j++) {           if (j == a1[i]) g = 1;           if (j == a2[i]) g = 2;           if (j == a3[i]) g = 3;         }       if (g == 1)         printf( %d %d n , ind[y[a1[i]]], a1[i]);       else         printf( %d %d n , a4[i], a1[i]);       if (g == 2)         printf( %d %d n , ind[y[a1[i]]], a2[i]);       else         printf( %d %d n , a4[i], a2[i]);       if (g == 3)         printf( %d %d n , ind[y[a1[i]]], a3[i]);       else         printf( %d %d n , a4[i], a3[i]);     }     for (int i = 1; i <= m; i++)       if (y[i] && fa[i] == i) printf( %d %d n , ind[y[i]], i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char x[15];   int main() {     scanf( %s , x);     int lenx = strlen(x);     for (int i = lenx - 1; i >= 0; i--) {       int dig = x[i] -  0 ;       if (dig == 0)         printf( O-|-OOOO n );       else if (dig == 1)         printf( O-|O-OOO n );       else if (dig == 2)         printf( O-|OO-OO n );       else if (dig == 3)         printf( O-|OOO-O n );       else if (dig == 4)         printf( O-|OOOO- n );       else if (dig == 5)         printf( -O|-OOOO n );       else if (dig == 6)         printf( -O|O-OOO n );       else if (dig == 7)         printf( -O|OO-OO n );       else if (dig == 8)         printf( -O|OOO-O n );       else         printf( -O|OOOO- n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     if (n == 1 || n == 2) {       cout <<  -1 ;       return 0;     } else if (n % 2 == 1) {       long long k = (n - 1) / 2;       cout << 2 * k * k + 2 * k <<     << 2 * k * k + 2 * k + 1;     } else {       long long k = n / 2;       cout << k * k - 1 <<     << k * k + 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6, pi = acos(-1);   const int N = 1e2 + 5, M = 1e9 + 7, SEGM = 4 * N, OO = 0x3f3f3f3f;   int t, n, m, v1, v2;   int mem[105][2005];   int main() {     scanf( %d%d%d%d , &v1, &v2, &n, &m);     if (v1 > v2) swap(v1, v2);     memset(mem, -OO, sizeof mem);     mem[0][v1] = v1;     for (int i = 1; i < n; ++i) {       for (int cur = v1; cur < 2005; ++cur) {         for (int j = 0; j <= m; ++j) {           if (cur + j < 2005)             mem[i][cur + j] = max(mem[i][cur + j], cur + j + mem[i - 1][cur]);           if (cur - j > -1)             mem[i][cur - j] = max(mem[i][cur - j], cur - j + mem[i - 1][cur]);         }       }     }     cout << mem[n - 1][v2];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long oo = 2e9, MOD = 998244353;   int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};   int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};   int main() {     int n, k;     string s;     cin >> n >> k >> s;     for (int i = 0; i < (int)s.size() - 1 && k; i++) {       if (s[i] ==  4  and s[i + 1] ==  7 ) {         if (((i + 1) & 1) and i + 2 < (int)s.size() and s[i + 2] ==  7 ) {           k %= 2;           if (k) {             s[i] =  4 , s[i + 1] =  4 ;           }           break;         }         if (!((i + 1) & 1) and i - 1 >= 0 and s[i - 1] ==  4 ) {           k %= 2;           if (k) {             s[i] =  7 , s[i + 1] =  7 ;           }           break;         }         if ((i + 1) & 1) {           s[i] =  4 , s[i + 1] =  4 ;         } else {           s[i] =  7 , s[i + 1] =  7 ;         }         k--;       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void flanther_fakadi() {     string s;     cin >> s;     long long n = s.length();     long long ct = 0;     for (long long i = 0; i < s.length(); i++) {       if (ct && s[i] ==  B ) {         n -= 2;         ct--;       } else {         ct++;       }     }     cout << n << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(NULL);     int t = 0;     cin >> t;     while (t--) {       flanther_fakadi();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<pair<long long int, long long int>> ans;     string des =   ;     for (long long int i = 1; i < k; i++) {       des +=  () ;     }     long long int maxx = (n / 2);     for (long long int i = 0; i < (maxx - k + 1); i++) {       des +=  ( ;     }     for (long long int i = 0; i < (maxx - k + 1); i++) {       des +=  ) ;     }     for (long long int i = 0; i < n; i++) {       if (s[i] != des[i]) {         long long int j = i + 1;         while (s[j] != des[i]) j++;         string temp = s.substr(i, (j - i + 1));         reverse(temp.begin(), temp.end());         for (long long int k = i; k <= j; k++) {           s[k] = temp[k - i];         }         ans.push_back({i + 1, j + 1});       }     }     cout << ans.size() <<   n ;     for (long long int i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second <<   n ;     }   }   signed main() {     long long int t;     cin >> t;     while (t--) {       solve();     }   }