OI I - pio

#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

// map (r,c) -> index 0..63 in row-major
inline int idx(int r, int c) {
    return r * 8 + c;
}

struct GaussSolver {
    // A: 64x64 matrix over GF(2). rows as ull (bits 0..63).
    // Solve A x = b (b is 64-bit vector of RHS). Return (is_solvable, minimal_solution_mask, min_weight)
    // If multiple solutions, searches all by enumerating nullspace if nullity <= MAX_ENUM.
    static const int MAX_ENUM = 26; // 2^26 enumeracja dokładna

    static tuple<bool, ull, int> solve(ull A_rows[64], ull bvec) {
        // copy
        ull mat[64];
        int rhs[64];
        for (int i = 0; i < 64; i++) {
            mat[i] = A_rows[i];
            rhs[i] = ((bvec >> i) & 1);
        }

        int row = 0;
        vector<int> where(64, -1); // which row is pivot for column
        for (int col = 0; col < 64 && row < 64; ++col) {
            int sel = -1;
            for (int i = row; i < 64; i++) {
                if ((mat[i] >> col) & 1ULL) {
                    sel = i;
                    break;
                }
            }
            if (sel == -1) continue;
            swap(mat[sel], mat[row]);
            swap(rhs[sel], rhs[row]);
            where[col] = row;
            // eliminate other rows
            for (int i = 0; i < 64; i++) {
                if (i != row && ((mat[i] >> col) & 1ULL)) {
                    mat[i] ^= mat[row];
                    rhs[i] ^= rhs[row];
                }
            }
            row++;
        }
        // check consistency
        for (int i = row; i < 64; i++) {
            if (mat[i] == 0 && rhs[i]) {
                return {false, 0ULL, -1};
            }
        }
        // Now compute particular solution by setting free vars = 0
        ull particular = 0ULL;
        for (int c = 0; c < 64; c++) {
            if (where[c] != -1) {
                int r = where[c];
                // value = rhs[r] - sum_{j>c} mat[r][j]*val[j] but free vars zero, and elimination made upper-triangular-ish,
                // because we eliminated all other rows earlier, we can compute directly:
                // mat[r] has 1 at col c and maybe others; but since we eliminated other rows, the system is reduced so just:
                // value = rhs[r] XOR (sum over j>c mat[r][j]*val[j]) but val[j] are zero for free vars >c since those are free and set to zero,
                // and pivot columns >c have values computed later? Simpler approach: since we eliminated all other rows above/below, we can compute
                // by: evaluate sum of mat[r] & particular (excluding col c).
                ull rowmask = mat[r] & (~(1ULL << c));
                int s = 0;
                // parity of bits where both rowmask and particular have 1
                s = __builtin_parityll(rowmask & particular);
                int val = rhs[r] ^ s;
                if (val) particular |= (1ULL << c);
            }
        }
        // Build nullspace basis: for each free variable f, set that free var=1, others free=0, compute pivot values.
        vector<int> free_cols;
        for (int c = 0; c < 64; c++)
            if (where[c] == -1) free_cols.push_back(c);
        int d = (int)free_cols.size();
        vector<ull> basis;
        basis.reserve(d);
        for (int k = 0; k < d; k++) {
            int fcol = free_cols[k];
            ull vec = 0ULL;
            // free var fcol = 1
            vec |= (1ULL << fcol);
            // compute pivots
            for (int c = 0; c < 64; c++) {
                if (where[c] != -1) {
                    int r = where[c];
                    // value at pivot c = parity( mat[r] * vec ) (since homogeneous)
                    ull mask = mat[r];
                    int val = __builtin_parityll(mask & vec);
                    if (val) vec |= (1ULL << c);
                }
            }
            basis.push_back(vec);
        }

        // If nullity small -> enumerate all combos for minimal Hamming weight
        ull best_sol = 0ULL;
        int best_w = INT_MAX;
        if (d <= MAX_ENUM) {
            uint64_t total = 1ULL << d;
            for (uint64_t m = 0; m < total; m++) {
                ull cur = particular;
                // combine basis vectors according to bits of m
                uint64_t mm = m;
                int idxb = 0;
                while (mm) {
                    if (mm & 1ULL) cur ^= basis[idxb];
                    mm >>= 1;
                    idxb++;
                }
                int w = __builtin_popcountll(cur);
                if (w < best_w) {
                    best_w = w;
                    best_sol = cur;
                }
            }
            return {true, best_sol, best_w};
        } else {
            // if nullity large, do randomized local search to try find small-weight solution (heuristic fallback)
            // Start from particular, try flipping basis vectors greedily and random restarts
            best_sol = particular;
            best_w = __builtin_popcountll(particular);
            mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
            const int RESTARTS = 2000;
            for (int it = 0; it < RESTARTS; ++it) {
                ull cur = particular;
                // random initial combination: randomly include about half of free vars with small prob
                for (int k = 0; k < d; k++) {
                    if ((rng() & 7) == 0) cur ^= basis[k];
                }
                bool improved = true;
                int steps = 0;
                while (improved && steps < 500) {
                    improved = false;
                    steps++;
                    for (int k = 0; k < d; k++) {
                        ull cand = cur ^ basis[k];
                        int cw = __builtin_popcountll(cand);
                        if (cw < __builtin_popcountll(cur)) {
                            cur = cand;
                            improved = true;
                        }
                    }
                }
                int w = __builtin_popcountll(cur);
                if (w < best_w) {
                    best_w = w;
                    best_sol = cur;
                }
            }
            return {true, best_sol, best_w};
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<string> s(8);
    for (int i = 0; i < 8; i++) {
        if (!(cin >> s[i])) return 0;
        if ((int)s[i].size() != 8) {
            cerr << "Each line must have 8 characters\n";
            return 0;
        }
    }
    // map chars to bits: let's map 'C' -> 0, 'B' -> 1. If other letters, treat any char not 'C' as '1'
    ull start = 0ULL;
    for (int r = 0; r < 8; r++)
        for (int c = 0; c < 8; c++) {
            char ch = s[r][c];
            int bit = (ch == 'C') ? 0 : 1;
            if (bit) start |= (1ULL << idx(r, c));
        }
    // Build matrix A: A[row][col] = 1 if move at col flips cell row (i.e., row is neighbor of col)
    ull A_rows[64];
    for (int i = 0; i < 64; i++)
        A_rows[i] = 0ULL;
    for (int r = 0; r < 8; r++)
        for (int c = 0; c < 8; c++) {
            int col = idx(r, c); // move at (r,c)
            // neighbors of (r,c) excluding center
            for (int dr = -1; dr <= 1; ++dr)
                for (int dc = -1; dc <= 1; ++dc) {
                    if (dr == 0 && dc == 0) continue;
                    int nr = r + dr, nc = c + dc;
                    if (nr >= 0 && nr < 8 && nc >= 0 && nc < 8) {
                        int row = idx(nr, nc);
                        A_rows[row] |= (1ULL << col);
                    }
                }
        }
    // Two targets: all 0 -> b = start ; all 1 -> b = start ^ ones
    ull ones = ~0ULL;
    if (sizeof(ull) * 8 > 64) ones = ((1ULL << 64ULL) - 1ULL);
    ull b0 = start; // A x = start  => final all 0
    ull b1 = start ^ ones; // A x = start ^ 1 => final all 1

    auto [ok0, sol0, w0] = GaussSolver::solve(A_rows, b0);
    auto [ok1, sol1, w1] = GaussSolver::solve(A_rows, b1);

    bool choose0 = false;
    if (ok0 && ok1) {
        if (w0 <= w1)
            choose0 = true;
        else
            choose0 = false;
    } else if (ok0)
        choose0 = true;
    else if (ok1)
        choose0 = false;
    else {
        // no solution to either (theoretically shouldn't happen) -> print 0 moves
        cout << 0 << "\n\n";
        return 0;
    }

    ull sol = choose0 ? sol0 : sol1;
    int w = choose0 ? w0 : w1;

    // print result: first line minimal count, second line list of positions (1..64) in increasing order
    cout << w << "\n";
    bool first = true;
    for (int i = 0; i < 64; i++) {
        if ((sol >> i) & 1ULL) {
            if (!first) cout << " ";
            cout << (i + 1); // output 1-based index as required
            first = false;
        }
    }
    if (!first) cout << "\n";
    return 0;
}