1. Abridged Problem Statement

Given K (2…6) distinct monochrome symbols, each drawn on an N×M grid (N,M ≤ 10) as 0/1, choose a minimum-size set of pixel positions such that for every pair of symbols, there exists at least one chosen pixel where the two symbols have different values.

Output the minimum size and any N×M mask (1 = chosen pixel) achieving it.

2. Detailed Editorial

Key requirement reformulation
We need a set of pixels S such that for every pair of symbols (a,b), there is some pixel p ∈ S with symbol[a][p] ≠ symbol[b][p]. So each pair of symbols must be “separated” by at least one chosen pixel.

Observation: very small number of symbol pairs
K ≤ 6. The number of unordered pairs is P = C(K,2) ≤ C(6,2) = 15.
We can represent “which pairs are already separated” by a bitmask of length P.
- bit i = 1 means pair i has already been distinguished by the chosen pixels so far.

Goal: reach full_mask = (1<<P)-1 with minimum chosen pixels.

Precomputation per pixel: which pairs it separates
Let total pixels be T = N·M ≤ 100. Index pixels linearly p = 0..T-1.

Enumerate all pairs (a,b) into pair_list of size P.

For each pixel p, compute pixel_mask[p] = OR over i of [symbols[a_i][p] ≠ symbols[b_i][p]] · (1<<i).
This mask tells which symbol-pairs become distinguished if we include pixel p.

Dynamic programming: minimum pixels to reach each pair-mask
DP over pixels in order:

- dp[p][mask] = minimum number of selected pixels among the first p pixels that achieves pair-distinguishability state mask.
- Initialize dp[0][0] = 0, others = INF.

Transition for pixel p (0-indexed):
1. Skip pixel:
   - dp[p+1][mask] = min(dp[p+1][mask], dp[p][mask])
2. Take pixel:
   - new_mask = mask | pixel_mask[p]
   - dp[p+1][new_mask] = min(dp[p+1][new_mask], dp[p][mask] + 1)

Answer is dp[T][full_mask].

Complexity:
- States: T · 2^P ≤ 100 · 2^15 = 3,276,800
- Transitions: constant per state
This fits easily.

Reconstructing the chosen pixel set
To output an actual mask, store parent info:
- prev_mask_of[p+1][mask'] = mask before processing pixel p that led to best dp[p+1][mask'].

Then backtrack from (T, full_mask) down to 0:
- If prev_mask != current_mask, that means the pixel was taken (because taking is the only way to change the mask).
- Mark that pixel as chosen.

Finally print the count and the N×M chosen mask.

3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, m, k;
vector<vector<bool>> symbols;

void read() {
    cin >> n >> m >> k;
    symbols.resize(k);
    for(int i = 0; i < k; i++) {
        symbols[i] = {};
        for(int j = 0; j < n; j++) {
            string s;
            cin >> s;
            for(char c: s) {
                symbols[i].push_back(c - '0');
            }
        }
    }
}

