malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int deg[25];   double g[25][25];   double p[510][510];   int main() {     int n, m, a, b;     scanf( %d%d%d%d , &n, &m, &a, &b);     a--;     b--;     int s = n * n;     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       x--;       y--;       deg[x]++;       deg[y]++;       g[x][y] = g[y][x] = 1;     }     for (int i = 0; i < n; i++) {       scanf( %lf , &g[i][i]);       for (int j = 0; j < n; j++) {         if (i != j) {           g[i][j] *= (1 - g[i][i]) / (double)deg[i];         }       }     }     for (int i = 0; i < s; i++) {       x = i / n;       y = i % n;       p[i][i] = -1;       if (x != y) {         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) {             p[j * n + k][i] += g[x][j] * g[y][k];           }         }       }     }     p[n * a + b][s] = -1;     double tmp;     for (int i = 0; i < s; i++) {       if (fabs(p[i][i]) < 1e-10)         for (int j = i + 1; j < s; j++)           if (fabs(p[j][i]) > 1e-10)             for (int k = i; k < s + 1; k++) std::swap(p[i][k], p[j][k]);       tmp = p[i][i];       for (int k = i; k < s + 1; k++) p[i][k] /= tmp;       for (int j = 0; j < s; j++)         if (i != j && fabs(tmp = p[j][i]) > 1e-10)           for (int k = i; k < s + 1; k++) p[j][k] -= tmp * p[i][k];     }     for (int i = 0; i < n; i++) {       printf( %.9lf  , p[n * i + i][s]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = std::numeric_limits<int>::max();   struct Cmp {     Cmp(const vector<deque<int>>& cont) : cont_(&cont) {}     bool operator()(int i, int j) const {       do {         if (!(!cont_->at(i).empty())) {           std::cerr <<  empty deque  << std::endl;           assert(false);         }       } while (false);       do {         if (!(!cont_->at(j).empty())) {           std::cerr <<  empty deque  << std::endl;           assert(false);         }       } while (false);       return cont_->at(i).front() < cont_->at(j).front() ||              (cont_->at(i).front() == cont_->at(j).front() && i > j);     }     const vector<deque<int>>* cont_;   };   void solve() {     int n;     cin >> n;     vector<deque<int>> a(n);     int numTasks = 0;     for (int i = 0; i < int(n); ++i) {       int k;       cin >> k;       numTasks += k;       {         int x;         cin >> x;         a[i].push_back(x);       }       long long x, y, m;       cin >> x >> y >> m;       for (int j = 0; j < int(k - 1); ++j) {         a[i].push_back((a[i].back() * x + y) % m);       }     }     a.push_back(deque<int>());     a.back().push_back(-1);     Cmp cmp(a);     std::set<int, Cmp> q(cmp);     for (int i = 0; i < int(n); ++i) q.insert(i);     int numDecs = 0;     bool print = numTasks <= 200 * 1000;     vector<pair<int, int>> output;     while (!q.empty()) {       auto it = q.lower_bound(n);       if (it == q.end()) {         it = q.begin();       }       q.erase(it);       int i = *it;       do {         if (!(!a[i].empty())) {           std::cerr <<  empty deque  << std::endl;           assert(false);         }       } while (false);       if (a[i].front() < a.back().back()) {         ++numDecs;       }       a.back().back() = a[i].front();       if (print) {         output.push_back(make_pair(a[i].front(), i + 1));       }       a[i].pop_front();       if (!a[i].empty()) {         q.insert(i);       }     }     cout << numDecs << endl;     for (int i = 0; i < int(output.size()); ++i) {       cout << output[i].first <<     << output[i].second << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[100005];   int tmp[100005];   int sl = 0;   int dp[100005];   int zs = 0;   int sz[1200005];   int dd[100005];   int cl[100005];   vector<int> g[100005];   int sol() {     zs = 0;     for (int i = 1; i <= sl; ++i) {       int u = tmp[i];       for (auto &v : g[u]) {         cl[v]++;         if (cl[v] == 1) sz[++zs] = v;       }     }     sort(sz + 1, sz + zs + 1);     int cnt = 0;     for (int i = zs; i >= 1; --i) {       dd[sz[i]] =           (dd[sz[i]] + (1ll * cl[sz[i]] * cl[sz[i]]) % 1000000007) % 1000000007;       cnt = 0;       for (auto &v : g[sz[i]])         if (v != sz[i]) dd[v] = (dd[v] - dd[sz[i]] + 1000000007) % 1000000007;     }     int res = 0;     for (int i = 1; i <= zs; ++i) {       res = (res + (1ll * dd[sz[i]] * sz[i]) % 1000000007) % 1000000007;       dd[sz[i]] = 0;       cl[sz[i]] = 0;     }     return res;   }   int main() {     ios ::sync_with_stdio(false);     cin >> n;     int ans = 0;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= 100000; ++i)       for (int j = 1; j * j <= i; ++j)         if (i % j == 0) {           g[i].push_back(j);           if (j * j != i) g[i].push_back(i / j);         }     for (int i = 1; i <= n; ++i) {       sl = 0;       for (int j = 1; i * j <= n; ++j) tmp[++sl] = a[i * j];       dp[i] = sol();     }     for (int i = n; i >= 1; --i)       for (int j = 2; i * j <= n; ++j)         dp[i] = (dp[i] - dp[i * j] + 1000000007) % 1000000007;     for (int i = 1; i <= n; ++i)       ans = (ans + (1ll * i * dp[i]) % 1000000007) % 1000000007;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   long long cnt[N];   int main() {     long long n, k;     cin >> n >> k;     long long sum = 0, right = 0, left = 0;     for (int i = 0; i < n; i++) {       cin >> cnt[i];       sum += cnt[i];       right = max(right, cnt[i]);     }     if (sum == k) {       return 0;     } else if (sum < k) {       puts( -1 );       return 0;     }     while (left < right) {       sum = 0;       long long mid = (left + right) / 2;       for (int i = 0; i < n; i++) {         sum += min(cnt[i], mid);       }       if (sum < k)         left = mid + 1;       else if (sum > k)         right = mid - 1;       else {         left = right = mid;         break;       }     }     sum = 0;     for (int i = 0; i < n; i++) sum += min(cnt[i], left);     if (sum > k) left--;     sum = 0;     for (int i = 0; i < n; i++) {       sum += min(left, cnt[i]);       cnt[i] -= min(left, cnt[i]);     }     sum = k - sum;     int ind = 0;     vector<int> tmp, res;     for (ind = 0; ind < n && sum > 0; ind++) {       if (cnt[ind] > 0) {         cnt[ind]--;         sum--;         if (cnt[ind] > 0) tmp.push_back(ind + 1);       }     }     for (; ind < n; ind++)       if (cnt[ind] > 0) res.push_back(ind + 1);     for (int i = 0; i < (int)tmp.size(); i++) res.push_back(tmp[i]);     int len = (int)res.size();     for (int i = 0; i < len; i++) {       printf( %d%c , res[i], i == len - 1 ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a, b, w, x;   int main() {     while (scanf( %d , &n) != EOF) {       cin >> a >> b;       for (int i = 1; i <= n; i++) {         scanf( %I64d , &w);         x = w * a / b;         x = x * b;         printf( %I64d%c , (w * a - x) / a,    n [i == n]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const* argv[]) {     string a, inp, min;     int n, i, l;     cin >> a >> n;     l = a.size();     min =   ;     while (n--) {       cin >> inp;       for (i = 0; i < l; i++)         if (inp[i] != a[i]) break;       if (i == l && (inp < min || min ==   )) min = inp;     }     if (min ==   )       cout << a << endl;     else       cout << min << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char rd;   int sig;   template <class T>   inline void read(T &a) {     for (a = 0, rd = getchar(); ( 0  > rd || rd >  9 ) && rd !=  - ;          rd = getchar())       ;     for (rd ==  -  ? sig = -1, rd = getchar() : sig = 1;  0  <= rd && rd <=  9 ;)       a *= 10, a += rd -  0 , rd = getchar();     a *= sig;   }   int n, k, l[100005], r[100005];   int main() {     read(n);     read(k);     int tot = 0;     for (int i = (1); i <= (n); ++i)       read(l[i]), read(r[i]), tot += r[i] - l[i] + 1;     int ans = (k - tot % k) % k;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<string, int> mp;     vector<string> vec;     string s;     int n, m, v;     double k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> s >> v;       if (v >= 100) {         mp[s] = k * v + 1e-9;         if (mp[s] >= 100)           vec.push_back(s);         else           mp[s] = 0;       }     }     for (int i = 0; i < m; i++) {       cin >> s;       if (!mp[s]) vec.push_back(s);     }     sort(vec.begin(), vec.end());     cout << vec.size() <<   n ;     for (int i = 0; i < vec.size(); i++) {       cout << vec[i] <<     << mp[vec[i]] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     bool p = 0;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) p = 1;     for (; c >=  0  && c <=  9 ; c = getchar())       x = (x << 3) + (x << 1) + (c ^ 48);     if (p) x = -x;   }   const int N = 1005, M = 10005;   const long long INF = 1000000000000000000;   struct node {     int id;     long long val;     node() {}     node(int _id, long long _val) {       id = _id;       val = _val;     }     bool operator<(node x) const { return val > x.val; }   };   int n, m, s, t;   long long L;   int head[N], pnt[M << 1], nxt[M << 1], E = 0;   int mark[M << 1], fm[M << 1], to[M << 1];   long long weight[M << 1];   void add_edge(int a, int b, long long c) {     pnt[E] = b;     nxt[E] = head[a];     weight[E] = c;     head[a] = E++;   }   priority_queue<node> q;   long long dist[N][2];   long long diff = 0;   void dijkstra(int s, int opt) {     for (int i = 1; i <= n; ++i) dist[i][opt] = INF;     dist[s][opt] = 0;     while (!q.empty()) q.pop();     q.push(node(s, 0));     while (!q.empty()) {       node now = q.top();       q.pop();       int u = now.id;       if (dist[u][opt] != now.val) continue;       for (int i = head[u], v; i != -1; i = nxt[i]) {         v = pnt[i];         if (opt) {           if (mark[i] && dist[u][1] + weight[i] < dist[v][0] + diff) {             weight[i] = weight[i ^ 1] = dist[v][0] + diff - dist[u][1];           }         }         if (dist[v][opt] > dist[u][opt] + weight[i]) {           dist[v][opt] = dist[u][opt] + weight[i];           q.push(node(v, dist[v][opt]));         }       }     }   }   int main() {     memset(head, -1, sizeof(head));     read(n);     read(m);     read(L);     read(s);     read(t);     ++s;     ++t;     for (int i = 1; i <= m; ++i) {       int u, v;       long long w;       read(u);       read(v);       read(w);       fm[E] = u;       fm[E + 1] = v;       to[E] = v;       to[E + 1] = u;       ++u;       ++v;       if (!w) {         mark[E] = mark[E + 1] = 1;         w = 1;       }       add_edge(u, v, w);       add_edge(v, u, w);     }     dijkstra(s, 0);     if (dist[t][0] > L) {       printf( NO n );       return 0;     }     diff = L - dist[t][0];     dijkstra(s, 1);     if (dist[t][1] != L) {       printf( NO n );       return 0;     }     printf( YES n );     for (int i = 0; i < E; i += 2) {       printf( %d %d %lld n , fm[i], to[i], weight[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[1100][1100];   bool a[1100][1010];   bool canDraw(int x, int y, int level) {     int i = level;     {       if (x + i < 0 || x + i >= n) return false;       if (y + i < 0 || y + i >= m) return false;       if (s[x + i][y] ==  . ) return false;       if (s[x][y + i] ==  . ) return false;     }     i = -level;     {       if (x + i < 0 || x + i >= n) return false;       if (y + i < 0 || y + i >= m) return false;       if (s[x + i][y] ==  . ) return false;       if (s[x][y + i] ==  . ) return false;     }     return true;   }   void Draw(int x, int y, int level) {     for (int i = -level; i <= level; i++) {       a[x][y + i] = true;       a[x + i][y] = true;     }   }   int ans;   int xx[11000000];   int yy[11000000];   int ll[10100000];   int main(int argc, char const *argv[]) {     while (cin >> n >> m) {       ans = 0;       for (int i = 0; i < n; i++) {         scanf( %s , s[i]);       }       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           int level = 0;           for (level = 0; level <= max(n, m); level++) {             if (!canDraw(i, j, level)) break;           }           if (level > 1) {             Draw(i, j, level - 1);             xx[ans] = i;             yy[ans] = j;             ll[ans] = level - 1;             ans++;           }         }       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           if (s[i][j] ==  *  && a[i][j] == false) {             ans = -1;           }         }       if (ans == -1) {         printf( -1 n );       } else {         printf( %d n , ans);         for (int i = 0; i < ans; i++)           printf( %d %d %d n , xx[i] + 1, yy[i] + 1, ll[i]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 60 + 7;   const int INF = (int)1e9;   int n;   int m;   int q;   int dp[N][N][N];   int one[N][N][N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int k = 0; k < N; k++) dp[i][j][k] = one[i][j][k] = INF;     cin >> n >> m >> q;     for (int it = 1; it <= m; it++) {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) cin >> one[it][i][j];       for (int k = 1; k <= n; k++)         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++)             one[it][i][j] = min(one[it][i][j], one[it][i][k] + one[it][k][j]);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int it = 1; it <= m; it++)           dp[i][j][0] = min(dp[i][j][0], one[it][i][j]);     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           for (int x = 1; x <= n; x++)             dp[i][j][k] = min(dp[i][j][k], dp[i][x][k - 1] + dp[x][j][0]);     while (q--) {       int a, b, k;       cin >> a >> b >> k;       k = min(k, n);       cout << dp[a][b][k] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[110];   int dp[110][110];   map<int, int> mp;   bool cmp(int p, int q) { return p > q; }   int main() {     int n, m;     while (scanf( %d%d , &n, &m) == 2) {       memset(a, 0, sizeof(a));       memset(dp, 0, sizeof(dp));       int u;       int b = -1;       for (int i = 1; i <= m; i++) {         cin >> u;         a[u]++;         b = max(b, u);       }       sort(a + 1, a + 110, cmp);       int ans = 0, l = 0;       for (int i = 0; i <= b; i++) {         if (a[i]) l++;       }       for (int i = 1; i <= n; i++) {         dp[1][i] = a[1] / i;       }       for (int i = 1; i <= l; i++) {         dp[i][1] = a[1];       }       for (int i = 2; i <= l; i++) {         for (int j = 1; j <= n; j++) {           for (int k = 0; k < j; k++) {             dp[i][j] = max(dp[i][j], min(dp[i - 1][k], a[i] / (j - k)));           }         }       }       int Max = 0;       for (int i = 1; i <= l; i++) {         Max = max(dp[i][n], Max);       }       cout << Max << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int maxn = 1010;   int n, K, mxa;   int a[maxn];   inline int MOD(int x) { return x < mod ? x : x - mod; }   inline int Mod(int x) { return x < 0 ? x + mod : x; }   void input() {     int i;     scanf( %d%d , &n, &K);     for (i = 1; i <= n; i++) scanf( %d , a + i);     sort(a + 1, a + n + 1);     mxa = a[n] - a[1];   }   int f[maxn][maxn], g[maxn][maxn];   int calc(int Lim) {     int i, j, k;     for (i = 1; i <= K; i++) g[0][i] = 0;     for (i = 1; i <= n; i++) f[i][1] = 1, g[i][1] = g[i - 1][1] + 1;     for (k = 2; k <= K; k++) {       j = 0;       for (i = 1; i <= n; i++) {         for (; a[i] - a[j + 1] >= Lim; j++)           ;         f[i][k] = g[j][k - 1];         g[i][k] = MOD(g[i - 1][k] + f[i][k]);       }     }     return g[n][K];   }   void solve() {     int i, t, fans = 0;     for (i = 1;; i++) {       t = calc(i);       if (!t) break;       fans = MOD(fans + t);     }     printf( %d n , fans);   }   int main() {     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   const int mod = 1e9 + 7;   vector<int> e[MAXN];   int n, sz[MAXN], f[MAXN][MAXN][2], tmp[MAXN][2], c[MAXN][MAXN];   inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }   inline void inc(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }   void dfs(int u, int ff) {     sz[u] = 1;     f[u][0][1] = f[u][0][0] = 1;     for (int v, i = (int)e[u].size() - 1; ~i; --i)       if ((v = e[u][i]) != ff) {         dfs(v, u);         for (int j = 0; j < sz[u] + sz[v]; ++j) tmp[j][0] = tmp[j][1] = 0;         for (int j = 0; j < sz[u]; ++j)           for (int k = 0; k < sz[v]; ++k) {             inc(tmp[j + k + 1][0], 1ll * f[u][j][0] * f[v][k][0] % mod);             inc(tmp[j + k + 1][1],                 (1ll * f[u][j][0] * f[v][k][1] + 1ll * f[u][j][1] * f[v][k][0]) %                     mod);             inc(tmp[j + k][0], 1ll * f[u][j][0] * f[v][k][1] % mod);             inc(tmp[j + k][1], 1ll * f[u][j][1] * f[v][k][1] % mod);           }         sz[u] += sz[v];         for (int j = 0; j < sz[u]; ++j)           f[u][j][0] = tmp[j][0], f[u][j][1] = tmp[j][1];       }   }   inline int qpow(int a, int b) {     int re = 1;     b < 0 ? b += mod - 1 : 0;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) re = 1ll * re * a % mod;     return re;   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; ++i)       scanf( %d%d , &u, &v), e[u].push_back(v), e[v].push_back(u);     dfs(1, 0);     c[0][0] = 1;     for (int i = 1; i < n; ++i) {       c[i][0] = 1;       for (int j = 1; j <= i; ++j) c[i][j] = add(c[i - 1][j - 1], c[i - 1][j]);     }     for (int i = 0; i < n; ++i)       f[1][i][1] = 1ll * f[1][i][1] * qpow(n, n - i - 2) % mod;     for (int i = 0; i < n; ++i) {       int ans = 0, cf = 1;       for (int j = i; j < n; ++j)         inc(ans, 1ll * f[1][j][1] * cf % mod * c[j][i] % mod), cf = mod - cf;       printf( %d  , ans);     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const long double PI = 3.14159265358979323846;   const long double gammama = 0.57721566490153286060;   const long double eps = 1e-8;   const long long INF = 777777777777 + 1;   vector<int> a(10, 0);   int pow(int x, int st) {     int res = 1;     for (int i = 0; i < st; ++i) res *= x;     return res;   }   long long c(int n, int k) {     long long res = 1;     for (int i = 0; i < k; ++i) {       res *= n - i;       res /= i + 1;     }     return res;   }   void add(long long m, int shift) {     if (m < 1) return;     if (m == 1) {       ++a[shift];       return;     }     if (m <= 10) {       for (int i = 0; i < m; ++i) {         if ((i == 4) || (i == 7))           ++a[shift + 1];         else           ++a[shift];       }       return;     }     long long d = 1;     int s = 0;     while (d * 10 <= m) {       d *= 10;       ++s;     }     if (m == d) {       a[shift] += pow(8, s);       for (int i = 1; i <= s; ++i) {         a[shift + i] += c(s, i) * pow(2, i) * pow(8, s - i);       }       return;     }     int x = m / d;     for (int i = 0; i < x; ++i) {       if ((i == 4) || (i == 7))         add(d, shift + 1);       else         add(d, shift);     }     if ((x == 4) || (x == 7)) ++shift;     add(m - d * x, shift);   }   const long long inv[] = {0,        1,         500000004, 166666668,                            41666667, 808333339, 301388891};   long long mod = 1000 * 1000 * 1000 + 7;   long long cm(long long n, int k) {     long long res = 1;     for (int i = 0; i < k; ++i) {       res = (res * (n - i)) % mod;     }     res = (res * inv[k]) % mod;     return res;   }   long long get(int s, int k) {     if (k == 0) return 1;     long long res = 0;     for (int i = 0; i < s; ++i) {       --a[i];       if (a[i] >= 0)         res = (res + (long long)(a[i] + 1) * get(s - i, k - 1)) % mod;       ++a[i];     }     return res;   }   int main() {     long long m;     cin >> m;     add(m + 1, 0);     --a[0];     long long res = 0;     for (int s = 1; s <= 9; ++s) {       long long cur = ((long long)(a[s]) * get(s, 6)) % mod;       res = (res + cur) % mod;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       int n, l;       cin >> n >> l;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int il = 0, ir = n - 1, sl = 1, sr = 1;       double time = 0, pl = 0, pr = l;       while (il <= ir) {         double tl = (a[il] - pl) / sl, tr = (pr - a[ir]) / sr;         if (tl < tr) {           pl = a[il];           pr -= sr * tl;           il++;           sl++;           time += tl;         } else {           pr = a[ir];           pl += sl * tr;           ir--;           sr++;           time += tr;         }       }       cout << fixed << setprecision(15) << time + (pr - pl) / (sr + sl) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #include<string>   #include<vector>    using namespace std;      //#include <ext/pb_ds/assoc_container.hpp>    //#include <ext/pb_ds/tree_policy.hpp>   //using namespace __gnu_pbds;   //typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> o_set;      typedef long double ld;   typedef long long int ll;   #define int long long   typedef vector<int> vi;   typedef pair<int, int> ii;   typedef vector<ii> vii;   typedef vector<vi> vvi;   typedef vector<vii> vvii;      #define FAST   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   #define INF 1e18   #define MOD 1000000007   #define pb push_back   #define mp make_pair   #define fi first   #define se second    #define loop(i,n) for(ll i=0;i<n;i++)   #define leep(i,n) for(ll i=1;i<=n;i++)   #define all(v) v.begin(), v.end()   #define remove_dulpicate(d)    d.resize(unique(all(d))-d.begin())      ll power(ll a,ll b){      if(b==0) return 1LL;      ll p=power(a,b/2);      p=p*p%MOD;      return (b&1)?p*a%MOD:p;   }      int32_t main() {         FAST      int tt;      cin>>tt;      while(tt--)      {         int n,m,cnt=0;         cin>>n>>m;                  char mat[n][m];                  for(int i=0;i<n;i++){            string s;            cin>>s;            cnt+=count(all(s), # );          }                  int ans=power(2,cnt);                  if(cnt==n*m){            ans=(ans-1+MOD)%MOD;         }         cout<<ans<<  n ;      }      //check constraints        return 0;   }