malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:67108864 )   const int MOD = 1000000007;   const long long INF = 3000000000000000001;   const double EPS = 1e-6;   const int HASH_POW = 29;   const double PI = acos(-1.0);   using namespace std;   double workTime() { return double(clock()) / CLOCKS_PER_SEC; }   void my_return(int code) { exit(code); }   int cnt[1000000];   void add(string s) {     reverse(s.begin(), s.end());     int len = s.length();     int ptr = 0;     for (int i = 0; i < 18; ++i) {       int bit;       if (i < len)         bit = (s[i] -  0 ) % 2;       else         bit = 0;       ptr += bit * (1 << i);     }     ++cnt[ptr];   }   void destroy(string s) {     reverse(s.begin(), s.end());     int len = s.length();     int ptr = 0;     for (int i = 0; i < 18; ++i) {       int bit;       if (i < len)         bit = (s[i] -  0 ) % 2;       else         bit = 0;       ptr += bit * (1 << i);     }     --cnt[ptr];   }   int count(string s) {     reverse(s.begin(), s.end());     int len = s.length();     int ptr = 0;     for (int i = 0; i < 18; ++i) {       int bit;       if (i < len)         bit = (s[i] -  0 ) % 2;       else         bit = 0;       ptr += bit * (1 << i);     }     return cnt[ptr];   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     mt19937 mt_rand(time(0));     int q;     cin >> q;     while (q--) {       char c;       string v;       cin >> c >> v;       if (c ==  + )         add(v);       else if (c ==  - )         destroy(v);       else if (c ==  ? )         cout << count(v) << endl;       else         return 1;     }     my_return(0);   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, i, j, a[1000000], b[1000000], x, res = 1;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       cin >> x;       b[x] = i;     }     while (b[a[res]] > b[a[res - 1]]) {       res++;     }     res = n - res;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h, cen;     long long n, num;     while (scanf( %d%I64d , &h, &n) != EOF) {       num = (long long)pow(2.0, h) - 1 + n;       int flag;       long long ans = 0;       if (num % 2 == 0)         flag = 0;       else         flag = 1;       cen = h - 1;       while (1) {         ans++;         num /= (long long)2;         if (num % 2 == 0) {           if (flag == 0) ans += (long long)pow(2.0, h - cen) - (long long)1.0;           flag = 0;         } else {           if (flag == 1) ans += (long long)pow(2.0, h - cen) - (long long)1.0;           flag = 1;         }         if (num == 1) break;         cen--;       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int used[110];   int v[110][110];   vector<int> ans;   int main() {     int n, x;     memset(used, 0, sizeof(used));     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> x;         if (x == 1) {           used[i] = 1;         } else if (x == 2) {           used[j] = 1;         } else if (x == 3) {           used[i] = used[j] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       if (!used[i]) {         ans.push_back(i);       }     }     cout << ans.size() << endl;     if (!ans.size()) return 0;     bool cond = true;     for (int i = 0; i < (int)ans.size(); i++) {       if (!cond) cout <<    ;       cout << ans[i];       cond = false;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long P = 998244353;   double PI = 3.141592653589793;   const int sqr = 500;   const int arrn = 2e5 + 5;   const int arrn2 = 1e3 + 5;   long long inv[arrn] = {};   long long fac[arrn] = {};   void prefinv(int n, int p) {     inv[0] = 1;     inv[1] = 1;     fac[1] = 1;     fac[0] = 1;     for (int i = 2; i <= n; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= p;       inv[i] = (p - (((p / i) * inv[p % i]) % p)) % p;     }     for (int i = 2; i <= n; i++) {       inv[i] = inv[i] * inv[i - 1];       inv[i] %= p;       if (inv[i] < 0) inv[i] += p;     }   }   long long comb(int n, int r, int mod) {     if (n < r)       return 0;     else {       long long temp = fac[n];       temp *= inv[r];       temp %= mod;       temp *= inv[n - r];       temp %= mod;       return temp;     }   }   long long binpow(long long a, long long n, long long p) {     long long ret = 1;     while (n) {       if (n & 1) ret *= a;       ret %= p;       a *= a;       a %= p;       n /= 2;     }     return ret;   }   void solve() {     prefinv(arrn - 1, P);     int n;     long long k;     cin >> n >> k;     if (k > n - 1) {       cout << 0;       return;     }     long long out = 0;     for (int i = k; i < n; i++) {       if ((i - k) & 1) {         out = (out - ((comb(n - k, i - k, P) * binpow(n - i, n, P)) % P)) % P;       } else {         out = (out + ((comb(n - k, i - k, P) * binpow(n - i, n, P)) % P)) % P;       }     }     out = (out * comb(n, k, P)) % P;     if (k > 0) out *= 2;     out %= P;     cout << (out + P) % P;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int T = 1;     for (int c = 0; c < T; c++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int dif;     cin >> s >> dif;     set<char> st;     for (int i = (0); i < s.length(); i++) st.insert(s[i]);     if (s.length() < dif) {       cout <<  impossible  << endl;     } else if (st.size() >= dif)       cout << 0;     else       cout << dif - st.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int a, b;       cin >> a >> b;       int a1 = 2 * min(a, b);       int a2 = max(a, b);       cout << pow(max(a1, a2), 2) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, viz[1005], n;   int sol[100005], nrsol;   int main(void) {     cin >> n;     for (i = 2; i <= n; ++i)       if (viz[i] == 0) {         int nrp = i;         int put = nrp;         while (put <= n) {           sol[++nrsol] = put;           put *= nrp;         }         for (j = 2; j * i <= n; ++j) viz[i * j] = 1;       }     cout << nrsol <<   n ;     for (i = 1; i <= nrsol; ++i) cout << sol[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   long long a00, a01, a10, a11;   long long newton(long long n) { return n * (n - 1) / 2; }   long long sqrNewton(long long x) {     long long n = 0;     while (newton(n) < x) n++;     return newton(n) == x ? n : -1;   }   int W[MAXN];   bool policz(long long zero, long long one) {     long long ile = zero * one;     long long n = zero + one;     if (zero < 0 || one < 0 || (newton(n) != a00 + a01 + a10 + a11) || ile < a01)       return false;     int suf = 0;     while (one > 0 && ile - one >= a01) {       suf++;       ile -= one;       if (suf > zero) return false;     }     for (int i = 1; i <= n; i++) W[i] = 1;     for (int i = 1; i <= zero - suf; i++) W[i] = 0;     for (int i = 1; i <= suf; i++) W[n - i + 1] = 0;     long long p = ile - a01;     if (p > 0) {       W[zero - suf + p] = 0;       W[zero - suf] = 1;     }     for (int i = 1; i <= n; i++) cout << W[i];     return true;   }   int main() {     cin >> a00 >> a01 >> a10 >> a11;     if (a00 == 0 && a01 == 0 && a10 == 0 && a11 == 0) {       cout <<  0 ;       return 0;     }     vector<long long> zero;     vector<long long> one;     zero.push_back(sqrNewton(a00));     one.push_back(sqrNewton(a11));     if (a00 == 0) zero.push_back(1);     if (a11 == 0) one.push_back(1);     int d1 = zero.size();     int d2 = one.size();     for (int i = 0; i < d1; i++)       for (int j = 0; j < d2; j++)         if (policz(zero[i], one[j])) return 0;     cout <<  Impossible ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e6;   const long long LINF = 8e18;   const int MOD = 1e9 + 7;   const long double EPS = 1e-9;   int n;   vector<long long> a;   struct triplet {     int ti, i, j;   };   vector<struct triplet> s;   int cnt[INF];   int main() {     scanf( %d , &n);     ;     if (n == 1) {       printf( 0 );       return 0;     }     for (int i = 0; i < INF; i++) cnt[i] = 0;     for (int i = 0; i < n; i++) {       long long X;       scanf( %lld , &X);       a.push_back(X);       cnt[X]++;     }     int mx = -1, mx_i = 0;     for (int i = 0; i < n; i++) mx = max(mx, cnt[a[i]]);     for (int i = 0; i < n; i++)       if (mx == cnt[a[i]]) mx_i = i;     for (int i = mx_i + 1; i < n; i++) {       if (a[i] < a[mx_i]) s.push_back({1, i, i - 1});       if (a[i] > a[mx_i]) s.push_back({2, i, i - 1});     }     for (int i = mx_i - 1; i > -1; i = i - 1) {       if (a[i] < a[mx_i]) s.push_back({1, i, i + 1});       if (a[i] > a[mx_i]) s.push_back({2, i, i + 1});     }     printf( %ld , s.size());     for (struct triplet it : s) {       printf(  n );       printf( %d %d %d , it.ti, it.i + 1, it.j + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, c, x, ans;     cin >> t;     while (t--) {       ans = 0;       x = -1;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         if (a[i] == 1) {           if (x == -1) {             x = i;           } else {             ans = ans + (i - x - 1);             x = i;           }         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, b, i, rez, a[2013], minn[2013], maxx[2013];   int main() {     minn[0] = 123456890;     cin >> n >> b;     for (i = 1; i <= n; ++i) {       cin >> a[i];       minn[i] = min(minn[i - 1], a[i]);     }     for (i = n; i >= 1; --i) {       maxx[i] = max(maxx[i + 1], a[i]);     }     for (i = 1; i <= n; ++i) {       rez = max(rez, b / minn[i] * maxx[i] + b % minn[i]);     }     cout << rez;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second < b.second) return true;     if (a.second == b.second) return a.first < b.first;     return false;   }   bool isprime(int n) {     if (n <= 1) return false;     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   bool isPowerOfTwo(int n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     return (a / gcd(a, b)) * b;   }   long long int ncr(long long int n, long long int r) {     if (r == 0) return 1;     r = min(r, n - r);     long long int ans = 1;     for (int i = 1; i <= r; i++) {       ans *= (n - i + 1);       ans /= i;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       int n, m;       cin >> n >> m;       vector<pair<int, int>> v;       int x, y;       for (int i = 0; i < m; i++) {         cin >> x >> y;         v.push_back(make_pair(x, y));       }       int ans = 0;       if (v[0].first != 1) {         cout << 1 <<     << 0 <<   n ;       } else {         int dayno = -1;         for (int i = 1; i < v.size(); i++) {           if (v[i].first == v[i - 1].second) {             ans = 2;             dayno = v[i].first;             int j = i + 1;             while (j < v.size() && v[j].first == v[i].first) ans++, j++;             break;           } else if (v[i].first != v[i - 1].second + 1) {             dayno = v[i - 1].second + 1;             ans = 0;             break;           }         }         if (dayno != -1)           cout << dayno <<     << ans <<   n ;         else {           if (v[v.size() - 1].second != n)             cout << v[v.size() - 1].second + 1 <<     << 0 <<   n ;           else             cout <<  OK                   <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int dp[100005], x[105], s[105];   bool vis[100005];   int main() {     int n, m, minv = INF;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &x[i], &s[i]);       minv = min(minv, x[i]);       for (int j = max(x[i] - s[i], 1); j <= min(x[i] + s[i], m); ++j) {         vis[j] = true;       }     }     memset(dp, INF, sizeof(dp));     dp[0] = 0;     for (int i = 1; i <= m; ++i) {       if (vis[i])         dp[i] = min(dp[i - 1], dp[i]);       else {         if (i >= minv) dp[i] = min(dp[i], dp[i - 1] + 1);         for (int j = 0; j < n; ++j) {           if (x[j] > i) {             int tem = x[j] - s[j] - i;             dp[min(m, x[j] + s[j] + tem)] =                 min(dp[min(x[j] + s[j] + tem, m)], dp[i - 1] + tem);           }         }       }     }     printf( %d n , dp[m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:16777216 )   const int fin = 111110;   struct T {     int cnt, val, l, r, mx, y, ans;     T() : cnt(0), val(-1), l(fin), r(fin), mx(-1000000000), y(-1), ans(-1) {}   };   T a[111111];   void upd(int v) {     a[v].cnt = 1 + a[a[v].r].cnt + a[a[v].l].cnt;     a[v].mx = max(a[v].val, max(a[a[v].r].mx, a[a[v].l].mx));   }   void split(int v, int &l, int &r, int key) {     l = r = fin;     if (v == fin) return;     if (key && (a[v].l == -1 || a[a[v].l].cnt < key)) {       l = v;       split(a[v].r, a[v].r, r, key - a[a[v].l].cnt - 1);       upd(l);     } else {       r = v;       split(a[v].l, l, a[v].l, key);       upd(r);     }   }   int merge(int l, int r) {     if (l == fin) return r;     if (r == fin) return l;     if (a[l].y < a[r].y) {       a[l].r = merge(a[l].r, r);       upd(l);       return l;     } else {       a[r].l = merge(l, a[r].l);       upd(r);       return r;     }   }   int root, m;   void push(int val) {     a[m].y = (rand() << 16) + rand();     a[m].val = val;     a[m].cnt = 1;     a[m].mx = val;     a[m].ans = m + 1;     root = merge(root, m++);   }   int tot = 0;   void print(int v) {     if (v == fin) return;     if (a[v].l != fin) print(a[v].l);     {       if (tot)         printf(   );       else         tot = 1;       printf( %d , a[v].ans);     }     if (a[v].r != fin) print(a[v].r);   }   int fmin(int st, int fn) {     int r1, r2, r3, r4;     split(root, r1, r2, st);     split(r2, r3, r4, fn - st);     int rez = (r3 != -1) ? (a[r3].mx) : (-1000000000);     root = merge(r1, r3);     root = merge(root, r4);     return rez;   }   int n, A, C;   int find(int v, int maxim, int value, int lft) {     if (a[a[v].r].cnt + 1 > maxim)       return find(a[v].r, maxim, value, lft + 1 + a[a[v].l].cnt);     else if (a[a[v].r].mx > value)       return find(a[v].r, maxim, value, lft + 1 + a[a[v].l].cnt);     else if (a[v].val > value)       return lft + a[a[v].l].cnt;     else       return find(a[v].l, maxim - 1 - a[a[v].r].cnt, value, lft);   }   int main() {     a[fin].cnt = 0;     a[fin].mx = -1000000000;     scanf( %d , &n);     for (int(i) = 0; (i) < (n); ++(i)) {       scanf( %d%d , &A, &C);       if (i) {         int high = max(i - C, 0);         if (fmin(high, i) > A) high = find(root, C, A, 0) + 1;         int r1, r2;         split(root, r1, r2, high);         root = r1;         push(A);         root = merge(root, r2);       } else {         a[0].val = A;         a[0].ans = 1;         a[0].cnt = 1;         a[0].mx = A;         root = 0;         m = 1;       }     }     print(root);     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k, l, x = 1;     cin >> n >> m >> k >> l;     if (k + l > n)       cout <<  -1 ;     else if ((k + l) % m == 0 && (k + l) <= n)       cout << (k + l) / m;     else if ((k + l) % m != 0 && ((k + l) / m + 1) * m <= n)       cout << ((k + l) / m) + 1;     else       cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (n == 1) {       cout << 1;       return 0;     }     if (n & 1) {       if (m <= n / 2)         cout << m + 1;       else         cout << m - 1;     } else {       if (m <= n / 2)         cout << m + 1;       else         cout << m - 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch -  0  < 0 || ch -  0  > 9) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch -  0  >= 0 && ch -  0  <= 9) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m;   int a[55], w[55];   int A, B;   int f[55][55][55];   int inv[3010];   int quick_pow(int x, int p) {     int an = 1;     int po = x;     while (p) {       if (p & 1) an = 1ll * an * po % 998244353;       po = 1ll * po * po % 998244353;       p >>= 1;     }     return an;   }   void solve(int id) {     memset(f, 0, sizeof(f));     f[0][0][0] = 1;     for (int i = 0; i < m; i++) {       for (int j = 0; j <= i; j++) {         for (int k = 0; k <= i; k++) {           if (!f[i][j][k]) continue;           if (a[id]) {             int nowA = A + k, nowB = B - (i - k), sum = A + B + k - (i - k),                 noww = w[id] + j;             f[i + 1][j + 1][k + 1] +=                 1ll * f[i][j][k] * noww % 998244353 * inv[sum] % 998244353;             f[i + 1][j + 1][k + 1] %= 998244353;             f[i + 1][j][k + 1] += 1ll * f[i][j][k] * (nowA - noww) % 998244353 *                                   inv[sum] % 998244353;             f[i + 1][j][k + 1] %= 998244353;             f[i + 1][j][k] +=                 1ll * f[i][j][k] * nowB % 998244353 * inv[sum] % 998244353;             f[i + 1][j][k] %= 998244353;           } else {             int nowA = A + k, nowB = B - (i - k), sum = A + B + k - (i - k),                 noww = w[id] - j;             f[i + 1][j + 1][k] +=                 1ll * f[i][j][k] * noww % 998244353 * inv[sum] % 998244353;             f[i + 1][j + 1][k] %= 998244353;             f[i + 1][j][k + 1] +=                 1ll * f[i][j][k] * nowA % 998244353 * inv[sum] % 998244353;             f[i + 1][j][k + 1] %= 998244353;             f[i + 1][j][k] += 1ll * f[i][j][k] * (nowB - noww) % 998244353 *                               inv[sum] % 998244353;             f[i + 1][j][k] %= 998244353;           }         }       }     }     int res = 0;     for (int j = 0; j <= m; j++) {       for (int k = 0; k <= m; k++) {         if (!f[m][j][k]) continue;         if (a[id])           res = (res + 1ll * (w[id] + j) * f[m][j][k] % 998244353) % 998244353;         else           res = (res + 1ll * (w[id] - j) * f[m][j][k] % 998244353) % 998244353;       }     }     printf( %d n , res);   }   int main() {     n = read();     m = read();     for (int i = 1; i <= 3000; i++) inv[i] = quick_pow(i, 998244353 - 2);     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) w[i] = read();     for (int i = 1; i <= n; i++) A += w[i] * (a[i] == 1), B += w[i] * (a[i] == 0);     for (int i = 1; i <= n; i++) solve(i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxk = 105, maxn = 2e5 + 5, inf = 1e9;   int n, k, l[maxk], r[maxk], dp[2][maxn];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= k; ++i) scanf( %d %d , l + i, r + i);     if (l[k] != 2 * n) {       ++k;       l[k] = r[k] = 2 * n;     }     for (int t = 0; t < maxn; ++t) dp[1][t] = inf;     dp[1][l[1]] = 0;     for (int j = 2; j <= k; ++j) {       for (int t = 0; t < maxn; ++t) dp[j & 1][t] = inf;       for (int t = l[j] - l[j - 1]; t <= l[j]; ++t) {         dp[j & 1][t] = min(dp[j & 1][t], dp[(j - 1) & 1][t - l[j] + l[j - 1]]);       }       deque<pair<int, int> > minq;       for (int s = 0; s <= l[j]; ++s) {         int val = dp[(j - 1) & 1][s] + 1;         while (!minq.empty() && minq.back().first >= val) minq.pop_back();         minq.push_back({val, s});         while (!minq.empty() && minq.front().second + r[j - 1] - l[j - 1] < s)           minq.pop_front();         int t = l[j] - s;         dp[j & 1][t] = min(dp[j & 1][t], minq.front().first);       }       while (!minq.empty()) minq.pop_back();       for (int s = 0; s <= r[j - 1]; ++s) {         int val = dp[(j - 1) & 1][s] + 2;         while (!minq.empty() && minq.back().first >= val) minq.pop_back();         minq.push_back({val, s});         while (!minq.empty() && minq.front().second + r[j - 1] - l[j - 1] < s)           minq.pop_front();         int t = s + l[j] - r[j - 1];         dp[j & 1][t] = min(dp[j & 1][t], minq.front().first);       }     }     if (dp[k & 1][n] == inf)       printf( Hungry n );     else       printf( Full n%d n , dp[k & 1][n]);   }
#include <bits/stdc++.h>   long long mod = 1e9 + 7;   int main() {     long long n, m;     std::cin >> n >> m;     std::string s;     std::cin >> s;     std::vector<std::vector<long long>> dp(n - m + 1,                                            std::vector<long long>(n - m + 1));     dp[0][0] = 1;     for (long long i = 1; i < n - m + 1; ++i)       for (long long j = 0; j < n - m + 1; ++j) {         dp[i][j] = 0;         if (j > 0) dp[i][j] += dp[i - 1][j - 1];         if (j < n - m) dp[i][j] += dp[i - 1][j + 1];         dp[i][j] %= mod;       }     long long min = 0, balance = 0;     for (long long i = 0; i < m; ++i)       if (s[i] ==  ( )         ++balance;       else if (--balance < min)         min = balance;     long long res = 0;     for (long long left = 0; left <= n - m; ++left)       for (long long here = -min; here <= left; ++here)         if (here + balance <= n - m - left)           res = (res + dp[left][here] * dp[n - m - left][here + balance]) % mod;     std::cout << res;     return 0;   }
#include <bits/stdc++.h>   char a[300][300];   int n, m, t, z, s;   const int X[8] = {0, 1, 0, -1, 1, 1, -1, -1},             Y[8] = {1, 0, -1, 0, 1, -1, 1, -1};   void F(int x, int y, int &s) {     if (x < 0 || x >= n || y < 0 || y >= m || a[x][y] !=  1 ) return;     a[x][y] =  2 , s++;     for (int i = 0; i < 8; i++) F(x + X[i], y + Y[i], s);   }   int C(int x, int y, int d, int l, int r) {     for (int i = 0; i < d + 1; i++)       for (int j = l; j < r; j++)         if (x + X[j] * i < 0 || x + X[j] * i >= n || y + Y[j] * i < 0 ||             y + Y[j] * i >= m || a[x + X[j] * i][y + Y[j] * i] !=  2 )           return 0;     return 1;   }   int main() {     for (scanf( %d , &t); t; t--) {       scanf( %d%d , &n, &m), z = 0;       for (int i = 0; i < n; i++) scanf( %s , a[i]);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (a[i][j] ==  1 ) {             F(i, j, s = 0);             if (s % 4 || s / 4 > 250) continue;             z += C(i, j, s / 4, 0, 2) && C(i + s / 4, j + s / 4, s / 4, 2, 4);             z += C(i, j, s / 4, 4, 6) && C(i + s / 2, j, s / 4, 6, 8);           }       printf( %d n , z);     }     return 0;   }