There is a rectangular grid of _n_ rows of _m_ initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the _i_\-th operation, a non-empty subset of rows _R__i_ and a non-empty subset of columns _C__i_ are chosen. For each row _r_ in _R__i_ and each column _c_ in _C__i_, the intersection of row _r_ and column _c_ is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (_i_, _j_) (_i_ < _j_) exists such that or , where denotes intersection of sets, and denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
## Input
The first line contains two space-separated integers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following _n_ lines contains a string of _m_ characters, each being either '_._' (denoting a white cell) or '_#_' (denoting a black cell), representing the desired setup.
## Output
If the given grid can be achieved by any valid sequence of operations, output "_Yes_"; otherwise output "_No_" (both without quotes).
You can print each character in any case (upper or lower).
[samples]
## Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<center></center>For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Let $ G \in \{0,1\}^{n \times m} $ be the given grid, where $ G_{r,c} = 1 $ if cell $ (r,c) $ is black, and $ 0 $ if white.
Let $ \mathcal{R} = \{R_1, R_2, \dots, R_k\} $ be a collection of non-empty subsets of rows $ \{1, 2, \dots, n\} $, and $ \mathcal{C} = \{C_1, C_2, \dots, C_k\} $ be a collection of non-empty subsets of columns $ \{1, 2, \dots, m\} $, for some $ k \geq 0 $, such that:
- For all $ i \neq j $, $ R_i \cap R_j = \emptyset $ and $ C_i \cap C_j = \emptyset $ (each row and each column is used in at most one operation).
The grid $ G $ is produced if and only if:
$$
G_{r,c} = 1 \iff \exists\, i \text{ such that } r \in R_i \text{ and } c \in C_i.
$$
**Objective:** Determine whether such collections $ \mathcal{R}, \mathcal{C} $ exist.
---
**Equivalent characterization:**
Define:
- $ \mathcal{R}^* = \{ r \in [n] \mid \exists c \in [m], G_{r,c} = 1 \} $ — rows with at least one black cell.
- $ \mathcal{C}^* = \{ c \in [m] \mid \exists r \in [n], G_{r,c} = 1 \} $ — columns with at least one black cell.
For each row $ r \in \mathcal{R}^* $, define its *pattern*: $ P_r = \{ c \in [m] \mid G_{r,c} = 1 \} $.
For each column $ c \in \mathcal{C}^* $, define its *pattern*: $ Q_c = \{ r \in [n] \mid G_{r,c} = 1 \} $.
**Necessary and sufficient condition:**
There exists a partition of $ \mathcal{R}^* $ into disjoint non-empty subsets $ R_1, \dots, R_k $, and a partition of $ \mathcal{C}^* $ into disjoint non-empty subsets $ C_1, \dots, C_k $, such that for all $ i \in [k] $:
$$
\forall r \in R_i,\ \forall c \in C_i,\ G_{r,c} = 1,
$$
and
$$
\forall r \in R_i,\ P_r = C_i,
\quad
\forall c \in C_i,\ Q_c = R_i.
$$
In other words:
All rows in a group $ R_i $ must have *identical* black patterns, equal to $ C_i $,
and all columns in a group $ C_i $ must have *identical* black patterns, equal to $ R_i $.
Equivalently, define an equivalence relation on rows:
$ r \sim r' \iff P_r = P_{r'} $,
and on columns:
$ c \sim c' \iff Q_c = Q_{c'} $.
Then, the grid is realizable if and only if:
- The set of distinct row patterns $ \{P_r \mid r \in \mathcal{R}^*\} $ is in bijection with the set of distinct column patterns $ \{Q_c \mid c \in \mathcal{C}^*\} $,
- And for each distinct row pattern $ P $, the set of rows with pattern $ P $ is exactly the set of columns whose pattern is the corresponding column pattern $ Q $, and vice versa.
More precisely:
Let $ \mathcal{P} = \{ P_1, P_2, \dots, P_k \} $ be the distinct row patterns.
Let $ \mathcal{Q} = \{ Q_1, Q_2, \dots, Q_k \} $ be the distinct column patterns.
Then, there exists a bijection $ f: \mathcal{P} \to \mathcal{Q} $ such that:
- For every row $ r $ with pattern $ P_i $, the set of columns where it is black is $ P_i $,
- For every column $ c $ with pattern $ Q_j $, the set of rows where it is black is $ Q_j $,
- And $ f(P_i) = Q_j \iff P_i = Q_j $ as sets? Not exactly.
Wait — better:
Let $ S_i \subseteq \mathcal{R}^* $ be the set of rows with pattern $ P_i $.
Let $ T_j \subseteq \mathcal{C}^* $ be the set of columns with pattern $ Q_j $.
Then, the grid is realizable **iff**:
- The number of distinct row patterns equals the number of distinct column patterns: $ |\mathcal{P}| = |\mathcal{Q}| = k $,
- And there exists a bijection $ \sigma: \{1,\dots,k\} \to \{1,\dots,k\} $ such that for all $ i $:
$$
\bigcup_{r \in S_i} P_r = T_{\sigma(i)}, \quad \text{and} \quad \bigcup_{c \in T_{\sigma(i)}} Q_c = S_i.
$$
But since all rows in $ S_i $ have the same pattern $ P_i $, we have $ \bigcup_{r \in S_i} P_r = P_i $.
Similarly, $ \bigcup_{c \in T_j} Q_c = Q_j $.
So the condition simplifies to:
> There exists a bijection $ \sigma: \mathcal{P} \to \mathcal{Q} $ such that for each row pattern $ P \in \mathcal{P} $,
> $$
> \sigma(P) = \{ c \in [m] \mid \exists r \text{ with } P_r = P \text{ and } G_{r,c} = 1 \} = P,
> $$
> and for each column pattern $ Q \in \mathcal{Q} $,
> $$
> \sigma^{-1}(Q) = \{ r \in [n] \mid \exists c \text{ with } Q_c = Q \text{ and } G_{r,c} = 1 \} = Q.
> $$
Wait — this implies $ P = \sigma(P) $, so $ \mathcal{P} = \mathcal{Q} $ as sets of sets.
Actually, we must have:
For each row pattern $ P $, the set of columns where *any* row with pattern $ P $ is black is exactly $ P $.
But those columns must form a single group $ C_i $, and their column patterns must all be equal to the set of rows with pattern $ P $, i.e., $ Q_c = \{ r \mid P_r = P \} $ for all $ c \in P $.
So:
Let $ S_P = \{ r \in [n] \mid P_r = P \} $ — the set of rows with pattern $ P $.
Let $ T_P = P $ — the set of columns where those rows are black.
Then, for each column $ c \in T_P $, we must have $ Q_c = S_P $.
Therefore, the condition is:
> For every distinct row pattern $ P $,
> the set of columns $ c $ with $ G_{r,c} = 1 $ for some (hence all) $ r \in S_P $ is exactly $ P $,
> and for every column $ c \in P $, its pattern $ Q_c $ is exactly $ S_P $.
Thus, the grid is realizable **iff**:
- For every row $ r $, define $ P_r = \{ c \mid G_{r,c} = 1 \} $,
- For every column $ c $, define $ Q_c = \{ r \mid G_{r,c} = 1 \} $,
- Then, for any two rows $ r_1, r_2 $:
$$
P_{r_1} = P_{r_2} \iff Q_c = Q_{c'} \text{ for all } c \in P_{r_1}, c' \in P_{r_2},
$$
and
$$
\text{if } P_{r_1} = P_{r_2}, \text{ then } \forall c \in P_{r_1},\ Q_c = \{ r \mid P_r = P_{r_1} \}.
$$
In other words:
**Final formal condition:**
Let $ \mathcal{P} = \{ P_r \mid r \in [n], P_r \neq \emptyset \} $,
and for each $ P \in \mathcal{P} $, define $ S_P = \{ r \in [n] \mid P_r = P \} $.
Then, for every $ P \in \mathcal{P} $ and every $ c \in P $, it must hold that:
$$
Q_c = S_P.
$$
Additionally, every column $ c $ with $ G_{r,c} = 1 $ for some $ r $ must satisfy $ Q_c \in \{ S_P \mid P \in \mathcal{P} \} $, and every such $ S_P $ must be equal to $ Q_c $ for some $ c \in P $.
Thus, the grid is realizable **if and only if**:
$$
\boxed{
\forall c \in [m],\ \exists P \in \mathcal{P} \text{ such that } c \in P \text{ and } Q_c = S_P
}
$$
And since $ P = \{ c \mid G_{r,c} = 1 \} $ for any $ r \in S_P $, this is well-defined.
**Algorithmic check:**
1. For each row $ r $, compute $ P_r = \{ c \mid G_{r,c} = 1 \} $.
2. For each column $ c $, compute $ Q_c = \{ r \mid G_{r,c} = 1 \} $.
3. Let $ \mathcal{P} = \{ P_r \mid P_r \neq \emptyset \} $.
4. For each distinct non-empty pattern $ P \in \mathcal{P} $:
- Let $ S_P = \{ r \mid P_r = P \} $.
- For every column $ c \in P $, check that $ Q_c = S_P $.
5. Also, ensure that every column $ c $ with $ Q_c \neq \emptyset $ appears in some $ P \in \mathcal{P} $ (i.e., $ \exists r $ such that $ G_{r,c} = 1 $), which is already implied.
6. If all such checks pass, output "Yes"; else, "No".
This is the formal characterization.