Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an _n_ by _m_ grid of characters, where the character '_X_' denotes a part of the puzzle and '_._' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.
The puzzle pieces are very heavy, so Hongcow **cannot rotate or flip** the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also **cannot overlap**.
You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two '_X_' from different pieces can share the same position.
## Input
The first line of input will contain two integers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 500), the dimensions of the puzzle piece.
The next _n_ lines will describe the jigsaw piece. Each line will have length _m_ and will consist of characters '_._' and '_X_' only. '_X_' corresponds to a part of the puzzle piece, '_._' is an empty space.
It is guaranteed there is at least one '_X_' character in the input and that the '_X_' characters form a 4-connected region.
## Output
Output "_YES_" if it is possible for Hongcow to make a rectangle. Output "_NO_" otherwise.
[samples]
## Note
For the first sample, one example of a rectangle we can form is as follows
111222
111222
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
.....
..XX.
.....
.....
.....
Hongcow 喜欢解谜题。
一天,Hongcow 找到了两个完全相同的拼图块,旁边写着说明:“组成一个矩形”。这些拼图块可以用一个 #cf_span[n] 行 #cf_span[m] 列的字符网格来描述,其中字符 '_X_' 表示拼图的一部分,'_._' 表示网格中的空位。保证拼图块是一个 4-连通的整体。具体细节请参见输入格式和样例,了解拼图块的表示方式。
拼图块非常重,因此 Hongcow *不能旋转或翻转* 拼图块。但他可以将它们向任意方向移动。拼图块 *不能重叠*。
你将获得其中一个拼图块的描述。请判断是否可以用两个与输入完全相同的副本组成一个矩形。矩形必须是实心的,即内部或边界上都不能有空洞。请注意,Hongcow 不允许翻转或旋转拼图块,且它们不能重叠,即来自不同拼图块的两个 '_X_' 不能占据相同的位置。
输入的第一行包含两个整数 #cf_span[n] 和 #cf_span[m](#cf_span[1 ≤ n, m ≤ 500]),表示拼图块的尺寸。
接下来的 #cf_span[n] 行将描述该拼图块。每行长度为 #cf_span[m],仅由字符 '_._' 和 '_X_' 组成。'_X_' 对应拼图块的一部分,'_._' 是空位。
保证输入中至少有一个 '_X_' 字符,且所有 '_X_' 字符构成一个 4-连通区域。
如果 Hongcow 能够组成一个矩形,则输出 "_YES_";否则输出 "_NO_"。
对于第一个样例,我们可以组成的一个矩形示例如下:
对于第二个样例,不旋转或翻转拼图块的情况下,无法将两个这样的块组合成矩形。
在第三个样例中,我们可以将第一个拼图块向右平移一格,然后组合成如下矩形:
## Input
输入的第一行包含两个整数 #cf_span[n] 和 #cf_span[m](#cf_span[1 ≤ n, m ≤ 500]),表示拼图块的尺寸。接下来的 #cf_span[n] 行将描述该拼图块。每行长度为 #cf_span[m],仅由字符 '_._' 和 '_X_' 组成。'_X_' 对应拼图块的一部分,'_._' 是空位。保证输入中至少有一个 '_X_' 字符,且所有 '_X_' 字符构成一个 4-连通区域。
## Output
如果 Hongcow 能够组成一个矩形,则输出 "_YES_";否则输出 "_NO_"。
[samples]
## Note
对于第一个样例,我们可以组成的一个矩形示例如下:
111222
111222
对于第二个样例,不旋转或翻转拼图块的情况下,无法将两个这样的块组合成矩形。
在第三个样例中,我们可以将第一个拼图块向右平移一格,然后组合成如下矩形:
.......
XX.....
.......
.......
.......
Given a binary $ n \times m $ grid $ P $, where each cell is either $ 1 $ (denoting a puzzle piece part) or $ 0 $ (empty), and the set of $ 1 $'s forms a 4-connected region, determine whether there exists a translation vector $ \vec{v} = (dx, dy) \in \mathbb{Z}^2 \setminus \{(0,0)\} $ such that:
- The translated copy $ P + \vec{v} $ does not overlap with $ P $:
$$
\forall (i,j),\ P[i][j] = 1 \Rightarrow (P[i][j] = 1 \text{ and } P[i+dx][j+dy] = 1) = \emptyset
$$
- The union $ P \cup (P + \vec{v}) $ forms a solid rectangle (i.e., a contiguous axis-aligned rectangular region with no holes and all cells filled):
Let $ R $ be the minimal axis-aligned bounding box of $ P \cup (P + \vec{v}) $. Then:
$$
|P \cup (P + \vec{v})| = |R|
$$
and
$$
R \text{ is a rectangle: } R = [a, a + h - 1] \times [b, b + w - 1] \text{ for some } a,b,h,w \in \mathbb{Z}, h,w \geq 1
$$
where $ |P| $ denotes the number of $ 1 $'s in $ P $, and $ |P \cup (P + \vec{v})| = 2|P| $ since no overlap.
**Objective:**
Determine whether such a $ \vec{v} $ exists.
---
**Formal Statement:**
Let $ P \subseteq \{0, \dots, n-1\} \times \{0, \dots, m-1\} $ be the set of positions where $ P[i][j] = 1 $, with $ |P| = k > 0 $, and $ P $ is 4-connected.
Does there exist $ \vec{v} = (dx, dy) \in \mathbb{Z}^2 \setminus \{(0,0)\} $ such that:
1. $ P \cap (P + \vec{v}) = \emptyset $,
2. Let $ S = P \cup (P + \vec{v}) $, and let $ R $ be the minimal axis-aligned rectangle containing $ S $,
3. Then $ |S| = |R| $, i.e., $ S = R $ (no holes, fully filled rectangle).
Output "YES" if such $ \vec{v} $ exists; otherwise "NO".