void solve() {
    // For problems like this it's often useful to define what exactly we are
    // looking for. Here we want each of the k symbols to be distinguishable,
    // meaning that for each pair of the C(k, 2), there should be at least one
    // selected pixel where the symbols differ. The key observation is that k <=
    // 6, implies that C(k, 2) <= 15. Therefore, 2^C(k, 2) isn't very large, and
    // we can do some approach that encodes the mask of pairs that are already
    // distinguishable. To finish it off, we can do a DP[position][mask], where
    // position <= n*m is the current pixel we are considering. We have two
    // options - either include the pixel at the current position, meaning that
    // some of the relationships will become "1", or skip it, keeping the
    // current mask. Note that we can precompute for each position, the mask it
    // will "or" / "|", so that each transition is in O(1). Overall, the time
    // complexity would be O(n * m * 2^C(k, 2)) which comfortably passes the
    // given constraints.

    int total = n * m;
    int pairs = 0;
    vector<pair<int, int>> pair_list;
    for(int a = 0; a < k; a++) {
        for(int b = a + 1; b < k; b++) {
            pair_list.push_back({a, b});
            pairs++;
        }
    }

    int full_mask = (1 << pairs) - 1;

    vector<int> pixel_mask(total);
    for(int p = 0; p < total; p++) {
        for(int i = 0; i < pairs; i++) {
            auto [a, b] = pair_list[i];
            if(symbols[a][p] != symbols[b][p]) {
                pixel_mask[p] |= (1 << i);
            }
        }
    }

    vector<vector<int>> dp(total + 1, vector<int>(full_mask + 1, total + 1));
    vector<vector<int>> prev_mask_of(total + 1, vector<int>(full_mask + 1, -1));
    dp[0][0] = 0;

    for(int p = 0; p < total; p++) {
        for(int mask = 0; mask <= full_mask; mask++) {
            if(dp[p][mask] > total) {
                continue;
            }
            if(dp[p + 1][mask] > dp[p][mask]) {
                dp[p + 1][mask] = dp[p][mask];
                prev_mask_of[p + 1][mask] = mask;
            }
            int new_mask = mask | pixel_mask[p];
            if(dp[p + 1][new_mask] > dp[p][mask] + 1) {
                dp[p + 1][new_mask] = dp[p][mask] + 1;
                prev_mask_of[p + 1][new_mask] = mask;
            }
        }
    }

    vector<bool> chosen(total, false);
    int mask = full_mask;
    for(int p = total; p > 0; p--) {
        int pm = prev_mask_of[p][mask];
        if(pm != mask) {
            chosen[p - 1] = true;
        }
        mask = pm;
    }

    cout << dp[total][full_mask] << '\n';
    for(int i = 0; i < total; i++) {
        cout << (chosen[i] ? '1' : '0');
        if((i + 1) % m == 0) {
            cout << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        solve();
    }

    return 0;
}
```

4. Python Solution

```python
import sys

def solve() -> None:
    data = sys.stdin.read().split()
    it = iter(data)

    # Read N, M, K
    n = int(next(it))
    m = int(next(it))
    k = int(next(it))

    total = n * m

    # Read K symbols, each consists of N strings of length M.
    # Store each symbol as a flat list of ints (0/1) of length total.
    symbols = []
    for _ in range(k):
        flat = []
        for _ in range(n):
            row = next(it)
            flat.extend(1 if c == '1' else 0 for c in row)
        symbols.append(flat)

    # Build list of all unordered symbol pairs (a<b).
    pair_list = []
    for a in range(k):
        for b in range(a + 1, k):
            pair_list.append((a, b))
    pairs = len(pair_list)                 # <= 15
    full_mask = (1 << pairs) - 1

    # Precompute for each pixel p: bitmask of which symbol pairs differ at p.
    pixel_mask = [0] * total
    for p in range(total):
        pm = 0
        for i, (a, b) in enumerate(pair_list):
            if symbols[a][p] != symbols[b][p]:
                pm |= (1 << i)
        pixel_mask[p] = pm

    INF = total + 1

    # dp[p][mask] = min selected pixels using first p pixels to achieve 'mask'.
    # Use a list of lists; size (total+1) x (full_mask+1).
    dp = [[INF] * (full_mask + 1) for _ in range(total + 1)]
    prev = [[-1] * (full_mask + 1) for _ in range(total + 1)]

    dp[0][0] = 0
    prev[0][0] = 0

    # Standard 0/1 DP over pixels.
    for p in range(total):
        for mask in range(full_mask + 1):
            cur = dp[p][mask]
            if cur >= INF:
                continue

            # Option 1: skip pixel p
            if dp[p + 1][mask] > cur:
                dp[p + 1][mask] = cur
                prev[p + 1][mask] = mask

            # Option 2: take pixel p
            new_mask = mask | pixel_mask[p]
            if dp[p + 1][new_mask] > cur + 1:
                dp[p + 1][new_mask] = cur + 1
                prev[p + 1][new_mask] = mask

    # Reconstruct which pixels were chosen by backtracking.
    chosen = [0] * total
    mask = full_mask
    for p in range(total, 0, -1):
        pm = prev[p][mask]
        # If mask changed, pixel p-1 was taken; otherwise it was skipped.
        if pm != mask:
            chosen[p - 1] = 1
        mask = pm

    # Output
    out = []
    out.append(str(dp[total][full_mask]))
    for i in range(n):
        row = chosen[i * m:(i + 1) * m]
        out.append("".join('1' if x else '0' for x in row))

    sys.stdout.write("\n".join(out))

if __name__ == "__main__":
    solve()
```

5. Compressed Editorial

- Need minimum pixel set that distinguishes every pair of K≤6 symbols.
- There are P=C(K,2)≤15 pairs ⇒ represent “distinguished pairs” as a bitmask of size P.
- For each pixel position p (≤100), precompute pixel_mask[p]: which pairs differ at p.
- DP over pixels: dp[p][mask] = min chosen pixels among first p pixels achieving mask. Transition by skipping p or taking p (OR with pixel_mask[p]).
- Answer is dp[total][full_mask].
- Reconstruct chosen pixels using stored previous mask; if mask changes at step, pixel was taken.
