## 1) Concise, 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 (how the solution works)

### Key requirement reformulation
We need a set of pixels \(S\) such that for every pair of symbols \((a,b)\), there is some pixel \(p \in S\) with:
\[
symbol[a][p] \ne 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 \le 6\). The number of unordered pairs is:
\[
P = \binom{K}{2} \le \binom{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 \cdot M \le 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] = \bigvee_{i=0}^{P-1} [symbols[a_i][p] \ne symbols[b_i][p]] \cdot (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 \cdot 2^P \le 100 \cdot 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) Provided C++ solution with detailed line-by-line comments

```cpp
#include <bits/stdc++.h>
using namespace std;

// Pretty-printing for pairs (not essential to solving; just utility).
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

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

// Read a vector by reading each element in order.
template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for (auto& x: a) in >> x;
    return in;
}

// Print a vector separated by spaces (utility).
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for (auto x: a) out << x << ' ';
    return out;
}

int n, m, k;

// symbols[i] is the i-th symbol as a flat array of n*m booleans.
// We store each symbol’s pixels in row-major order.
vector<vector<bool>> symbols;

void read() {
    cin >> n >> m >> k;

    // Prepare storage for k symbols.
    symbols.resize(k);

    // For each symbol, read N strings of length M; flatten into symbols[i].
    for (int i = 0; i < k; i++) {
        symbols[i] = {};              // clear (not strictly necessary after resize)
        for (int j = 0; j < n; j++) {
            string s;
            cin >> s;                 // reads a row (skips whitespace/newlines automatically)
            for (char c: s) {
                symbols[i].push_back(c - '0'); // store each pixel as bool-like 0/1
            }
        }
    }
}

void solve() {
    // Total pixel count in the grid.
    int total = n * m;

    // Build list of all unordered pairs of symbols (a < b).
    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++;
        }
    }

    // Target mask with all pairs distinguished.
    int full_mask = (1 << pairs) - 1;

    // For each pixel position p, compute which symbol-pairs differ at that pixel.
    vector<int> pixel_mask(total); // bitmask over 'pairs' bits
    for (int p = 0; p < total; p++) {
        for (int i = 0; i < pairs; i++) {
            auto [a, b] = pair_list[i];
            // If symbols a and b differ at pixel p, then selecting p distinguishes this pair.
            if (symbols[a][p] != symbols[b][p]) {
                pixel_mask[p] |= (1 << i);
            }
        }
    }

    // dp[p][mask] = minimum number of selected pixels among first p pixels
    // achieving distinguished-pairs state 'mask'.
    // Initialize to large value total+1 (acts as INF).
    vector<vector<int>> dp(total + 1, vector<int>(full_mask + 1, total + 1));

    // prev_mask_of[p][mask] stores the previous mask used to reach dp[p][mask]
    // (to reconstruct which pixels were chosen).
    vector<vector<int>> prev_mask_of(total + 1, vector<int>(full_mask + 1, -1));

    // Base case: processed 0 pixels, distinguished nothing, used 0 pixels.
    dp[0][0] = 0;

    // Process pixels one by one.
    for (int p = 0; p < total; p++) {
        for (int mask = 0; mask <= full_mask; mask++) {

            // Skip unreachable states.
            if (dp[p][mask] > total) continue;

            // Option 1: do not take pixel p.
            // Mask stays the same, cost stays the same.
            if (dp[p + 1][mask] > dp[p][mask]) {
                dp[p + 1][mask] = dp[p][mask];
                prev_mask_of[p + 1][mask] = mask; // came from same mask
            }

            // Option 2: take pixel p.
            // New mask gains all pairs distinguished by this pixel.
            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; // came from old mask
            }
        }
    }

    // Reconstruct chosen pixels by backtracking from (total, full_mask).
    vector<bool> chosen(total, false);
    int mask = full_mask;

    for (int p = total; p > 0; p--) {
        int pm = prev_mask_of[p][mask]; // previous mask before processing pixel p-1

        // If the mask changed, then pixel (p-1) must have been chosen
        // (because skipping keeps mask unchanged).
        if (pm != mask) {
            chosen[p - 1] = true;
        }
        mask = pm; // move to previous state
    }

    // Output minimum number of pixels.
    cout << dp[total][full_mask] << '\n';

    // Output the chosen mask in N rows of M chars.
    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; // single test in this problem
    for (int test = 1; test <= T; test++) {
        read();
        solve();
    }
    return 0;
}
```

---

## 4) Python solution (same approach, with detailed comments)

```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=\binom{K}{2}\le 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.