malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   char mp[444][444];   struct node {     int num[8];   } np[444][444];   int dy[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   long long ans;   bool in(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }   void cal(int x, int y) {     for (int i = 0; i < 8; i++) {       int xx = x;       int yy = y;       while (in(xx, yy) && mp[xx][yy] ==  0 ) {         np[x][y].num[i]++;         xx += dx[i];         yy += dy[i];       }       np[x][y].num[i]--;     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , mp[i] + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (mp[i][j] ==  0 ) cal(i, j);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (mp[i][j] ==  0 ) {           long long cur = 0LL;           node &now = np[i][j];           for (int k = 0; k < 8; k++) {             if (k % 2 == 0) {               for (int l = 1; l <= now.num[k]; l++) {                 node &then = np[i + l * dx[k]][j + l * dy[k]];                 if (then.num[(k + 2) % 8] >= l && now.num[(k + 1) % 8] / 2 >= l)                   cur++;                 if (then.num[(k + 3) % 8] >= l && now.num[(k + 1) % 8] >= l)                   cur++;                 if (then.num[(k + 3) % 8] / 2 >= l && now.num[(k + 2) % 8] >= l)                   cur++;               }             } else {               for (int l = 1; l <= now.num[k]; l++) {                 node &then = np[i + l * dx[k]][j + l * dy[k]];                 if (l % 2 == 0 && then.num[(k + 3) % 8] >= l / 2 &&                     now.num[(k + 1) % 8] >= l / 2)                   cur++;                 if (then.num[(k + 2) % 8] >= l && now.num[(k + 1) % 8] >= l)                   cur++;                 if (then.num[(k + 3) % 8] >= l && now.num[(k + 2) % 8] >= l)                   cur++;               }             }           }           ans += cur;         }       }     }     printf( %I64d n , ans / 3);   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 2e5 + 5;   int x[MXN];   int y[MXN];   int d[MXN];   int xr[MXN];   int par[MXN];   int siz[MXN];   int sol[MXN];   int type[MXN];   int basis[30];   stack<pair<int *, int>> stk;   vector<array<int, 3>> st[2 << 18];   void change(int &ref, int val) {     stk.push({&ref, ref});     ref = val;   }   array<int, 2> get(int x) {     int len = 0;     while (par[x]) {       len ^= xr[x];       x = par[x];     }     return {x, len};   }   void join(int x, int y, int d) {     auto [px, xrx] = get(x);     auto [py, xry] = get(y);     if (px == py) {       int cycle = xrx ^ d ^ xry;       for (int i = 29; i >= 0; --i) {         if (cycle >> i & 1) {           if (basis[i]) {             cycle ^= basis[i];           } else {             change(basis[i], cycle);             break;           }         }       }     } else {       if (siz[px] < siz[py]) {         swap(px, py);       }       change(siz[px], siz[px] + siz[py]);       change(xr[py], xrx ^ d ^ xry);       change(par[py], px);     }   }   void dfs(int lo, int hi, int nd = 0) {     int sz = stk.size();     for (auto [x, y, d] : st[nd]) {       join(x, y, d);     }     if (lo + 1 == hi) {       sol[lo] ^= get(x[lo])[1];       sol[lo] ^= get(y[lo])[1];       for (int i = 29; i >= 0; --i) {         sol[lo] = min(sol[lo], sol[lo] ^ basis[i]);       }     } else {       int mid = (lo + hi) / 2;       dfs(lo, mid, 2 * nd + 1);       dfs(mid, hi, 2 * nd + 2);     }     while (sz < (int)stk.size()) {       auto [ptr, val] = stk.top();       *ptr = val;       stk.pop();     }   }   void add(int l, int r, array<int, 3> e, int lo, int hi, int nd = 0) {     if (l <= lo && hi <= r) return st[nd].push_back(e);     int mid = (lo + hi) / 2;     if (l < mid) add(l, r, e, lo, mid, 2 * nd + 1);     if (mid < r) add(l, r, e, mid, hi, 2 * nd + 2);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     map<array<int, 2>, array<int, 2>> mp;     for (int i = 0; i < m; ++i) {       int x, y, d;       cin >> x >> y >> d;       mp[{x, y}] = {0, d};     }     int q;     cin >> q;     int sz = 0;     for (int i = 0; i < q; ++i) {       cin >> type[i] >> x[i] >> y[i];       if (type[i] == 1) cin >> d[i];       sz += type[i] == 3;     }     int cq = 0;     for (int i = 0; i < q; ++i) {       if (type[i] == 1) {         mp[{x[i], y[i]}] = {cq, d[i]};       } else if (type[i] == 2) {         auto [pq, d] = mp[{x[i], y[i]}];         mp.erase({x[i], y[i]});         if (pq < cq) add(pq, cq, {x[i], y[i], d}, 0, sz);       } else {         x[cq] = x[i];         y[cq] = y[i];         cq++;       }     }     for (auto [a, b] : mp) {       if (b[0] < sz) add(b[0], sz, {a[0], a[1], b[1]}, 0, sz);     }     for (int i = 1; i <= n; ++i) {       siz[i] = 1;     }     dfs(0, sz);     for (int i = 0; i < sz; ++i) {       cout << sol[i] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int ans = 0;     while (n--) {       string t;       cin >> t;       int c = k;       for (char x : t)         if (x ==  4  || x ==  7 ) c--;       if (c >= 0) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, neg, zero;     cin >> x;     int arr[x];     for (int i = 0; i < x; i++) cin >> arr[i];     sort(arr, arr + x);     if (arr[x - 1] <= 0) {       cout <<  1             <<     << arr[0] << endl;       cout <<  2             <<     << arr[1] <<     << arr[2] << endl;       for (int i = 3; i < x; i++) {         if (i == 3)           cout << x - i <<     << arr[3];         else           cout <<     << arr[i];       }     } else {       for (int i = 0; i < x; i++) {         if (arr[i] < 0)           neg = i;         else if (arr[i] == 0)           zero = i;       }       cout <<  1   << arr[0] << endl;       cout << x - zero - 1 <<    ;       for (int i = zero + 1; i < x; i++) cout << arr[i] <<    ;       cout << endl;       cout << zero;       for (int i = 1; i <= zero; i++) cout <<     << arr[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const char c[3][4] = { RGB ,  GBR ,  BRG };   int sum[3][N];   char s[N];   int main() {     int n, k, T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &k);       sum[0][0] = sum[1][0] = sum[2][0] = 0;       scanf( %s , s);       if (k == 1) {         printf( 0 n );         continue;       }       for (int i = 0; i < 3; i++) {         for (int j = 0; j < n; j++) {           if (s[j] != c[i][j % 3]) {             sum[i][j + 1] = sum[i][j] + 1;           } else {             sum[i][j + 1] = sum[i][j];           }         }       }       int ans = N;       for (int p = 0; p < 3; p++) {         for (int i = 1; i + k - 1 <= n; i++) {           int j = i + k - 1;           ans = min(ans, sum[p][j] - sum[p][i - 1]);         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   char s[N];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       scanf( %s , s);       getchar();       vector<int> cnt(27, 0);       for (int i = 0; i < n; ++i) ++cnt[s[i] -  a ];       for (int len = n; len >= 1; --len) {         vector<int> circ, c_cnt, used(len, 0);         for (int i = 0; i < len; ++i) {           if (used[i]) continue;           used[i] = 1;           int j = (i + k) % len;           circ.push_back(1);           while (!used[j]) {             used[j] = 1;             circ.back()++;             j = (j + k) % len;           }         }         c_cnt = cnt;         sort(circ.begin(), circ.end());         sort(c_cnt.begin(), c_cnt.end());         int ok = 1;         while (!circ.empty()) {           if (circ.back() > c_cnt.back()) {             ok = 0;             break;           } else {             c_cnt.back() -= circ.back();             circ.pop_back();             sort(c_cnt.begin(), c_cnt.end());           }         }         if (ok) {           printf( %d n , len);           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, x, y, res;   vector<int> g[200200], o[200200];   bool u[3][200200], w[200200], ok = true;   char r[200200];   void dfs(int i, int z) {     u[z][i] = true;     w[i] = true;     for (int j = 0; j < g[i].size(); j++) {       int k = g[i][j];       if (w[k]) ok = false;       if (!u[z][k]) dfs(k, z);     }     w[i] = false;   }   void ofs(int i, int z) {     u[z][i] = true;     for (int j = 0; j < o[i].size(); j++) {       int k = o[i][j];       if (!u[z][k]) ofs(k, z);     }   }   int main() {     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       g[x].push_back(y);       o[y].push_back(x);     }     for (i = 1; ok && i <= n; i++)       if (!u[0][i]) dfs(i, 0);     if (!ok) {       puts( -1 );       return 0;     }     memset(u, 0, sizeof(u));     for (i = 1; i <= n; i++)       if (!u[0][i] && !u[1][i] && !u[2][i]) {         dfs(i, 0);         ofs(i, 0);         r[i - 1] =  A ;         res++;       } else {         r[i - 1] =  E ;         if (!u[1][i]) dfs(i, 1);         if (!u[2][i]) ofs(i, 2);       }     printf( %d n , res);     puts(r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, lim = 1e7 + 10, key = 1010;   int v[lim], r[lim], d[lim];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (long long i = 1, _b = (n); i <= _b; i++)       for (long long j = 1, _b = (m); j <= _b; j++) scanf( %d , v + key * i + j);     for (long long i = 0, _b = (n); i <= _b; i++)       for (long long j = 0, _b = (m); j <= _b; j++) {         r[key * i + j] = key * i + (j + 1);         d[key * i + j] = key * (i + 1) + j;       }     int _a, _b, _c, _d, h, w;     int x, y, x0, y0;     for (long long i = 0, _n = (q); i < _n; i++) {       scanf( %d%d%d%d%d%d , &_a, &_b, &_c, &_d, &h, &w);       x0 = 0;       while (--_a) x0 = d[x0];       while (--_b) x0 = r[x0];       y0 = 0;       while (--_c) y0 = d[y0];       while (--_d) y0 = r[y0];       x = x0, y = y0;       for (long long j = 0, _n = (h); j < _n; j++)         x = d[x], y = d[y], swap(r[x], r[y]);       for (long long j = 0, _n = (w); j < _n; j++)         x = r[x], y = r[y], swap(d[x], d[y]);       x = x0, y = y0;       for (long long j = 0, _n = (w); j < _n; j++)         x = r[x], y = r[y], swap(d[x], d[y]);       for (long long j = 0, _n = (h); j < _n; j++)         x = d[x], y = d[y], swap(r[x], r[y]);     }     x0 = 0;     for (long long i = 0, _n = (n); i < _n; i++) {       x0 = d[x0];       x = x0;       for (long long j = 0, _n = (m); j < _n; j++) x = r[x], printf( %d  , v[x]);       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int a, b, c, d, i, j, n, m, k, ans;   char mas2[2001][2001];   bitset<2000> mas[2001], ver[2001];   int si[2001];   int main() {     gets(mas2[0]);     sscanf(mas2[0],  %d , &n);     for (int _n((n)-1), i(0); i <= _n; i++) gets(mas2[i]);     for (int _n((n)-1), i(0); i <= _n; i++)       for (int _n(n - 1), j(i); j <= _n; j++)         if (mas2[i][j] ==  1 ) {           mas[i].set(j);         }     for (int _n((n)-1), i(0); i <= _n; i++) {       for (int j = n - 1; j > i; --j) {         if (mas[i].test(j) ^ ver[j].test(i)) {           ++ans;           si[i] ^= 1;           si[j] ^= 1;           mas[i].flip();           ver[j].flip();         }       }     }     for (int _n((n)-1), i(0); i <= _n; i++) mas[i].reset(), ver[i].reset();     for (int _n((n)-1), i(0); i <= _n; i++)       for (int _n(n - 1), j(i); j <= _n; j++)         if (mas2[j][i] ==  1 ) {           mas[i].set(j);         }     for (int _n((n)-1), i(0); i <= _n; i++) {       for (int j = n - 1; j > i; --j) {         if (mas[i].test(j) ^ ver[j].test(i)) {           ++ans;           si[i] ^= 1;           si[j] ^= 1;           mas[i].flip();           ver[j].flip();         }       }       if (si[i]) mas2[i][i] ^= 1;       if (mas2[i][i] ==  1 ) {         ++ans;         mas[i].flip(i);       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   const int N = 200200;   using namespace std;   int n, k, s, t;   int c[N];   int v[N];   vector<int> g;   bool f(int x) {     long long cnt = s + s;     for (int i = 0; i + 1 < g.size(); i++) {       if (g[i + 1] - g[i] > x) return false;       int l = x - (g[i + 1] - g[i]);       cnt -= min(g[i + 1] - g[i], l);     }     return cnt <= t;   }   int main() {     ios_base::sync_with_stdio(0);     scanf( %d%d%d%d , &n, &k, &s, &t);     for (int i = 1; i <= n; i++) scanf( %d%d , &c[i], &v[i]);     g.push_back(0);     g.push_back(s);     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       g.push_back(x);     }     sort(g.begin(), g.end());     int l = 0, r = 1e9 + 1;     while (l < r) {       int m = (l + r) / 2;       if (f(m))         r = m;       else         l = m + 1;     }     int ans = 1e9 + 1;     for (int i = 1; i <= n; i++)       if (v[i] >= l) ans = min(ans, c[i]);     if (ans == 1e9 + 1) ans = -1;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, t, k, ret;   int a[N];   int sum[N];   int main() {     scanf( %d%d%d , &n, &t, &k);     int all = 0;     sum[0] = 1;     a[0] = 1;     for (int i = 1; i <= t; i++) {       scanf( %d , &a[i]);       sum[i] = sum[i - 1] + a[i];       if (a[i] < a[i - 1]) ret += a[i - 1] - a[i];     }     if (ret + a[t] > k || n - t < k) {       printf( -1 n );       return 0;     }     printf( %d n , n);     int fa = 1, now = 2;     int need = n - t - k;     for (int i = 1; i <= t; i++) {       while (now <= sum[i]) {         printf( %d %d n , fa, now);         if (fa != sum[i - 1] && now != sum[i] && need > 0) {           fa++;           need--;         }         now++;       }       fa = sum[i - 1] + 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, m, r0;     cin >> a >> b >> m >> r0;     int step = 0;     map<int, int> smap;     smap[r0] = 0;     while (true) {       r0 = r0 * a + b;       r0 %= m;       step++;       if (smap.find(r0) != smap.end()) {         cout << step - smap[r0];         break;       }       smap[r0] = step;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int maxn = 100000 + 10;   struct Point {     double x, y;     Point() {}     Point(double x, double y) : x(x), y(y) {}   } inter;   struct Line {     int a, b, c, id;     Line() {}     Line(int a, int b, int c, int id) : a(a), b(b), c(c), id(id) {}   } e[maxn];   struct Node {     int x, y;     Node() {}     Node(int x, int y) : x(x), y(y) {}   } ans[10];   int n, k, cnt, tot, pos;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline int dcmp(double x) {     if (fabs(x) < eps) return 0;     return x < 0 ? -1 : 1;   }   bool judge(int l, int r) {     if (dcmp((double)e[l].a * e[r].b - (double)e[r].a * e[l].b) == 0) return 0;     inter = Point(((double)e[l].b * e[r].c - (double)e[l].c * e[r].b) /                       ((double)e[l].a * e[r].b - (double)e[r].a * e[l].b),                   ((double)e[l].a * e[r].c - (double)e[l].c * e[r].a) /                       ((double)e[l].b * e[r].a - (double)e[l].a * e[r].b));     return 1;   }   int main() {     n = read(), k = read();     for (int i = 1, a, b, c; i <= n; i++) {       a = read(), b = read(), c = read();       e[i] = Line(a, b, c, i);     }     cnt = n;     bool exis = 1;     while (cnt) {       if (k >= cnt) {         ans[++tot] = Node(e[cnt].id, -1);         cnt--;         continue;       }       for (pos = 1; pos <= 100; pos++) {         int a = rand() % cnt + 1, b = rand() % cnt + 1, sz = 0;         if (!judge(a, b)) continue;         for (int i = 1; i <= cnt; i++)           if (dcmp((double)e[i].a * inter.x + (double)e[i].b * inter.y +                    e[i].c) == 0)             sz++;         if (sz * k >= cnt) {           ans[++tot] = Node(e[a].id, e[b].id);           break;         }       }       if (pos > 100) {         exis = 0;         break;       }       for (int i = cnt; i >= 1; i--)         if (dcmp((double)e[i].a * inter.x + (double)e[i].b * inter.y +                  (double)e[i].c) == 0) {           swap(e[i], e[cnt]);           cnt--;         }       k--;     }     if (!exis)       puts( NO );     else {       puts( YES );       printf( %d n , tot);       for (int i = 1; i <= tot; i++) printf( %d %d n , ans[i].x, ans[i].y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265389793238462643383279502884197169;   const long long MOD = 1e9 + 7;   const int MAXN = 1e6 + 5;   const int oo = 1e9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t, p;     cin >> t;     while (t--) {       cin >> p;       cout << 2 <<     << p - 1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 2 * acos(0.0);   long long infinity = std::numeric_limits<long long>::max();   long long binary_search(long long dp[], long long n, long long p) {     long long l, r, mid;     l = 0;     r = n - 1;     sort(dp, dp + n);     while (l <= r && l >= 0 && l <= n - 1 && r >= 0 && r <= n - 1) {       mid = (l + r) / 2;       if (dp[mid] >= p) {         r = mid - 1;       } else {         l = mid + 1;       }     }     return l;   }   struct order {     long long l, r;   };   bool compare(order o1, order o2) {     if (o1.l == o2.l)       return (o1.r < o2.r);     else       return (o1.l < o2.l);   }   bool check(order o1, order o2) { return (o1.r < o2.l); }   int main() {     long long t;     cin >> t;     while (t--) {       long long r, c, k, num_R = 0, i, j;       cin >> r >> c >> k;       char A[r][c];       for (i = 0; i < r; ++i)         for (j = 0; j < c; ++j) {           cin >> A[i][j];           num_R += (A[i][j] ==  R );         }       long long x = ceil((double)num_R / (double)k), a, b, c1 = 0, x_count = 0,                 y_count = 0;       char req = 48;       b = x * k - num_R;       a = k - b;       long long a1 = a, b1 = b, l = 0, f = 0;       for (i = 0; i < r; ++i) {         if (i % 2 == 0)           j = 0;         else           j = c - 1;         while ((i % 2 == 0 && j < c) || (i % 2 == 1 && j >= 0)) {           if (A[i][j] !=  R )             A[i][j] = req;           else {             A[i][j] = req;             ++c1;             if (c1 == x * a) {               c1 = 0;               x = x - 1;               a = b;               if (l == 1 || a == 0) {                 f = 1;                 break;               }               if (a != 0) ++req;               ++l;             } else if (c1 % x == 0) {               ++req;             }           }           if (i % 2 == 0)             ++j;           else             --j;           if (req == 58)             req = 65;           else if (req == 91)             req = 97;         }         if (f == 1) {           break;         }       }       for (i = 0; i < r; ++i) {         for (j = 0; j < c; ++j) {           if (A[i][j] !=  . )             cout << A[i][j];           else             cout << req;         }         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double x, y, a, b, t;     while (cin >> a >> b) {       int n;       cin >> n;       double p = 1e18;       for (int i = 0; i < n; i++) {         cin >> x >> y >> t;         p = min(p, hypot((x - a), (y - b)) / t);       }       printf( %.20lf , p);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a, b[100100], p[100100];   bool check(int num) {     long long gongfei = 0LL;     for (int i = n - num + 1; i <= n; i++) {       int j = i - (n - num);       if (b[i] < p[j]) {         gongfei += p[j] - b[i];       }     }     if (gongfei > a) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> a;     for (int i = 1; i <= n; i++) {       cin >> b[i];     }     for (int i = 1; i <= m; i++) {       cin >> p[i];     }     sort(b + 1, b + n + 1);     sort(p + 1, p + m + 1);     int le = -1, ri = min(n, m) + 1;     int res = 0;     while (le + 1 < ri) {       int mi = (le + ri) / 2;       if (check(mi)) {         le = mi;       } else {         ri = mi;       }     }     long long tot = 0;     for (int i = 1; i <= le; i++) tot += p[i];     cout << le <<     << max(tot - a, 0LL) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, P = 1e9 + 7;   int qpow(int a, int n) {     int ans = 1;     for (; n; a = a * (int64_t)a % P, n >>= 1)       if (n & 1) ans = ans * (int64_t)a % P;     return ans;   }   int fac[N], ifac[N], f[N];   int C(int n, int m) {     if (m > n) return 0;     return fac[n] * (int64_t)ifac[m] % P * ifac[n - m] % P;   }   int main() {     fac[0] = 1;     for (int i = 1; i < N; ++i) fac[i] = fac[i - 1] * (int64_t)i % P;     ifac[N - 1] = qpow(fac[N - 1], P - 2);     for (int i = N - 2; i >= 0; --i) ifac[i] = ifac[i + 1] * (i + 1ll) % P;     int n, m, k;     cin >> n >> m >> k;     if (m == 1) return cout << qpow(k, n) << endl, 0;     for (int i = 1; i <= min(n, k); ++i) {       for (int j = i; j >= 0; --j) {         int ret = (int64_t)C(i, j) * qpow(j, n) % P;         if (j % 2 == i % 2)           f[i] = (f[i] + ret) % P;         else           f[i] = (f[i] - ret) % P;       }     }     int ans = 0;     if (m == 2) {       for (int i = 1; i <= n; ++i) {         ans = (ans + C(k, i) * (int64_t)C(k, i) % P * f[i] % P * f[i]) % P;       }     } else {       for (int i = 1; i <= min(n, k); ++i) {         for (int j = 1; j <= i; ++j) {           ans = (ans + C(k, i) * (int64_t)C(i, j) % P * C(k - i, i - j) % P *                            f[i] % P * f[i] % P * qpow(j, n * (m - 2))) %                 P;         }       }     }     if (ans < 0) ans += P;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n, m, x, y;       cin >> n >> m >> x >> y;       string s[n];       for (int a = 0; a < n; a++) cin >> s[a];       if (y > (2 * x)) y = 2 * x;       long long int xx, yy, zz, ans = 0;       for (int a = 0; a < n; a++) {         for (int b = 0; b < m; b++) {           if (s[a][b] ==  . ) {             if (b == m - 1)               ans += x;             else if (s[a][b + 1] ==  . ) {               ans += y;               b++;             } else               ans += x;           }         }       }       cout << ans <<   n ;     }     return 0;   }