malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5;   long long a[N];   int32_t tree[N << 2], bit_cnt[N];   struct seg_tree {     long long combine(long long x, long long y) { return max(x, y); }     void build(long long l, long long r, long long node) {       if (l == r) {         tree[node] = bit_cnt[l];         return;       }       long long mid = (l + r) >> 1, lc = node + node, rc = 1 + lc;       build(l, mid, lc);       build(mid + 1, r, rc);       tree[node] = combine(tree[lc], tree[rc]);     }     long long query(long long l, long long r, long long ql, long long qr,                     long long node) {       if (qr < l || r < ql) return 0;       if (ql <= l and r <= qr) {         return tree[node];       }       long long mid = (l + r) >> 1, lc = node + node, rc = 1 + lc;       return combine(query(l, mid, ql, qr, lc), query(mid + 1, r, ql, qr, rc));     }   };   long long dp[N][2];   long long prefix_sum[N];   void solve() {     long long n;     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       bit_cnt[i] = __builtin_popcountll(a[i]);     }     seg_tree ins;     ins.build(1, n, 1);     for (long long i = 1; i <= n; ++i) {       prefix_sum[i] = bit_cnt[i] + prefix_sum[i - 1];     }     dp[0][0] = 1;     map<long long, long long> mp;     mp[0] = 1;     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       long long c = prefix_sum[i] & 1LL;       dp[i][0] = dp[i - 1][0];       dp[i][1] = dp[i - 1][1];       dp[i][c] += 1;       ans += dp[i - 1][c];       long long res = -1, mx = bit_cnt[i];       long long sum = 0;       for (long long j = i; i - j <= 62 && j > 0; --j) {         mx = max(mx, (long long)bit_cnt[j]);         sum += bit_cnt[j];         if ((sum - mx < mx) && (sum & 1) == 0) {           --ans;         }       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long i = 1; i <= t; ++i) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;      int main() {   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif       ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    cout.precision(10);    int t;    cin >> t;    while (t--) {     int n;     cin >> n;     string s;     cin >> s;     int l[n + 1], r[n + 1];     l[0] = 1;     for (int i = 1; i <= n; i++) {      l[i] = 1;      if (i == 1) {       if (s[i - 1] ==  L ) {        l[i] = 2;       }      } else {       if (s[i - 1] ==  L ) {        l[i] = 2;        if (s[i - 2] ==  R ) {         l[i] = 2 + l[i - 2];        }       }      }     }     r[n] = 1;     for (int i = n - 1; i >= 0; i--) {      r[i] = 1;      if (i == n - 1) {       if (s[i] ==  R ) {        r[i] = 2;       }      } else {       if (s[i] ==  R ) {        r[i] = 2;        if (s[i + 1] ==  L ) {         r[i] = 2 + r[i + 2];        }       }      }     }     for (int i = 0; i <= n; i++) {      cout << l[i] + r[i] - 1 <<    ;     }     cout << endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100002;   int n, m, k, currentOutCost[N], cntOut, cntIn;   struct flight {     int i, d, c;   } in[N], out[N];   multiset<int> a[N];   bool cmp(flight x, flight y) { return x.d < y.d; }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = (1); i <= (int)(m); ++i) {       int d, first, t, c;       scanf( %d%d , &d, &first);       scanf( %d%d , &t, &c);       if (first)         out[++cntOut] = {first, d, c};       else         in[++cntIn] = {t, d, c};     }     sort(out + 1, out + 1 + cntOut, cmp);     sort(in + 1, in + 1 + cntIn, cmp);     long long ans = 1000000000000000000ll, currOut = 0, currInSum = 0,               currOutSum = 0, j = 1;     for (int i = (1); i <= (int)(cntIn); ++i) a[in[i].i].insert(in[i].c);     for (int i = (1); i <= (int)(n); ++i)       if (((int)(a[i]).size()))         currInSum += *a[i].begin();       else         return cout << -1, 0;     for (int i = (1); i <= (int)(cntOut); ++i) {       int node = out[i].i, d = out[i].d, c = out[i].c;       while (j <= cntIn and in[j].d <= d + k) {         currInSum -= *a[in[j].i].begin();         a[in[j].i].erase(a[in[j].i].find(in[j].c));         if (!((int)(a[in[j].i]).size())) goto fn;         currInSum += *a[in[j].i].begin();         ++j;       }       if (!currentOutCost[node]) {         ++currOut;         currInSum += currentOutCost[node] = c;       } else {         currInSum -= currentOutCost[node];         currentOutCost[node] = min(currentOutCost[node], c);         currInSum += currentOutCost[node];       }       if (currOut == n) ans = min(ans, currOutSum + currInSum);     }   fn:     cout << (ans == 1000000000000000000ll ? -1 : ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, j, ans;     cin >> n >> k;     int arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     ans = 0;     for (i = n - 1; i >= 0; i = i - k) {       ans += 2 * (arr[i] - 1);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream& operator<<(ostream& out, const pair<A, B>& a) {     return out <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class A>   ostream& operator<<(ostream& out, const vector<A>& a) {     out <<  [ ;     for (auto it = a.begin(); it != a.end(); ++it) {       if (it != a.begin()) out <<  ,  ;       out << *it;     }     return out <<  ] ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, i, j, x, t, y, d, m;     cin >> d;     cin >> n >> m;     vector<pair<pair<long long, long long>, pair<long long, long long>>> a(d);     for (i = 0; i < d; i++)       cin >> a[i].first.first >> a[i].first.second >> a[i].second.first >>           a[i].second.second;     long long cnt_u, cnt_d, cnt_l, cnt_r;     cin >> cnt_u >> cnt_d >> cnt_l >> cnt_r;     vector<long long> vl(100005, 0), vr(100005, 0), vu(100005, 0), vd(100005, 0);     for (i = 0; i < d; i++) {       vu[min(a[i].first.first, a[i].second.first)]++;       vd[max(a[i].first.first, a[i].second.first)]++;       vl[min(a[i].first.second, a[i].second.second)]++;       vr[max(a[i].first.second, a[i].second.second)]++;     }     for (i = 1; i < 100005; i++) {       vu[i] += vu[i - 1];       vl[i] += vl[i - 1];     }     for (i = 100005 - 4; i >= 0; i--) {       vd[i] += vd[i + 1];       vr[i] += vr[i + 1];     }     for (i = 0; i < d; i++) {       vu[min(a[i].first.first, a[i].second.first)]--;       vd[max(a[i].first.first, a[i].second.first)]--;       vl[min(a[i].first.second, a[i].second.second)]--;       vr[max(a[i].first.second, a[i].second.second)]--;       long long x1, x2, y1, y2;       x1 = vu[max(a[i].first.first, a[i].second.first) - 1];       x2 = vd[min(a[i].first.first, a[i].second.first) + 1];       y1 = vl[max(a[i].first.second, a[i].second.second) - 1];       y2 = vr[min(a[i].first.second, a[i].second.second) + 1];       if (x1 == cnt_u && x2 == cnt_d && y1 == cnt_l && y2 == cnt_r) {         cout << i + 1;         return 0;       }       vu[min(a[i].first.first, a[i].second.first)]++;       vd[max(a[i].first.first, a[i].second.first)]++;       vl[min(a[i].first.second, a[i].second.second)]++;       vr[max(a[i].first.second, a[i].second.second)]++;     }     cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   struct hren {     long int pos, ob, tim;   };   hren down, up, lin, rech, u1, u2, u3, u4;   long long int c, q = 1, f = 1, g = 1;   long int n, j, i, timer = 0, x, y, p = 0;   void pere1(hren &q) {     if (timer == q.tim) {       q.pos = 1;       q.ob = 1;       return;     }     if (timer > q.tim) {       q.pos += 2;       q.ob += q.pos;       return;     }   }   void pere2(hren &q) {     if (timer == q.tim) {       q.pos = 1;       q.ob = 1;       return;     }     if (timer > q.tim) {       q.pos += 1;       q.ob += q.pos;       return;     }   }   void plusq(hren r) {     if (r.ob > 0) q += r.ob;     return;   }   void minusq(hren r) {     if (r.ob > 0) q -= r.ob;     return;   }   int main() {     scanf( %d%d%d%I64d , &n, &x, &y, &c);     down.tim = x;     up.tim = n - x + 1;     rech.tim = y;     lin.tim = n - y + 1;     u1.tim = n - y + x + 1;     u3.tim = n - x + y + 1;     u2.tim = x + y;     u4.tim = 2 * n + 2 - x - y;     while (1) {       if (g >= c) {         printf( %d , timer);         return 0;       }       timer++;       pere1(up);       pere1(down);       pere1(lin);       pere1(rech);       pere2(u1);       pere2(u2);       pere2(u3);       pere2(u4);       p += 4;       f += p;       q = 0;       plusq(up);       plusq(down);       plusq(lin);       plusq(rech);       minusq(u1);       minusq(u2);       minusq(u3);       minusq(u4);       g = f - q;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e6, mod = 998244353;   int arr[101];   int n;   bool rot(int idx, int deg) {     deg %= 360;     if (deg < 0) deg += 360;     if (idx == n) return !deg;     return rot(idx + 1, deg + arr[idx]) | rot(idx + 1, deg - arr[idx]);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , arr + i);     if (rot(0, 0))       puts( YES );     else       puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   int dp[45][45][45][45] = {0};   int sumar[45][45] = {0};   int ar[45][45] = {0};   int check(int i, int j, int p, int q) {     int s1 = sumar[p][q];     int s2 = sumar[i - 1][q];     int s3 = sumar[p][j - 1];     int s4 = sumar[i - 1][j - 1];     return ((s1 - s2 - s3 + s4) == 0);   }   int main() {     int m, q, n;     char ch;     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < n; i++) {       getchar();       for (int j = 0; j < m; j++) {         ch = getchar();         ar[i][j] = ch -  0 ;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         sumar[i][j] = sumar[i][j - 1] + sumar[i - 1][j] - sumar[i - 1][j - 1] +                       ar[i - 1][j - 1];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int p = i; p <= n; p++) {           for (int q = j; q <= m; q++) {             dp[i][j][p][q] = dp[i][j][p - 1][q] + dp[i][j][p][q - 1] -                              dp[i][j][p - 1][q - 1] + check(i, j, p, q);           }         }       }     }     for (int p = n; p >= 1; p--) {       for (int q = m; q >= 1; q--) {         for (int i = p; i >= 1; i--) {           for (int j = q; j >= 1; j--) {             dp[i][j][p][q] +=                 dp[i + 1][j][p][q] + dp[i][j + 1][p][q] - dp[i + 1][j + 1][p][q];           }         }       }     }     int a, b, c, d;     for (int i = 0; i < q; i++) {       scanf( %d %d %d %d , &a, &b, &c, &d);       cout << dp[a][b][c][d] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   char map[55][55];   int main() {     int n, ans = 2147483647;     std::pair<int, int> s, t;     std::queue<std::pair<int, int> > q;     std::vector<std::pair<int, int> > vec1, vec2;     scanf( %d %d %d %d %d , &n, &s.first, &s.second, &t.first, &t.second);     for (int i = 1; i <= n; ++i) scanf( %s , map[i] + 1);     vec1.push_back(s), map[s.first][s.second] =  2 , q.push(s);     while (!q.empty()) {       std::pair<int, int> p = q.front();       q.pop();       std::pair<int, int> temp = std::make_pair(p.first, p.second + 1);       if (temp.second <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);       temp = std::make_pair(p.first, p.second - 1);       if (temp.second >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);       temp = std::make_pair(p.first + 1, p.second);       if (temp.first <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);       temp = std::make_pair(p.first - 1, p.second);       if (temp.first >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);     }     if (map[t.first][t.second] ==  2 ) {       putchar( 0 );       return 0;     }     vec2.push_back(t), map[t.first][t.second] =  2 , q.push(t);     while (!q.empty()) {       std::pair<int, int> p = q.front();       q.pop();       std::pair<int, int> temp = std::make_pair(p.first, p.second + 1);       if (temp.second <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);       temp = std::make_pair(p.first, p.second - 1);       if (temp.second >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);       temp = std::make_pair(p.first + 1, p.second);       if (temp.first <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);       temp = std::make_pair(p.first - 1, p.second);       if (temp.first >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);     }     for (auto x1 : vec1)       for (auto x2 : vec2)         ans =             std::min(ans, (x2.first - x1.first) * (x2.first - x1.first) +                               (x2.second - x1.second) * (x2.second - x1.second));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, s;     int c(0);     cin >> a >> s;     sort(s.begin(), s.end()), reverse(s.begin(), s.end());     for (int i = 0; i < a.size(); i++) {       if (a[i] < s[c]) a[i] = s[c++];     }     cout << a << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     char b[101];     int k = 0;     for (int i = 0; i < a.length() - 1; ++i) {       if (a[i] != a[i + 1] || a[i] !=  / ) {         b[k] = a[i];         ++k;       }     }     if ((k == 0) || (a[a.length() - 1] !=  / )) {       b[k] = a[a.length() - 1];       ++k;     }     for (int i = 0; i < k; ++i) cout << b[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000006];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long score = 0;     for (int i = 0; i < n - 1; i++) score += 1ll * (i + 2) * a[i];     score += a[n - 1] * n;     cout << score << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef double db;   const int mod=1e9+7;   const int N=1e6+11;   const double eps=0.00000001;   bool check(int u,int v){    int a=0,b=0;        for(int i=0;i<31;i++){     if(u>>i&1) a++;        if(v>>i&1) b++;     if(b){           if(!a) return false;       a--,b--;         }    }    return true;   }   void solve(){    int q;    cin>>q;    while(q--){     int u,v;     cin>>u>>v;     if(u<=v&&check(u,v)) cout<< YES n ;       else cout<< NO n ;    }   }   int main(){    ios_base::sync_with_stdio(false);cin.tie(0);    solve();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y;     cin >> x >> y;     const auto n = int(x.size());     auto ok = true;     for (auto i = 0; i < n; i++) ok &= y[i] <= x[i];     if (ok)       cout << y << endl;     else       cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a, b, h, w, ans = INT_MAX, f[int(1e5 + 10)];   bool cmp(int x, int y) { return x > y; }   void get_answ(long long x, long long y, int d, bool flag) {     if (x >= a && y >= b) {       ans = min(ans, d - 1);       return;     }     if (d == n + 1) return;     if ((!flag || f[d] != f[d - 1]) && x < a)       get_answ(1ll * x * f[d], y, d + 1, 0);     if (y < b) get_answ(x, 1ll * y * f[d], d + 1, 1);   }   int main() {     scanf( %d%d%d%d%d , &a, &b, &h, &w, &n);     for (int i = 1; i <= n; i++) scanf( %d , f + i);     sort(f + 1, f + n + 1, cmp);     get_answ(h, w, 1, 0);     get_answ(w, h, 1, 0);     if (ans != INT_MAX)       printf( %d , ans);     else       printf( -1 );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int Tests = 1;     while (Tests--) {       long long int N;       cin >> N;       vector<long long int> A(N);       for (long long int i = 0; i < N; i++) cin >> A[i];       if (N == 1) cout << A[0] << endl;       if (N == 3) {         sort((A).begin(), (A).end());         cout << A[1] << endl;       }       if (N == 5) {         sort((A).begin(), (A).end());         cout << A[2] << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long md) {     if (p == 0) return 1;     if (p % 2 == 1) {       return ((b % md) * bigmod(b, p - 1, md)) % md;     } else {       long long y = bigmod(b, p / 2, md);       return (y * y) % md;     }   }   set<int> vis;   set<int> st[200005];   vector<int> ans;   int cnt;   void dfs(int s) {     cnt++;     for (auto it = vis.begin(); it != vis.end();) {       if (st[s].find(*it) == st[s].end()) {         int node = *it;         vis.erase(node);         dfs(node);         it = vis.lower_bound(node);       } else         it++;     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       st[a].insert(b);       st[b].insert(a);     }     for (int i = 1; i <= n; i++) vis.insert(i);     for (int i = 1; i <= n; i++) {       if (vis.find(i) != vis.end()) {         cnt = 0;         vis.erase(i);         dfs(i);         ans.push_back(cnt);       }     }     cout << ans.size() <<   n ;     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long jc[100005], fac[12], vp[12], P[12], s, v[100005][12], r[100005][12];   long long n, L, R, p;   long long fpower(long long x, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans = ans * x % p;       x = x * x % p;       k >>= 1;     }     if (!ans) return p;     return ans;   }   long long c(long long x, long long y) {     long long m[12] = {}, ans = 0;     for (long long i = 1; i <= s; ++i) {       long long o = v[x][i] - v[y][i] - v[x - y][i];       if (o >= vp[i]) continue;       long long q = fpower(fac[i], vp[i] - o);       m[i] =           fpower(fac[i], o) *           (r[x][i] *            fpower(r[y][i] * r[x - y][i] % q, q / fac[i] * (fac[i] - 1) - 1) % q) %           P[i];       ans += m[i] * fpower(p / P[i], P[i] / fac[i] * (fac[i] - 1)) % p;     }     return ans % p;   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &p, &L, &R);     jc[0] = 1;     for (long long i = 1; i <= n; ++i) jc[i] = jc[i - 1] * i % p;     long long t = p;     for (long long i = 2; i * i <= t; ++i) {       if (t % i) continue;       fac[++s] = i;       while (t % i == 0) vp[s]++, t /= i;       P[s] = fpower(fac[s], vp[s]);     }     if (t > 1) fac[++s] = t, vp[s] = 1, P[s] = t;     for (long long i = 1; i <= s; ++i) {       r[0][i] = 1;       for (long long j = 1; j <= n; ++j) {         long long t = j, sum = 0;         while (t % fac[i] == 0) t /= fac[i], sum++;         v[j][i] = v[j - 1][i] + sum, r[j][i] = r[j - 1][i] * t % P[i];       }     }     long long ans = 0;     for (long long i = 0; i <= n; ++i) {       long long o = 0;       if (i - L >= 0) o += c(i, (i - L) / 2);       if (i - R - 1 >= 0) o -= c(i, (i - R - 1) / 2);       ans = (ans + c(n, i) * o) % p;     }     printf( %I64d n , (p + ans % p) % p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long Inv[1000005];   void inv(int n) {     Inv[1] = 1;     for (int i = 2; i <= n; i++) {       Inv[i] = (mod - mod / i * Inv[mod % i] % mod) % mod;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     long long tot = 1;     for (int i = 1; i < n + 1; i++) {       tot *= i;       tot %= mod;     }     vector<int> v;     for (int i = 0; i < n; i++) {       int add;       cin >> add;       v.push_back(add);     }     inv(n);     sort(v.rbegin(), v.rend());     long long cur = 0;     long long ans = 0;     int last = 0;     int cnt = 0;     for (int i = 0; i < n; i++) {       if (v[i] == last) {         cur++;         cnt++;         continue;       }       if (last != v[0]) {         ans += tot * last % mod * Inv[cur] % mod * cnt % mod;         ans %= mod;       }       cur++;       cnt = 1;       last = v[i];     }     if (last != v[0]) {       ans += tot * last % mod * Inv[cur] % mod * cnt % mod;       ans %= mod;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int f[100][300] = {0};   int main() {     std::ios::sync_with_stdio(false);     string s1, s2;     cin >> s1 >> s2;     int t1 = 0, t2 = 0, q = 0;     for (int i = 0; i < s1.length(); i += 1) {       if (s1[i] ==  + )         t1++;       else         t1--;     }     for (int i = 0; i < s2.length(); i += 1) {       if (s2[i] ==  + )         t2++;       else if (s2[i] ==  - )         t2--;       else         q++;     }     int w = t1 - t2;     int dta = 20;     f[0][dta] = 1;     for (int i = 1; i <= q; i += 1) {       for (int j = -10; j <= 10; j += 1) {         f[i][j + dta] = f[i - 1][j + dta - 1] + f[i - 1][j + dta + 1];       }     }     double ans = f[q][w + dta] / double(1 << q);     cout << fixed << setprecision(12) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   const string dom[2][7] = {{ ......... ,  ....O.... ,  O.......O ,  O...O...O ,                               O.O...O.O ,  O.O.O.O.O ,  OOO...OOO },                             { ......... ,  ....O.... ,  ..O...O.. ,  ..O.O.O.. ,                               O.O...O.O ,  O.O.O.O.O ,  O.OO.OO.O }};   const int mod = 1000000007;   int n;   int m;   char w[1002][1002];   int g[250][250];   int can[250], can2[250];   int cnt[251], res[251];   int get(int i, int j) {     string s =   ;     for (int p = 0; p < 3; p++)       for (int q = 0; q < 3; q++) s += w[i + p][j + q];     int res = 0;     for (int p = 0; p < 2; p++)       for (int q = 0; q < 7; q++)         if (s == dom[p][q]) res |= (p + 1);     return res;   }   int main() {     scanf( %d%d , &n, &m);     gets(w[0]);     for (int i = 0; i < 4 * n + 1; i++) gets(w[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) g[i][j] = get(4 * i + 1, 4 * j + 1);     for (int j = 0; j < m; j++) {       can[j] = int(n % 2 == 0);       for (int i = 0; i < n; i++) can[j] &= int((g[i][j] & 2) != 0);     }     for (int j = 0; j + 1 < m; j++) {       memset(cnt, 0, sizeof(cnt));       cnt[0] = 1;       for (int i = 0; i < n; i++) {         if (g[i][j] & g[i][j + 1] & 1) cnt[i + 1] = (cnt[i + 1] + cnt[i]) % mod;         if (i + 1 < n &&             int(g[i][j] & g[i + 1][j] & g[i][j + 1] & g[i + 1][j + 1] & 2))           cnt[i + 2] = (cnt[i + 2] + cnt[i]) % mod;       }       can2[j] = (cnt[n] - can[j] * can[j + 1] + mod) % mod;     }     memset(res, 0, sizeof(res));     res[0] = 1;     for (int j = 0; j < m; j++) {       if (can[j]) res[j + 1] = (res[j + 1] + res[j]) % mod;       if (j + 1 < m)         res[j + 2] = (res[j + 2] + (long long)res[j] * can2[j]) % mod;     }     printf( %d n , res[m]);     return 0;   }