malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t, n, m, i, j;     cin >> n >> m;     string a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     long long f = 0;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (a[i][j] ==  . ) continue;         if (i - 1 >= 0 && j - 1 >= 0 && a[i - 1][j] ==  X  &&             a[i][j - 1] ==  X  && a[i - 1][j - 1] ==  . ) {           f = 1;           break;         }         if (i - 1 >= 0 && j + 1 < n && a[i - 1][j] ==  X  && a[i][j + 1] ==  X  &&             a[i - 1][j + 1] ==  . ) {           f = 1;           break;         }         if (i + 1 < n && j - 1 >= 0 && a[i][j - 1] ==  X  && a[i + 1][j] ==  X  &&             a[i + 1][j - 1] ==  . ) {           f = 1;           break;         }         if (i + 1 < n && j + 1 < n && a[i + 1][j] ==  X  && a[i][j + 1] ==  X  &&             a[i + 1][j + 1] ==  . ) {           f = 1;           break;         }       }       if (f) break;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (a[i][j] ==  . ) continue;         if (i - 1 >= 0 && j - 1 >= 0 && a[i - 1][j - 1] ==  X  &&             (a[i - 1][j] ==  .  || a[i][j - 1] ==  . )) {           f = 1;           break;         }         if (i - 1 >= 0 && j + 1 < n && a[i - 1][j + 1] ==  X  &&             (a[i - 1][j] ==  .  || a[i][j + 1] ==  . )) {           f = 1;           break;         }         if (i + 1 < n && j - 1 >= 0 && a[i + 1][j - 1] ==  X  &&             (a[i + 1][j] ==  .  || a[i][j - 1] ==  . )) {           f = 1;           break;         }         if (i + 1 < n && j + 1 < n && a[i + 1][j + 1] ==  X  &&             (a[i + 1][j] ==  .  || a[i][j + 1] ==  . )) {           f = 1;           break;         }       }       if (f) break;     }     if (f)       cout <<  NO n ;     else       cout <<  YES n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   pair<int, pair<int, int> > A[maxn];   map<int, int> X;   map<int, int> Y;   int Hx[maxn], Hy[maxn];   int ans[maxn];   int fa[maxn];   int fi(int u) {     if (fa[u] == u) return u;     return fa[u] = fi(fa[u]);   }   void un(int u, int v) {     int p1 = fi(u), p2 = fi(v);     if (p1 != p2) fa[p1] = p2;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n * m; i++) {       fa[i] = i;       scanf( %d , &A[i].first);       A[i].second.first = i / m;       A[i].second.second = i % m;     }     int j = -1;     sort(A, A + n * m);     for (int i = 0; i < n * m; i++) {       if (i != n * m - 1 && A[i].first == A[i + 1].first) continue;       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         Hx[x] = p;         Hy[y] = p;       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         un(Hx[x], p);         un(Hy[y], p);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         int pa = fi(p);         ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         X[x] = max(X[x], ans[fi(p)]);         Y[y] = max(Y[y], ans[fi(p)]);       }       j = i;     }     for (int i = 0; i < n * m; i++) {       printf( %d  , ans[fi(i)]);       if (i % m == m - 1) printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> adj[100005], stx, sty;   long long mx = 0ll, ans[100005];   int sz[100005], par[100005];   pair<int, int> centroid = {0, 0};   bool cmp(int u, int v) { return sz[u] < sz[v]; }   void dfs(int nw, int bf) {     par[nw] = bf;     sz[nw] = 1;     for (int nx : adj[nw])       if (nx != bf) {         dfs(nx, nw);         sz[nw] += sz[nx];       }     sort(adj[nw].begin(), adj[nw].end(), cmp);     mx += 2 * min(sz[nw], n - sz[nw]);     centroid = max(centroid, {min(sz[nw], n - sz[nw]), nw});   }   void get_subtree(int nw, int bf, vector<int> &v) {     v.push_back(nw);     for (int nx : adj[nw])       if (nx != bf) get_subtree(nx, nw, v);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int u, v, i = 1; i < n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     int x = centroid.second, y = par[x];     if (sz[x] * 2 > n) swap(x, y);     get_subtree(x, y, stx);     get_subtree(y, x, sty);     for (int i = 0; i < stx.size(); i++) {       ans[stx[i]] = sty[i];       ans[sty[sty.size() - stx.size() + i]] = stx[i];     }     for (int i = 0; i < sty.size() - stx.size(); i++)       ans[sty[i]] = sty[stx.size() + i];     cout << mx << endl;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a, b;   bool temp = false;   int main() {     cin >> a;     for (b = 1; b <= 500; b++)       if ((b * (b + 1)) / 2 == a) {         temp = true;         break;       }     if (temp)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e5 + 9, lg = 20;   int n, q, timer = 1;   vector<int> adj[inf], level[inf];   int depth[inf], in[inf], out[inf], parent[inf][lg];   void dfs(int u, int par) {     in[u] = timer++;     level[depth[u]].push_back(in[u]);     for (auto v : adj[u])       if (v != par) parent[v][0] = u, depth[v] = depth[u] + 1, dfs(v, u);     out[u] = timer++;   }   int KthParent(int u, int k) {     for (int j = lg - 1; j >= 0; j--)       if (k & (1ll << j)) u = parent[u][j];     return u;   }   int CntLevelInSubtree(int u, int h) {     return upper_bound(level[h].begin(), level[h].end(), out[u]) -            lower_bound(level[h].begin(), level[h].end(), in[u]);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       if (tmp) adj[tmp].push_back(i), adj[i].push_back(tmp);     }     for (int i = 1; i <= n; i++)       if (!in[i]) dfs(i, 0);     for (int j = 1; j < lg; j++)       for (int i = 1; i <= n; i++) parent[i][j] = parent[parent[i][j - 1]][j - 1];     cin >> q;     while (q--) {       int v, p;       cin >> v >> p;       if (depth[v] < p) {         cout << 0 <<    ;         continue;       }       int u = KthParent(v, p);       cout << CntLevelInSubtree(u, depth[v]) - 1 <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1000000 + 5;   int f[maxn], inv[maxn], finv[maxn];   void init() {     inv[1] = 1;     for (int i = 2; i < maxn; i++)       inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;     f[0] = finv[0] = 1;     for (int i = 1; i < maxn; i++) {       f[i] = f[i - 1] * 1ll * i % mod;       finv[i] = finv[i - 1] * 1ll * inv[i] % mod;     }   }   int C(int n, int m) {     if (m < 0 || m > n) return 0;     return f[n] * 1ll * finv[n - m] % mod * finv[m] % mod;   }   long long qpow(long long x, long long n) {     long long r = 1;     while (n > 0) {       if (n & 1) r = r * x % mod;       n >>= 1;       x = x * x % mod;     }     return r;   }   long long T(long long n, long long k) {     if (k == n) return 1;     return k * qpow(n, n - k - 1) % mod;   }   int n, m, a, b;   int main() {     init();     cin >> n >> m >> a >> b;     long long ans = 0;     for (int i = 1; i < n; i++) {       long long tot = 1ll * C(m - 1, i - 1) * C(n - 2, i - 1) % mod * f[i - 1] %                       mod * qpow(m, n - i - 1) % mod * T(n, i + 1) % mod;       ans += tot;       if (ans >= mod) ans -= mod;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int func1(long long int i) {     long long int m = i;     return i * (i + 1) * (2 * i + 1) / 6 - (m + m + 2) * i * (i + 1) / 2 +            (m + m + 1 + m * m) * i;   }   long long int func2(long long int x, long long int i) {     return x * (i + i * i - i * (i + 1) / 2);   }   int main() {     long long int inp, tem, ans = 0, tem2;     cin >> inp;     vector<pair<long long int, long long int> > v;     bool flag = 0;     for (int i = 0; i < 100000000; i++)       if (ans > 0) ans += 1;     ans = 0;     for (long long int i = 1; func1(i) <= inp; i++) {       tem = inp - func1(i);       if (!tem) {         flag = 1;         v.push_back(make_pair(i, i));       } else {         tem2 = func2(1, i);         if (tem % tem2 == 0) v.push_back(make_pair(i, i + tem / tem2));       }     }     if (!flag)       cout << 2 * v.size();     else       cout << 2 * v.size() - 1;     cout <<   n ;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second <<   n ;     int i = v.size() - 1;     if (flag) i--;     for (; i >= 0; i--) cout << v[i].second <<     << v[i].first <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkMax(T &x, T y) {     if (y > x) x = y;   }   template <typename T>   void chkMin(T &x, T y) {     if (y < x) x = y;   }   template <typename T>   void inline read(T &x) {     int f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s <=  9  && s >=  0 ) x = x * 10 + (s ^ 48), s = getchar();     x *= f;   }   const int N = 2005;   int n, f[10][10][10][10][10], g[10][10][10][10][10];   int ans = 2e9;   int main() {     read(n);     memset(f, 0x3f, sizeof f);     f[1][0][0][0][0] = 0;     for (int i = 1; i <= n; i++) {       int x, y;       read(x), read(y);       memcpy(g, f, sizeof f);       memset(f, 0x3f, sizeof f);       for (int p = 1; p <= 9; p++) {         for (int a = 0; a <= 9; a++) {           for (int b = 0; b <= 9; b++) {             for (int c = 0; c <= 9; c++) {               for (int d = 0; d <= 9; d++) {                 if (a == 0) {                   chkMin(f[x][y][b][c][d], g[p][a][b][c][d] + abs(p - x));                 }                 if (b == 0) {                   chkMin(f[x][a][y][c][d], g[p][a][b][c][d] + abs(p - x));                 }                 if (c == 0) {                   chkMin(f[x][a][b][y][d], g[p][a][b][c][d] + abs(p - x));                 }                 if (d == 0) {                   chkMin(f[x][a][b][c][y], g[p][a][b][c][d] + abs(p - x));                 }               }             }           }         }       }       for (int a = 9; ~a; a--) {         for (int b = 9; ~b; b--) {           for (int c = 9; ~c; c--) {             for (int d = 9; ~d; d--) {               for (int p = 1; p <= 9; p++) {                 if (a) chkMin(f[a][0][b][c][d], f[p][a][b][c][d] + abs(p - a));                 if (b) chkMin(f[b][a][0][c][d], f[p][a][b][c][d] + abs(p - b));                 if (c) chkMin(f[c][a][b][0][d], f[p][a][b][c][d] + abs(p - c));                 if (d) chkMin(f[d][a][b][c][0], f[p][a][b][c][d] + abs(p - d));               }             }           }         }       }     }     for (int i = 1; i <= 9; i++) chkMin(ans, f[i][0][0][0][0]);     printf( %d n , ans + 2 * n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int k = 0, l = 0, n;     cin >> a >> b;     n = a.size();     for (int i = 0; i < n; i++) {       if (a[i] ==  4  && b[i] ==  7 ) {         k++;       } else if (a[i] ==  7  && b[i] ==  4 ) {         l++;       }     }     int p = max(k, l);     cout << p << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   T gcd(T a, T b) {     return ((b == 0) ? a : gcd(b, a % b));   }   void solve() {     int n, k;     long long x;     cin >> n >> k >> x;     string s;     cin >> s;     x--;     int cnt = 0;     vector<int> nm;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  * )         cnt++;       else {         if (cnt) nm.push_back(cnt);         cnt = 0;       }     }     if (cnt) nm.push_back(cnt);     int uwu = 0;     vector<int> d;     while (x > 0) {       int cr = (nm[uwu++] * k) + 1;       d.push_back(x % cr);       x /= cr;     }     int ind = 0, lst = -1;     string ans =   ;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  a )         ans +=  a , lst = 1;       else {         if (!lst) continue;         if (ind == (int)(d.size())) continue;         for (int j = 0; j < (int)(d[ind]); j++) ans +=  b ;         ind++;         lst = 0;       }     }     reverse(ans.begin(), ans.end());     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       long long n, s, t;       cin >> n >> s >> t;       cout << max(n - s + 1, n - t + 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[105], g[105][2], q[105], t, n;   int main() {     f[1] = 1;     f[2] = 2;     for (int i = 3; i <= 86; ++i) f[i] = f[i - 1] + f[i - 2];     int cases;     for (scanf( %d , &cases); cases--;) {       scanf( %I64d , &n);       t = 0;       for (int i = 86; i; --i)         if (f[i] <= n) q[++t] = i, n -= f[i];       g[t][0] = 1;       g[t][1] = (q[t] - 1) >> 1;       for (int i = t - 1; i; --i) {         g[i][0] = g[i + 1][0] + g[i + 1][1];         int l = q[i] - q[i + 1] - 1;         g[i][1] = (l >> 1) * g[i + 1][0] + ((l + 1) >> 1) * g[i + 1][1];       }       printf( %I64d n , g[1][0] + g[1][1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace runzhe2000 {   const int INF = 1 << 29;   int ft[100005], gt[100005], f[100005][10], g[100005][10], timer = 1, c[10],                                                             sta[100005], top;   char s[100005];   bool insta[100005];   struct node {     int l, r, v;   } no[100005];   void del(int x) {     no[no[x].l].r = no[x].r;     no[no[x].r].l = no[x].l;   }   void main() {     int n, q;     scanf( %d%d%s , &n, &q, s + 1);     for (int i = 1, v; i <= n; i++) {       if (s[i] >=  0  && s[i] <=  9 )         v = s[i] -  0 ;       else         v = s[i] ==  <  ? 11 : 10;       no[i] = (node){i - 1, i + 1, v};     }     memset(ft, 63, sizeof(ft));     memset(gt, 63, sizeof(gt));     ++timer;     ++n;     no[n] = (node){n - 1, n + 1, 10};     for (int l = 1; l <= n; l++)       if (ft[l] > INF) {         for (int cur = l, next, pos = 10; l <= cur && cur <= n;              cur = next, ++timer) {           if (timer < ft[cur]) {             ft[cur] = timer;             for (int i = 0; i < 10; i++) f[cur][i] = c[i];           }           if (no[cur].v < 10) {             c[no[cur].v--]++;             if (no[cur].v < 0) del(cur);           } else {             pos = no[cur].v;           }           next = pos == 11 ? no[cur].l : no[cur].r;           if (no[cur].v > 9 && no[next].v > 9) del(cur);           if (!insta[cur]) sta[++top] = cur, insta[cur] = 1;           if (pos == 11) {             for (; no[cur].l < sta[top] && sta[top] <= cur && top; --top) {               gt[sta[top]] = ++timer;               for (int i = 0; i < 10; i++) g[sta[top]][i] = c[i];             }           }         }       }     for (; q--;) {       int l, r;       scanf( %d%d , &l, &r);       if (ft[r + 1] < gt[l]) {         for (int i = 0; i < 10; i++)           printf( %d%c , f[r + 1][i] - f[l][i], i == 9 ?   n  :    );       } else {         for (int i = 0; i < 10; i++)           printf( %d%c , g[l][i] - f[l][i], i == 9 ?   n  :    );       }     }   }   }  // namespace runzhe2000   int main() { runzhe2000::main(); }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int r = 0, b = 0, y = 0, g = 0;     int len = s.size();     for (int i = 0; i < len; i++) {       if (s[i] ==  B )         b = i % 4;       else if (s[i] ==  G )         g = i % 4;       else if (s[i] ==  R )         r = i % 4;       else if (s[i] ==  Y )         y = i % 4;     }     int w = 0, x = 0, yy = 0, z = 0, pos;     for (int i = 0; i < len; i++) {       if (s[i] ==  ! ) {         pos = i % 4;         if (pos == r)           w++;         else if (pos == b)           x++;         else if (pos == y)           yy++;         else if (pos == g)           z++;       }     }     cout << w <<     << x <<     << yy <<     << z << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, a[300005], b[300005];   int main() {     cin >> n >> k;     k--;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];     long long res = a[n] - a[1];     sort(b + 1, b + n);     for (int i = n - 1; i >= n - k; i--) res -= b[i];     cout << res;     return 0;   }
#include <bits/stdc++.h>   int main() {     char a[3][4];     int i, f;     for (i = 0; i < 3; i++) scanf( %s , a[i]);     if (a[0][0] == a[2][2] && a[0][1] == a[2][1] && a[0][2] == a[2][0] &&         a[1][0] == a[1][2])       f = 1;     else       f = 0;     if (f == 1)       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int T = 31;   const int mod = 1000000007;   const long long oo = 1LL << 60;   long long N;   int K;   long long B[T][T];   long long power[70];   long long dp[70][T][T];   bool bio[70];   long long rot[T][T][T];   long long mult(long long a, long long b) {     if (a == 0) return 0;     if (b >= oo / a + 1) return oo;     return a * b;   }   void mult(long long A[T][T], long long B[T][T]) {     static long long C[T][T];     for (int i = (0); i < (T); ++i)       for (int j = (0); j < (T); ++j) C[i][j] = 0;     for (int i = (0); i < (T); ++i)       for (int j = (0); j < (T); ++j)         for (int k = (0); k < (T); ++k)           C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;     for (int i = (0); i < (T); ++i)       for (int j = (0); j < (T); ++j) A[i][j] = C[i][j];   }   void rec(long long prefix, int n, long long A[T][T]) {     long long lo = mult(prefix, power[n]);     long long hi = lo + power[n] - 1;     if (lo >= N) return;     long long z = prefix % K;     mult(A, rot[z]);     if (n == 0) {       mult(A, B);     } else {       bool memo = hi < N;       auto AA = memo ? dp[n] : A;       if (!bio[n] && memo)         for (int i = (0); i < (T); ++i) AA[i][i] = 1;       if (!bio[n] || !memo)         for (int i = (0); i < (K); ++i) rec(prefix * K + i, n - 1, AA);       if (memo) bio[n] = true, mult(A, AA);     }     mult(A, rot[(K - z) % K]);   }   int main() {     scanf( %lld%d , &N, &K);     for (int i = (0); i < (K); ++i) B[i][i] = 1;     for (int i = (1); i < (K); ++i) B[i][0] = 1;     B[K][0] = 1;     B[K][K] = 1;     for (int x = (0); x < (K); ++x)       for (int i = (0); i < (K); ++i) rot[x][i][(i + x) % K] = 1;     for (int x = (0); x < (K); ++x)       for (int i = (K); i < (T); ++i) rot[x][i][i] = 1;     static long long A[T][T];     A[0][K] = 1;     power[0] = 1;     for (int i = (1); i < (70); ++i) power[i] = mult(power[i - 1], K);     rec(0, 69, A);     long long ans = 1;     for (int i = (0); i < (K); ++i) ans = (ans + A[0][i]) % mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     int n, p, q;     cin >> n;     vector<pair<int, int>> v1;     int x1, x2;     for (size_t i = 0; i < n; i++) {       cin >> x1 >> x2;       v1.push_back(make_pair(x1, x2));     }     bool s = true;     sort(v1.begin(), v1.end());     for (size_t i = 0; i < n; i++) {       if (v1[i].second > v1[i + 1].second && i + 1 < n) {         s = false;         break;       }     }     if (s == true) {       cout <<  Poor Alex ;     } else {       cout <<  Happy Alex ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n;   double f1[N], f2[N], f3[N], a[N], ans;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       f1[i] = a[i] * (f1[i - 1] + 1);       f2[i] = a[i] * (f2[i - 1] + 1 + 2 * f1[i - 1]);       f3[i] = a[i] * (f3[i - 1] + 3 * f2[i - 1] + 3 * f1[i - 1] + 1);     }     for (int i = 1; i <= n + 1; ++i) ans += (1 - a[i]) * f2[i - 1];     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> t;   int n, x, i, j, h, sol, temp;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       t.push_back(x);     }     cin >> h;     sort(t.begin(), t.end());     sol = 0;     for (i = 0; i < n; i++) {       temp = 1;       for (j = i + 1; j < n; j++) {         if (t[j] - t[i] <= h) temp++;       }       sol = max(sol, temp);     }     cout << sol << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 305;   int n, m;   class Point {    public:     long long x, y;     Point() : x(0), y(0) {}     Point(long long _x, long long _y) : x(_x), y(_y) {}     void read() { scanf( %lld%lld , &x, &y); }     Point operator+(const Point &o) const { return Point(x + o.x, y + o.y); }     Point operator-(const Point &o) const { return Point(x - o.x, y - o.y); }     long long operator*(const Point &o) const { return x * o.y - y * o.x; }     bool operator<(const Point &o) const {       int c = (y == 0 && x > 0) || (y > 0);       int oc = (o.y == 0 && o.x > 0) || (o.y > 0);       if (c != oc) return c > oc;       return (*this) * o > 0;     }   } p[maxn];   class Edge {    public:     Point w;     int u, v;     Edge() {}     Edge(Point _w, int _u, int _v) : w(_w), u(_u), v(_v) {}     bool operator<(const Edge &o) const { return w < o.w; }   } e[maxn * maxn];   long long dp[maxn][maxn][6];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) p[i].read();     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         e[m++] = Edge(p[j] - p[i], i, j);         e[m++] = Edge(p[i] - p[j], j, i);       }     sort(e, e + m);     for (int i = 0; i < n; i++) dp[i][i][0] = 1;     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < 5; k++) dp[j][e[i].v][k + 1] += dp[j][e[i].u][k];     long long ans = 0;     for (int i = 0; i < n; i++) ans += dp[i][i][5];     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, x;     cin >> n >> x;     string second;     cin >> second;     long long ans = 0;     long long sm = 0;     for (long long i = 0; i < n; i++) {       if (second[i] ==  0 )         sm++;       else         sm--;     }     long long c = 0;     for (long long i = 0; i < n; i++) {       if (sm == 0 && c == x) {         cout << -1 << endl;         return;       }       if ((x - c) % sm == 0 && (x - c) / sm >= 0 && sm != 0) ans++;       if (second[i] ==  0 )         c++;       else         c--;     }     cout << ans << endl;   }   int main() {     long long t;     cin >> t;     while (t--) solve();   }