func_code_string: #include <bits/stdc++.h>   using namespace std;   bool grid[3][10004];   int n;   long long dp[10004][8];   long long calc(int i, int mask) {     int mask2 = 0;     if (grid[0][i]) mask2 |= 1;     if (grid[1][i]) mask2 |= 2;     if (grid[2][i]) mask2 |= 4;     if ((mask & mask2) != 0) {       return 0;     }     mask |= mask2;     long long ret = dp[i][mask];     if (ret != -1) {       return ret;     }     if (i == n - 1) {       if (mask == 1 || mask == 4 || mask == 7) {         return 1;       } else         return 0;     }     switch (mask) {       case 0:         ret = calc(i + 1, 4);         ret += calc(i + 1, 1);         ret += calc(i + 1, 7);         ret %= 1000000007;         break;       case 1:         ret = calc(i + 1, 6);         ret += calc(i + 1, 0);         ret %= 1000000007;         break;       case 2:         ret = calc(i + 1, 5);         break;       case 3:         ret = calc(i + 1, 4);         break;       case 4:         ret = calc(i + 1, 3);         ret += calc(i + 1, 0);         ret %= 1000000007;         break;       case 5:         ret = calc(i + 1, 2);         break;       case 6:         ret = calc(i + 1, 1);         break;       case 7:         ret = calc(i + 1, 0);         break;       default:         break;     }     dp[i][mask] = ret;     return ret;   }   int main() {     cin >> n;     string a, b, c;     cin >> a >> b >> c;     memset(grid, true, sizeof grid);     memset(dp, -1, sizeof dp);     for (int i = 0; i < n; i++) {       if (a[i] ==  . ) {         grid[0][i] = false;       }     }     for (int i = 0; i < n; i++) {       if (b[i] ==  . ) {         grid[1][i] = false;       }     }     for (int i = 0; i < n; i++) {       if (c[i] ==  . ) {         grid[2][i] = false;       }     }     if (a.find( O ) == string::npos && c.find( O ) == string::npos &&         b.find( O ) != 0 && b.find( O ) != n - 1) {       long long x = calc(0, 0);       int p = b.find( O );       memset(dp, -1, sizeof dp);       grid[1][p - 1] = true;       grid[2][p - 1] = true;       grid[0][p + 1] = true;       grid[1][p + 1] = true;       long long y = calc(0, 0);       grid[0][p - 1] = true;       grid[2][p - 1] = false;       grid[0][p + 1] = false;       grid[2][p + 1] = true;       memset(dp, -1, sizeof(dp));       long long z = calc(0, 0);       cout << (x - y - z + 1000000007 + 1000000007) % 1000000007 << endl;     } else {       cout << calc(0, 0) << endl;     }     return 0;   }   