malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int k[3], n, pos[200005];   int dp[200005][3];   int main() {     ios::sync_with_stdio(0);     for (int i = 0; i < 3; i++) cin >> k[i], n += k[i];     for (int t, p = 0; p < 3; p++)       for (int i = 1; i <= k[p]; i++) {         cin >> t, pos[t] = p;       }     for (int i = 1; i <= n; i++) {       dp[i][0] = dp[i - 1][0] + (pos[i] != 0);       dp[i][1] =           ((dp[i - 1][0]) < (dp[i - 1][1]) ? (dp[i - 1][0]) : (dp[i - 1][1])) +           (pos[i] != 1);       dp[i][2] =           ((dp[i - 1][0]) < (((dp[i - 1][1]) < (dp[i - 1][2]) ? (dp[i - 1][1])                                                               : (dp[i - 1][2])))                ? (dp[i - 1][0])                : (((dp[i - 1][1]) < (dp[i - 1][2]) ? (dp[i - 1][1])                                                    : (dp[i - 1][2])))) +           (pos[i] != 2);     }     cout << ((dp[n][0]) < (((dp[n][1]) < (dp[n][2]) ? (dp[n][1]) : (dp[n][2])))                  ? (dp[n][0])                  : (((dp[n][1]) < (dp[n][2]) ? (dp[n][1]) : (dp[n][2]))));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, num = 0, dem = 0;     cin >> n;     if (n % 2 == 0) {       num = (n / 2) - 1;       dem = (n / 2) + 1;     } else {       num = n / 2;       dem = n - num;     }     set<int> x, y;     while (1) {       int flag1 = -1;       x.clear();       y.clear();       if (num == 2) x.insert(num);       for (int i = 2; i * i <= num; i++) {         if (num % i == 0) {           x.insert(i);           x.insert(num / i);         }       }       for (int i = 2; i * i <= dem; i++) {         if (dem % i == 0) {           y.insert(i);           y.insert(dem / i);         }       }       for (auto i : x) {         if (y.count(i) == 1) {           flag1 = 1;           break;         }       }       if (flag1 == -1) break;       num--;       dem++;     }     return cout << num <<     << dem <<   n , 0;   }
#include <bits/stdc++.h>   using namespace std;   using i64 = long long int;   using ii = pair<int, int>;   using ii64 = pair<i64, i64>;   i64 ipow(i64 x, i64 n) {     if (n == 0) return 1ll;     i64 half = ipow(x, n / 2);     half = (half * half) % 1000000007;     if (n % 2 == 0)       return half;     else       return (half * x) % 1000000007;   }   int main() {     i64 n, m;     scanf( %lld %lld , &n, &m);     vector<i64> s1(n);     vector<i64> s2(n);     for (int i = 0; i < n; i++) scanf( %lld , &s1[i]);     for (int i = 0; i < n; i++) scanf( %lld , &s2[i]);     vector<i64> ps(n + 1);     vector<i64> qs(n + 1);     ps[n] = 0;     qs[n] = 1;     for (int i = n - 1; i >= 0; i--) {       qs[i] = qs[i + 1];       if (s1[i] == 0) qs[i] = (qs[i] * m) % 1000000007;       if (s2[i] == 0) qs[i] = (qs[i] * m) % 1000000007;     }     for (int i = n - 1; i >= 0; i--) {       if (s1[i] != 0 && s2[i] != 0) {         if (s1[i] == s2[i])           ps[i] = ps[i + 1];         else if (s1[i] > s2[i])           ps[i] = qs[i + 1];         else           ps[i] = 0;       } else if (s1[i] == 0 && s2[i] != 0) {         ps[i] = ps[i + 1];         ps[i] += (qs[i + 1] * (m - s2[i])) % 1000000007;         ps[i] %= 1000000007;       } else if (s1[i] != 0 && s2[i] == 0) {         ps[i] = ps[i + 1];         ps[i] += (qs[i + 1] * (s1[i] - 1)) % 1000000007;         ps[i] %= 1000000007;       } else if (s1[i] == 0 && s2[i] == 0) {         ps[i] = (m * ps[i + 1]) % 1000000007;         i64 arg = (m * (m - 1) / 2) % 1000000007;         ps[i] += (qs[i + 1] * arg) % 1000000007;         ps[i] %= 1000000007;       }     }     printf( %lld n , (ps[0] * ipow(qs[0], 1000000007 - 2)) % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[200010];   int vis[200010], d[200010];   stack<int> his;   void dfs(int u, int dd) {     his.push(u);     d[u] = dd;     for (int v : g[u]) {       if (!d[v])         dfs(v, dd + 1);       else if (d[u] - d[v] + 1 >= ceil(sqrt(n))) {         puts( 2 );         printf( %d n , d[u] - d[v] + 1);         for (int i = d[v] - 1; i < d[u]; ++i) {           printf( %d  , his.top());           his.pop();         }         exit(0);       }     }     if (!vis[u])       for (int v : g[u]) vis[v] = 1;     his.pop();   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, u, v; i < m; ++i) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 1);     puts( 1 );     int visT = 0;     for (int i = 1; visT < ceil(sqrt(n)); ++i) {       if (!vis[i]) printf( %d  , i), ++visT;     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-7;   const int INF = 1000000000;   char buf[100];   int maxl[2000000];   int maxr[2000000];   int minl[2000000];   int minr[2000000];   pair<int, int> g[2000000];   int n;   int X = 0;   void dfs(int, int);   void add_dfs(int x, int mm) {     if (X > mm) return;     if (g[x].second == -1) {       g[x].second = X;       X++;       dfs(g[x].second, mm);     }     add_dfs(g[x].second, mm);   }   bool OK = true;   void dfs(int x, int mm) {     if (X > minl[x]) OK = false;     if (X <= maxl[x]) {       g[x].first = X;       X++;       dfs(g[x].first, maxl[x]);     }     if (X > minr[x]) OK = false;     if (X <= maxr[x]) {       g[x].second = X;       X++;       dfs(g[x].second, maxr[x]);     }     add_dfs(x, mm);   }   vector<int> res;   void dfs2(int x) {     if (g[x].first != -1) dfs2(g[x].first);     res.push_back(x);     if (g[x].second != -1) dfs2(g[x].second);   }   int main() {     int m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       maxl[i] = 0;       maxr[i] = 0;       minl[i] = n;       minr[i] = n;       g[i] = make_pair(-1, -1);     }     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       scanf( %s , buf);       if (buf[0] ==  L ) {         maxl[x] = max(maxl[x], y);         minl[x] = min(minl[x], y);       } else {         maxr[x] = max(maxr[x], y);         minr[x] = min(minr[x], y);       }     }     X = 1;     dfs(0, n - 1);     dfs2(0);     if (!OK)       printf( IMPOSSIBLE n );     else {       for (int i = 0; i < res.size(); i++) {         printf( %d  , res[i] + 1);       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   inline long long max(long long a, long long b) { return ((a > b) ? a : b); }   inline long long min(long long a, long long b) { return ((a > b) ? b : a); }   inline long long gcd(long long a, long long b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   long long power(long long x, long long y) {     if (y == 0) return 1;     long long a = power(x, y / 2);     if (y % 2 == 0)       return a * a;     else       return x * a * a;   }   long long powermod(long long x, long long ex, long long md) {     long long ans = 1ll;     while (ex > 0) {       if (ex & 1ll) ans = (ans * x) % md;       ex >>= 1ll;       x = (x * x) % md;     }     return ans;   }   const long long inf = 1e18 + 9;   const long long mod = 1e9 + 7;   const long double PI = acos(-1);   const long double eps = 1e-9;   const long long N = 2e5 + 11;   long long n, t, easy, hard;   long long a[N], b[N], pfx[N], cnteasy[N], cnthard[N];   vector<pair<long long, long long> > v;   void solve() {     cin >> n >> t >> easy >> hard;     for (int i = 0; i < n; i++) cin >> b[i + 1];     for (int i = 0; i < n; i++) cin >> a[i + 1];     for (int i = 0; i < n; i++) v.push_back(make_pair(a[i + 1], b[i + 1]));     sort((v).begin(), (v).end());     for (int i = 0; i < n; i++) {       if (v[i].second)         pfx[i + 1] = pfx[i] + hard;       else         pfx[i + 1] = pfx[i] + easy;       cnthard[i + 1] = cnthard[i] + (v[i].second);       cnteasy[i + 1] = cnteasy[i] + (!v[i].second);     }     if (pfx[n] <= t) {       cout << n <<   n ;     } else {       long long ans = 0;       for (long long i = 0; i < n; i++) {         long long t = v[i].first - 1;         if (t < 0) continue;         long long val = i;         long long tym = pfx[i];         long long rem = t - tym;         if (rem >= 0) {           long long x = min(rem / easy, cnteasy[n] - cnteasy[i]);           rem -= (x * easy);           val += x;           val += min(rem / hard, cnthard[n] - cnthard[i]);           ans = max(ans, val);         }       }       cout << ans <<   n ;     }     for (int i = 0; i < n + 1; i++)       a[i] = b[i] = pfx[i] = cnteasy[i] = cnthard[i] = 0;     v.clear();     n = t = easy = hard = 0;   }   int main() {     {       ios::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     cout << fixed << setprecision(20);     long long NTC = 1;     cin >> NTC;     long long PTC = 0;     while (PTC++ < NTC) {       solve();       cout <<   n ;     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int x = 0, y = 0, dp = 0, tmp;     int sum = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  U ) {         y++;         if (x < y) {           if (dp == 2) sum++;           dp = 1;         }       }       if (s[i] ==  R ) {         x++;         if (x > y) {           if (dp == 1) sum++;           dp = 2;         }       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926536;   const long long INF = 1e18;   const int32_t M = 1e6 + 7;   const int32_t MM = 998244353;   long long a, b, c, d;   void solve() {     cin >> a >> b >> c >> d;     double p, q, x;     p = (double)a / b;     q = (double)c / d;     x = (1 - p) * (1 - q);     x = 1 - x;     cout << fixed << setprecision(12);     cout << p / x;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> ans;   int n, r, fr[101][101];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &r);       for (int x, j = 0; j < r; j++) {         scanf( %d , &x);         fr[i][x]++;       }     }     for (int i = 1; i <= 100; i++) {       int c = 0;       for (int j = 0; j <= 100; j++) {         c += fr[j][i];       }       if (c == n) {         ans.push_back(i);       }     }     for (int i = 0; i < ans.size(); i++) {       printf( %d , ans[i]);       if (i != ans.size() - 1) putchar(   );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   const int mod = 1e9 + 7;   int a[N], f[N];   int main() {     int n;     int p = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] == 0) f[p++] = i;     }     int v = 0;     for (int i = 0; i < n; i++) {       if (a[i] != 0) {         a[i] = abs(f[v] - i);         if (v + 1 < p) a[i] = min(a[i], abs(f[v + 1] - i));         if (v - 1 >= 0) a[i] = min(a[i], abs(f[v - 1] - i));       } else         v++;     }     printf( %d , a[0]);     for (int i = 1; i < n; i++) {       printf(  %d , a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dist[605][605], u, v, a[205], n, Vv, E, m, fix[605], match[605], w, ans, l,       r, k;   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       q;   vector<pair<int, int> > V[605];   vector<pair<pair<int, int>, int> > ed;   void dijkstra(int cur) {     for (int i = 1; i <= Vv; i++) dist[cur][i] = 1e7;     q.push({0, cur});     dist[cur][cur] = 0;     while (q.size()) {       u = q.top().second;       int d = q.top().first;       q.pop();       if (d > dist[cur][u]) continue;       for (int i = 0; i < V[u].size(); i++) {         v = V[u][i].first;         if (dist[cur][v] > dist[cur][u] + V[u][i].second) {           dist[cur][v] = dist[cur][u] + V[u][i].second;           q.push({dist[cur][v], v});         }       }     }   }   bool dfs(int u, int T) {     for (int v = 1; v <= Vv; v++) {       if (!fix[v] && dist[u][v] <= T) {         fix[v] = 1;         if (match[v] == -1 || dfs(match[v], T)) {           match[v] = u;           return true;         }       }     }     return false;   }   bool check(int T) {     int pas = 0;     for (k = 1; k <= Vv; k++) {       match[k] = -1;     }     for (k = 1; k <= n; k++) {       for (int i = 1; i <= Vv; i++) fix[i] = 0;       if (dfs(a[k], T)) pas++;     }     if (pas >= m) return true;     return false;   }   int main() {     cin >> Vv >> E >> n >> m;     for (k = 1; k <= n; k++) {       cin >> a[k];     }     for (k = 1; k <= E; k++) {       cin >> u >> v >> w;       ed.push_back({{u, v}, w});       V[u].push_back({v, w});       V[v].push_back({u, w});     }     for (k = 1; k <= n; k++) {       dijkstra(a[k]);     }     l = 0;     r = 1731311;     ans = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[200005], pos[200005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     long long n;     cin >> n;     cout << n <<    ;     if (n == 1) {       cout <<  1 ;       return 0;     }     if (n % 2) {       long long tmp = 1;       while (tmp < n) {         cout << tmp <<    ;         tmp += 2;       }       cout << n <<    ;       while (tmp > 1) {         cout << tmp - 2 <<    ;         tmp -= 2;       }       tmp = 2;       while (tmp < n - 1) {         cout << tmp <<    ;         tmp += 2;       }       cout << n - 1 <<     << n - 1 <<    ;       while (tmp > 2) {         cout << tmp - 2 <<    ;         tmp -= 2;       }     } else {       long long tmp = 2;       while (tmp < n) {         cout << tmp <<    ;         tmp += 2;       }       cout << n <<    ;       while (tmp > 2) {         cout << tmp - 2 <<    ;         tmp -= 2;       }       tmp = 1;       while (tmp < n - 1) {         cout << tmp <<    ;         tmp += 2;       }       cout << n - 1 <<     << n - 1 <<    ;       while (tmp > 1) {         cout << tmp - 2 <<    ;         tmp -= 2;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, r1, r2, r3, d;   const int N = 1e6 + 4;   long long dp[N][2];   long long a[N];   void debug() {     cout <<  -----debug-----  << endl;     for (int i = 1; i <= n; ++i) {       printf( dp[%d][%d]=%lld dp[%d][%d]=%lld n , i, 0, dp[i][0], i, 1, dp[i][1]);     }   }   int main() {     cin >> n >> r1 >> r2 >> r3 >> d;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     memset(dp, 0x3f, sizeof(dp));     dp[1][0] = r1 * a[1] + r3;     dp[1][1] = min(r1 * a[1] + r1, r2);     for (int i = 1; i < n; ++i) {       dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + d + r1 * a[i + 1] + r3);       dp[i + 1][1] = min(dp[i + 1][1], min(dp[i][0] + d + r1 * (a[i + 1] + 1),                                            dp[i][0] + d + r2));       dp[i + 1][0] =           min(dp[i + 1][0], dp[i][1] + d + r1 * (a[i + 1] + 2) + 2 * d + r1);       dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + d + r2 + r1 + 2 * d + r1);       dp[i + 1][0] =           min(dp[i + 1][0], dp[i][1] + d + r1 * a[i + 1] + r3 + 2 * d + r1);       dp[i + 1][1] =           min(dp[i + 1][1], dp[i][1] + d + r1 * a[i + 1] + r1 + d + r1 + d);       dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + d + r2 + d + r1 + d);       if (i == n - 1) {         dp[i + 1][0] =             min(dp[i + 1][0], dp[i][1] + d + r1 * a[i + 1] + r3 + d + r1);       }     }     cout << dp[n][0] << endl;     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int n;     int a[1100];     while (scanf( %d , &n) == 1) {       for (int i = 0; i < n; i++) scanf( %d , a + i);       int cnt = 1, ans = 0;       int j = 0;       if (n <= 2) {         printf( %d n , ans);         break;       }       if (a[0] > a[1])         j = -1;       else if (a[0] == a[1])         j = 0;       else         j = 1;       while (cnt < n - 1) {         if (j == -1) {           for (; cnt < n - 1 && a[cnt] > a[cnt + 1]; cnt++)             ;           if (cnt == n - 1) break;           if (a[cnt] > a[cnt + 1])             j = -1;           else if (a[cnt] == a[cnt + 1])             j = 0;           else {             ans++;             j = 1;           }         }         if (j == 0) {           for (; cnt < n - 1 && a[cnt] == a[cnt + 1]; cnt++)             ;           if (cnt == n - 1) break;           if (a[cnt] > a[cnt + 1])             j = -1;           else if (a[cnt] == a[cnt + 1])             j = 0;           else             j = 1;         }         if (j == 1) {           for (; cnt < n - 1 && a[cnt] < a[cnt + 1]; cnt++)             ;           if (cnt == n - 1) break;           if (a[cnt] > a[cnt + 1]) {             ans++;             j = -1;           } else if (a[cnt] == a[cnt + 1])             j = 0;           else             j = 1;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<set<int> > g(n + 1);     map<int, int> co;     for (int i = 0; i < m; i++) {       int n1, n2;       cin >> n1 >> n2;       g[n1].insert(n2);       g[n2].insert(n1);       co[n1]++;       co[n2]++;     }     int minn = 1000000000;     for (int i = 1; i <= n; i++) {       set<int>::iterator iter;       for (iter = g[i].begin(); iter != g[i].end(); iter++) {         set<int>::iterator iter2;         for (iter2 = g[*iter].begin(); iter2 != g[*iter].end(); iter2++) {           if (*iter2 == i) continue;           if (g[*iter2].count(i)) {             minn = min(minn, co[*iter] + co[*iter2] + co[i] - 6);           }         }       }     }     if (minn == 1000000000)       cout << -1 << endl;     else       cout << minn << endl;     return 0;   }
// REMEMBER USING MOD INVERSE WHILE DOING COMBINATORICS   // REMEMBER using int32_t while typecasting size into int      #include<bits/stdc++.h>   using namespace std;   #define pb push_back   #define int long long   #define all(x) x.begin(),x.end()   #define nl    n    #define ok  cout<< OK n    #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define free freopen( input.txt , r ,stdin);freopen( output.txt , w ,stdout)   #define ff first   #define ss second   typedef pair<int,int> pii;   const long long INF = 1ll << 32;   const long long MAX_N = 3e6 + 5;   const long long MOD = 1e9 + 7;      const long long N = 5001;      int I;      void solve()   {       int n;       cin>>n;       int even = 0 , odd = 0;       for(int i = 0 ; i<2 * n ; i++) {           int p;           cin>>p;           if(p & 1) odd++;           else even++;       }       cout<<(even == odd ?  Yes  :  No )<<nl;      }      int32_t main()   {       ios;       int Test = 1;       cin>>Test;       for(I = 1 ; I<=Test ;  I++)       {           solve();       }               }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const double PI = acos(-1.);   const double eps = 1e-10;   const int INF = 0x3f3f3f3f;   const long long INFll = 0x3f3f3f3f3f3f3f3f;   const int MAXN = 1e6 + 5;   const int MX = 123456;   const int inf = 0x3f3f3f3f;   const int MXE = 1e7;   struct MinCost_MaxFlow {     struct Edge {       int v, w, nxt;       int cost;     } E[MXE];     int head[MX], tot, level[MX], pre[MX], d[MX];     bool vis[MX];     void init() {       memset(head, -1, sizeof(head));       tot = 0;     }     void add(int u, int v, int w, int cost) {       E[tot].v = v;       E[tot].w = w;       E[tot].cost = cost;       E[tot].nxt = head[u];       head[u] = tot++;       E[tot].v = u;       E[tot].w = 0;       E[tot].cost = -cost;       E[tot].nxt = head[v];       head[v] = tot++;     }     bool spfa(int s, int t) {       memset(vis, 0, sizeof(vis));       memset(d, 0x3f, sizeof(d));       memset(pre, -1, sizeof(pre));       queue<int> q;       q.push(s);       d[s] = 0;       vis[s] = 1;       while (!q.empty()) {         int u = q.front();         q.pop();         vis[u] = 0;         for (int i = head[u]; ~i; i = E[i].nxt) {           int w = E[i].w, v = E[i].v, cost = E[i].cost;           if (w > 0 && d[v] > d[u] + cost) {             d[v] = d[u] + cost;             pre[v] = i;             if (!vis[v]) {               q.push(v);               vis[v] = 1;             }           }         }       }       return pre[t] != -1;     }     int solve(int s, int t, int &cost) {       int flow = 0;       cost = 0;       while (spfa(s, t)) {         int minFlow = inf;         for (int i = pre[t]; ~i; i = pre[E[i ^ 1].v])           minFlow = min(minFlow, E[i].w);         for (int i = pre[t]; ~i; i = pre[E[i ^ 1].v]) {           cost += minFlow * E[i].cost;           E[i].w -= minFlow;           E[i ^ 1].w += minFlow;         }         flow += minFlow;       }       return flow;     }   } F;   int a[MAXN];   int main() {     int n;     scanf( %d , &n);     F.init();     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int st = 0, en = 2 * n + 5;     int add = en - 1;     F.add(st, add, 4, 0);     int magic = 4;     for (int i = 1; i <= n; i++) {       F.add(add, i, 1, 0);       F.add(i + n, en, 1, 0);       F.add(i, i + n, 1, -1);       F.add(i, i + n, INF, 0);       int cnt1 = 0, cnt2 = 0;       for (int j = i + 1; j <= n; j++) {         if (abs(a[i] - a[j]) == 1 && cnt1 <= magic) {           F.add(i + n, j, 1, 0);           cnt1++;         }         if (a[i] % 7 == a[j] % 7 && cnt2 <= magic) {           F.add(i + n, j, 1, 0);           cnt2++;         }       }     }     int flow, cost;     flow = F.solve(st, en, cost);     printf( %d n , -cost);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx,avx2,tune=native )   template <typename T>   using Prior = std::priority_queue<T>;   template <typename T>   using prior = std::priority_queue<T, std::vector<T>, std::greater<T>>;   using namespace std;   void pre() {}   void solve() {     int n, k;     cin >> n >> k;     vector<long long> arr(n);     for (auto& x : arr) cin >> x;     vector<vector<long long>> dp(n, vector<long long>(n + 1));     for (int j = 1; j <= n; ++j)       dp[0][j] = dp[0][j - 1] + (bool)(arr[j - 1] == j);     if (dp[0].back() >= k) return cout << 0 <<   n , void();     for (int i = 1; i < n; ++i) {       for (int j = i + 1; j <= n; ++j)         dp[i][j] =             max(dp[i - 1][j - 1], dp[i][j - 1] + (bool)(arr[j - 1] == j - i));       if (dp[i].back() >= k) return cout << i <<   n , void();     }     cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     pre();     int _ = 1;     cin >> _;     vector<long long> __(_);     iota(begin(__), end(__), 1);     for (auto i : __) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long maxi(long long &a, long long b) {     if (b > a) {       a = b;       return 1;     }     return 0;   }   inline long long mini(long long &a, long long b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   inline long long maxi(long double &a, long double b) {     if (b > a) {       a = b;       return 1;     }     return 0;   }   inline long long mini(long double &a, long double b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long t;     cin >> t;     while (t--) {       long long n;       string a, b;       cin >> n >> a >> b;       vector<long long> ans1, ans2;       a +=  0 ;       b +=  0 ;       for (long long i = 1; i <= n; i++) {         if (a[i] != a[i - 1]) {           ans1.push_back(i);         }         if (b[i] != b[i - 1]) {           ans2.push_back(i);         }       }       for (long long i = (long long)ans2.size() - 1; i >= 0; i--) {         ans1.push_back(ans2[i]);       }       cout << (long long)ans1.size() <<   n ;       for (auto now : ans1) {         cout << now <<    ;       }       cout <<   n ;     }   }