malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long par[27];   long long parent(long long x) {     while (x != par[x]) {       par[x] = par[par[x]];       x = par[x];     }     return x;   }   void uni(long long x, long long y) {     long long px = parent(x);     long long py = parent(y);     par[y] = px;   }   int main() {     long long t = 1;     while (t--) {       long long n;       cin >> n;       set<long long> st;       for (long long i = 0; i < 27; i++) par[i] = i;       for (long long i = 0; i < n; i++) {         string s;         cin >> s;         st.insert(s[0] -  a );         for (long long i = 1; i < s.length(); i++) {           st.insert(s[i] -  a );           uni(s[0] -  a , s[i] -  a );         }       }       long long ans = 0;       for (long long i = 0; i < 26; i++)         if (parent(i) == i && st.find(i) != st.end()) ans++;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   long long int fast_pow(long long int base, long long int exp,                          long long int M = 1000000007) {     base = base % M;     long long int result = 1;     while (exp > 0) {       if (exp % 2 == 1) result = (result * base) % M;       base = (base * base) % M;       exp = exp / 2;     }     return result;   }   long long int modInverse(long long int A, long long int M = 1000000007) {     return fast_pow(A, M - 2, M);   }   long long int maxSubArraySum(long long int a[], long long int size) {     long long int max_so_far = INT_MIN, max_ending_here = 0;     for (long long int i = 0; i < size; i++) {       max_ending_here = max_ending_here + a[i];       if (max_so_far < max_ending_here) max_so_far = max_ending_here;       if (max_ending_here < 0) max_ending_here = 0;     }     return max_so_far;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       long long int yass = 0;       cin >> n;       long long int v[n];       for (long long int i = 0; i <= n - 1; i++) {         cin >> v[i];         yass += v[i];       }       long long int m1 = maxSubArraySum(v, n - 1);       long long int m2 = maxSubArraySum(v + 1, n - 1);       ;       long long int adel = max(m1, m2);       if (yass > adel) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k % 3 == 0) {         if (n >= k) {           n = n % (k + 1);           if (n == k)             cout <<  Alice n ;           else {             if ((n) % 3 != 0) {               cout <<  Alice n ;             } else {               cout <<  Bob n ;             }           }         } else {           if ((n) % 3 != 0) {             cout <<  Alice n ;           } else {             cout <<  Bob n ;           }         }       } else {         if ((n) % 3 != 0) {           cout <<  Alice n ;         } else {           cout <<  Bob n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define mod 1000000007   typedef long long ll;   #define MAXN 300005   #define mod 1000000007         int main(){       int n;       cin>>n;       vector<int>ar(n+1);       for(int i=1;i<=n;i++)cin>>ar[i];       vector<pair<int,pair<int,int> > >supp;       for(int i=1;i<=n;i++){           for(int j=i+1;j<=n;j++){               supp.push_back({abs(ar[i]-ar[j]),{i,j}});           }       }       sort(supp.rbegin(),supp.rend());       for(int i=0;i<(int)supp.size();i++){           pair<int,int>tmp=supp[i].second;           if(ar[tmp.first]<ar[tmp.second])swap(tmp.first,tmp.second);           cout<< ?  <<tmp.first<<   <<tmp.second<<endl;           string ok;           cin>>ok;           if(ok== Yes ){               cout<< !  <<tmp.first<<   <<tmp.second<<endl;               return 0;           }       }       cout<< ! 0 0 <<endl;      }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     int a[m + 1];     for (int i = 0; i < m + 1; i++) {       cin >> a[i];     }     int ans = 0;     for (int i = 0; i < m; i++) {       int count = 0;       for (int j = 0; j < n; j++) {         if (((a[m] >> j) & 1) != ((a[i] >> j) & 1)) {           count++;         }       }       if (count <= k) ans++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long mod = 1e9 + 7;   int n, m;   vector<int> depth;   vector<bool> visited;   vector<vector<int>> adj;   void dfs(int curr, int dt) {     depth[curr] = (dt) % 2;     visited[curr] = true;     for (int i = 0; i < adj[curr].size(); i++) {       if (!visited[adj[curr][i]]) {         dfs(adj[curr][i], dt + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       cin >> n >> m;       adj = vector<vector<int>>(n + 1);       depth = vector<int>(n + 1);       visited = vector<bool>(n + 1, false);       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       dfs(1, 0);       vector<int> v1;       vector<int> v2;       for (int i = 1; i <= n; i++) {         if (depth[i] % 2) {           v1.push_back(i);         } else {           v2.push_back(i);         }       }       if (v1.size() < v2.size()) {         cout << v1.size() << endl;         for (int i = 0; i < v1.size(); i++) {           cout << v1[i] <<    ;         }       } else {         cout << v2.size() << endl;         for (int i = 0; i < v2.size(); i++) {           cout << v2[i] <<    ;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   void self_add(long long &x, long long y) { x = (x + y) % mod; }   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = (res * a) % mod;       n >>= 1;       a = (a * a) % mod;     }     return res;   }   int main() {     long long n;     cin >> n;     long long fact = 1;     for (long long i = 2; i <= n; i++) {       fact = (fact * (i)) % mod;     }     long long power = binpow(2, n - 1);     long long ans = (fact - power) % mod;     if (ans < 0) ans += mod;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int v;     cin >> v;     int a[9];     int t = 100000, x;     for (long long i = 0; i < 9; ++i) {       cin >> a[i];       t = min(t, a[i]);     }     if (t > v) {       cout << -1;       return;     }     x = v / t;     while (x--) {       for (int i = 8; i >= 0; i--) {         if (a[i] <= v && (v - a[i]) / t == x) {           cout << i + 1;           v -= a[i];           break;         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, f;     char na;   } f[30];   bool cmp(node a, node b) { return a.na < b.na; }   char s[1005][1005];   int s1[1005][1005];   int s2[1005][1005];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     memset(f, 0, sizeof(f));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         s1[i][j] = s1[i][j - 1] + ((s[i][j] ==  # ) ? 1 : 0);       }     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) {         s2[j][i] = s2[j - 1][i] + ((s[j][i] ==  # ) ? 1 : 0);       }     int ns = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (s[i][j] >=  A  && s[i][j] <=  Z ) {           f[ns].x = i;           f[ns].y = j;           f[ns].na = s[i][j];           ns++;         }       }     sort(f, f + ns, cmp);     int nq;     scanf( %d , &nq);     for (int i = 0; i < nq; i++) {       char dir[9];       int len;       scanf( %s %d , dir, &len);       for (int j = 0; j < ns; j++) {         if (!f[j].f) {           if (dir[0] ==  W ) {             if (f[j].y - len < 1)               f[j].f = 1;             else if (s1[f[j].x][f[j].y] - s1[f[j].x][f[j].y - len - 1] > 0)               f[j].f = 1;             f[j].y = f[j].y - len;           }           if (dir[0] ==  E ) {             if (f[j].y + len > m)               f[j].f = 1;             else if (s1[f[j].x][f[j].y + len] - s1[f[j].x][f[j].y - 1] > 0)               f[j].f = 1;             f[j].y = f[j].y + len;           }           if (dir[0] ==  S ) {             if (f[j].x + len > n)               f[j].f = 1;             else if (s2[f[j].x + len][f[j].y] - s2[f[j].x - 1][f[j].y] > 0)               f[j].f = 1;             f[j].x = f[j].x + len;           }           if (dir[0] ==  N ) {             if (f[j].x - len < 1)               f[j].f = 1;             else if (s2[f[j].x][f[j].y] - s2[f[j].x - len - 1][f[j].y] > 0)               f[j].f = 1;             f[j].x = f[j].x - len;           }         }       }     }     int flag = 0;     for (int i = 0; i < ns; i++) {       if (!f[i].f) {         printf( %c , f[i].na);         flag = 1;       }     }     if (!flag) printf( no solution );     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int n, head[100005], tot, d[100005], fa[100005], vis[100005], lf[100005], cnt;   struct node {     int v, nxt;   } edg[100005 << 1];   inline void addedg(int u, int v) {     edg[tot].v = v;     edg[tot].nxt = head[u];     head[u] = tot++;   }   inline void init() {     memset(head, -1, sizeof(int) * (n + 1));     tot = cnt = 0;   }   inline void dfs1(int u, int f) {     int v;     d[u] = 0;     for (int i = head[u]; i != -1; i = edg[i].nxt) {       v = edg[i].v;       ++d[u];       if (v == f) continue;       dfs1(v, u);     }   }   inline void dfs2(int u, int f, int dis) {     int v;     fa[u] = f;     d[u] = dis;     for (int i = head[u]; i != -1; i = edg[i].nxt) {       v = edg[i].v;       if (f == v) continue;       dfs2(v, u, dis + 1);     }   }   inline bool cmp(int u, int v) { return d[u] > d[v]; }   set<int> se;   int main() {     scanf( %d , &n);     init();     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       addedg(u, v);       addedg(v, u);     }     dfs1(1, 1);     for (int i = 1; i <= n; ++i) {       if (d[i] == 1) lf[cnt++] = i;     }     int root = lf[0];     dfs2(root, root, 0);     vis[root] = 1;     int maxn = 0, minn = 1;     for (int i = 1; i < cnt; ++i) {       if (d[lf[i]] & 1) minn = 3;     }     fa[root] = edg[head[root]].v;     maxn = n - 1 - cnt;     for (int i = 0; i < cnt; ++i) se.insert(fa[lf[i]]);     maxn += se.size();     printf( %d %d n , minn, maxn);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 510;   const int inf = 0x3f3f3f3f;   int n;   long long d[maxn][maxn];   int w(int i, int j, int k) { return i * j * k; }   int main() {     int n;     scanf( %d , &n);     memset(d, 0x3f, sizeof(d));     for (int i = 1; i <= n; i++) {       d[i][i + 2] = w(i, i + 1, i + 2);       d[i][i] = 0;       d[i][i + 1] = 0;     }     for (int i = n - 2; i >= 1; i--) {       for (int j = i + 2; j <= n; j++) {         for (int k = i + 1; k < j; k++) {           d[i][j] = min(d[i][j], d[i][k] + d[k][j] + w(i, j, k));         }       }     }     printf( %I64d , d[1][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   int l, MOD;   map<long long, int> mp;   int fib(long long n) {     if (mp.count(n)) return mp[n];     if (n & 1)       return mp[n] = 1LL * fib(n / 2) * (fib(n / 2 - 1) + fib(n / 2 + 1)) % MOD;     return mp[n] = (1LL * fib(n / 2) * fib(n / 2) +                     1LL * fib(n / 2 - 1) * fib(n / 2 - 1)) %                    MOD;   }   int bpow(int a, long long b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % MOD;       b >>= 1;       a = 1LL * a * a % MOD;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k >> l >> MOD;     if (k >= (1LL << min(l, 62))) {       cout <<  0 n ;       return 0;     }     mp[0] = 1 % MOD;     mp[1] = 1 % MOD;     int zero = fib(n + 1);     int one = (bpow(2, n) - zero + MOD) % MOD;     int ans = 1 % MOD;     for (int i = 0; i < min(l, 62); i++)       if ((1LL << i) & k)         ans = 1LL * ans * one % MOD;       else         ans = 1LL * ans * zero % MOD;     for (int i = 62; i < l; i++) ans = 1LL * ans * zero % MOD;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void sol() {     long long int n;     cin >> n;     vector<int> ar[6];     long long int a;     vector<int> v = {4, 8, 15, 16, 23, 42};     for (long long int i = 0; i < n; i++) {       cin >> a;       ar[lower_bound(v.begin(), v.end(), a) - v.begin()].push_back(i);     }     int p[6] = {0, 0, 0, 0, 0, 0};     int sit = 0;     int cnt = 0;     while (1) {       int prev = -1;       for (long long int i = 0; i < 6; i++) {         while (p[i] < ar[i].size() && ar[i][p[i]] < prev) {           p[i]++;         }         if (p[i] >= ar[i].size()) {           sit = 1;           break;         }         prev = ar[i][p[i]];         p[i]++;       }       if (sit == 1)         break;       else         cnt++;     }     cout << n - 6 * cnt <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       sol();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void readi(int &x);   const int maxn = 300005;   int n, b[maxn], id[maxn], rk[maxn];   double fl[maxn], fr[maxn];   bool cmpb(const int &i, const int &j) { return b[i] < b[j]; }   struct node {     double div, dta;     node *lc, *rc;     inline void downdate() {       if (div != 1)         lc->div *= div, lc->dta *= div, rc->div *= div, rc->dta *= div, div = 1;       if (dta != 0) lc->dta += dta, rc->dta += dta, dta = 0;     }     inline void modify(int l, int r, const int &a, const int &b, const double &c,                        const double &d) {       if (l >= a && r <= b)         div *= c, dta *= c, dta += d;       else {         int mid = l + r >> 1;         downdate();         if (a <= mid) lc->modify(l, mid, a, b, c, d);         if (b > mid) rc->modify(mid + 1, r, a, b, c, d);       }     }     inline double get(int l, int r, const int &p) {       if (l == r) return dta;       int mid = l + r >> 1;       downdate();       if (p <= mid)         return lc->get(l, mid, p);       else         return rc->get(mid + 1, r, p);     }   } ndl[maxn * 3], *root;   int ns;   node *build(int l, int r) {     node *c = ndl + ns++;     c->dta = 0;     c->div = 1;     if (l == r)       c->lc = c->rc = NULL;     else {       int mid = l + r >> 1;       c->lc = build(l, mid);       c->rc = build(mid + 1, r);     }     return c;   }   void build() { ns = 1, root = build(1, n); }   void init() {     readi(n);     for (int i = 1; i <= n; i++) readi(b[i]), id[i] = i;     sort(id + 1, id + n + 1, cmpb);     for (int i = 1; i <= n; i++) rk[id[i]] = i;   }   void work() {     build();     for (int i = 1; i <= n; i++) {       root->modify(1, n, 1, n, 1, 1);       if (rk[i] > 1) root->modify(1, n, 1, rk[i] - 1, .5, 0);       fl[i] = root->get(1, n, rk[i]) / 2;     }     build();     for (int i = n; i >= 1; i--) {       root->modify(1, n, 1, n, 1, 1);       if (rk[i] > 1) root->modify(1, n, 1, rk[i] - 1, .5, 0);       fr[i] = root->get(1, n, rk[i]) / 2;     }     double ans = 0;     for (int i = 1; i <= n; i++) ans += fl[i] * fr[i] * b[i];     ans /= (double)n * n;     printf( %lf , (double)ans * 2);   }   int main() {     init();     work();     return 0;   }   inline void readi(int &x) {     char c;     for (c = getchar(); c >  9  || c <  0 ; c = getchar())       ;     x = c ^  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar())       x = x * 10 + (c ^  0 );   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > seg[2];   int n, m, k, x, y, dX, dY;   bool flag = 0;   long long ans;   void add(int tx, int ty) {     seg[0].push_back(pair<int, int>(tx - ty, tx));     seg[1].push_back(pair<int, int>(tx + ty, tx));   }   void reflect() {     int fc;     if (dX == dY)       fc = 0;     else       fc = 1;     pair<int, int> p = (fc) ? pair<int, int>(x + y, x) : pair<int, int>(x - y, x);     vector<pair<int, int> >::iterator it =         upper_bound(seg[fc].begin(), seg[fc].end(), p);     while (it->first != p.first) it--;     if (dX < 0)       while (it->second >= x) it--;     ans += abs(x - it->second) - 1;     x = it->second;     y = (fc) ? (it->first - x) : (x - it->first);     bool A = binary_search(seg[0].begin(), seg[0].end(),                            pair<int, int>(x - y - dX, x - dX));     bool B = binary_search(seg[0].begin(), seg[0].end(),                            pair<int, int>(x - y + dY, x));     if (A == B)       flag = 1, dX = -dX, dY = -dY;     else {       if (A)         x -= dX, dY = -dY;       else if (B)         y -= dY, dX = -dX;     }   }   int main() {     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= m; i++) add(0, i), add(n + 1, i);     for (int i = 0; i <= n + 1; i++) add(i, 0), add(i, m + 1);     for (int i = 1; i <= k; i++) {       scanf( %d %d , &x, &y);       add(x, y);     }     scanf( %d %d , &x, &y);     char c = getchar();     while (c !=  N  && c !=  S  && c !=  W  && c !=  E ) c = getchar();     if (c ==  N )       dX = -1;     else       dX = 1;     c = getchar();     if (c ==  W )       dY = -1;     else       dY = 1;     sort(seg[0].begin(), seg[0].end());     sort(seg[1].begin(), seg[1].end());     reflect();     int sx = x, sy = y, sdx = dX, sdy = dY;     ans = 0;     do reflect();     while (!(x == sx && y == sy && dX == sdx && dY == sdy));     printf( %lld n , (flag) ? (ans >> 1) : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200005], d[200005], m(0), id, x;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], ++d[a[i]];     for (int i = 1; i <= n; i++)       if (d[a[i]] > m) m = d[a[i]], id = i, x = a[i];     cout << n - m <<   n ;     for (int i = id - 1; i; i--) {       if (a[i] < x)         cout << 1 <<     << i <<     << i + 1 <<   n ;       else if (a[i] > x)         cout << 2 <<     << i <<     << i + 1 <<   n ;     }     for (int i = id + 1; i <= n; i++) {       if (a[i] < x)         cout << 1 <<     << i <<     << i - 1 <<   n ;       else if (a[i] > x)         cout << 2 <<     << i <<     << i - 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7;   const double pi = acos(-1), eps = 1e-9;   int n, x, c = 1;   vector<int> v;   long long ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       if (x >= c) {         while (c < x) {           ans += i - v.back();           ++c;           v.pop_back();         }         ++c;       } else {         v.push_back(i);         ans += c - x - 1;       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int a[N];   long long dp[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       a[x]++;     }     long long ans = 0;     dp[N - 1] = dp[N - 2] = 0;     for (int i = N - 3; i >= 1; --i) {       dp[i] = max(dp[i + 1], dp[i + 2] + 1LL * a[i] * i);       ans = max(ans, dp[i]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 10, MAX = 2e5 + 1e4, MOD = 1e9 + 7, MAXL = 25;   void OUT(long double o, int x) {     cout << fixed << setprecision(x) << o;     return;   }   long long a[MAX], t = 1;   vector<int> adj[MAX];   void dfs(int v, int p) {     long long c = 0;     for (int u : adj[v]) {       if (u != p) {         dfs(u, v);         if (adj[u].size() == 1) c++;       }     }     if (adj[v].size() > 1 && c < 3) t = 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int i = 2; i <= n; i++) {       long long x;       cin >> x;       adj[x].push_back(i);       adj[i].push_back(x);     }     dfs(1, 1);     if (t)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e6 + 1, mod = 1e9 + 7;   int n, m, k, cnt[maxn], pow2[maxn], ans;   int main() {     scanf( %d%d%d , &n, &m, &k);     ++k;     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       if (u + 1 != v && u + k != v) {         puts( 0 );         return 0;       }       if (u + k == v) cnt[u] = 1;     }     for (int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1];     for (int i = k + 1; i <= n; ++i)       if (cnt[i] - cnt[i - 1] && cnt[i - k]) {         puts( 0 );         return 0;       }     pow2[0] = 1;     for (int i = 1; i <= n; ++i) {       pow2[i] = pow2[i - 1] << 1;       if (pow2[i] >= mod) pow2[i] -= mod;     }     ans = !cnt[n];     for (int i = 1; i <= n - k; ++i)       if (cnt[i] == cnt[n]) {         if (i <= k)           ans += pow2[i - cnt[i - 1] - 1];         else if (!cnt[i - k])           ans += pow2[k - cnt[i - 1] - 1];         if (ans >= mod) ans -= mod;       }     printf( %d n , ans);     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 = 2e3 + 10;   int n, k, a[maxN], dp[maxN][maxN];   void solve() {     cin >> n >> k;     for (int i = 1; i <= (int)(n); ++i) {       cin >> a[i];     }     for (int i = (int)(0); i <= (int)(n); ++i) {       for (int j = (int)(0); j <= (int)(n); ++j) {         dp[i][j] = -1e9;       }     }     dp[0][0] = 0;     for (int i = 1; i <= (int)(n); ++i) {       for (int j = (int)(0); j <= (int)(i); ++j) {         if (j > 0) {           uax(dp[i][j], dp[i - 1][j - 1]);         }         uax(dp[i][j], dp[i - 1][j] + (a[i] == i - j));       }     }     for (int i = 0; i < (int)(n); ++i) {       if (dp[n][i] >= k) {         cout << i <<   n ;         return;       }     }     cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int T = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }