#abc300b. [abc300_b]Same Map in the RPG World
[abc300_b]Same Map in the RPG World
Problem Statement
Takahashi is developing an RPG. He has decided to write a code that checks whether two maps are equal.
We have grids and with horizontal rows and vertical columns. Each cell in the grid has a symbol #
or .
written on it.
The symbols written on the cell at the -th row from the top and -th column from the left in and are denoted by and , respectively.
The following two operations are called a vertical shift and horizontal shift.
- For each , simultaneously do the following:
- simultaneously replace with .
- For each , simultaneously do the following:
- simultaneously replace with .
Is there a pair of non-negative integers that satisfies the following condition? Print Yes
if there is, and No
otherwise.
- After applying a vertical shift times and a horizontal shift times, is equal to .
Here, is said to be equal to if and only if for all integer pairs such that and .
Constraints
- is
#
or.
, and so is . - and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if there is a conforming integer pair ; print No
otherwise.
Sample Input 1
4 3
..#
...
.#.
...
#..
...
.#.
...
Sample Output 1
Yes
By choosing , the resulting is equal to .
We describe the procedure when is chosen. Initially, is as follows.
..#
...
.#.
...
We first apply a vertical shift to make as follows.
...
.#.
...
..#
Then we apply another vertical shift to make as follows.
.#.
...
..#
...
Finally, we apply a horizontal shift to make as follows, which equals .
#..
...
.#.
...
Sample Input 2
3 2
##
##
#.
..
#.
#.
Sample Output 2
No
No choice of makes equal .
Sample Input 3
4 5
#####
.#...
.##..
..##.
...##
#...#
#####
...#.
Sample Output 3
Yes
Sample Input 4
10 30
..........##########..........
..........####....###.....##..
.....##....##......##...#####.
....####...##..#####...##...##
...##..##..##......##..##....#
#.##....##....##...##..##.....
..##....##.##..#####...##...##
..###..###..............##.##.
.#..####..#..............###..
#..........##.................
................#..........##.
######....................####
....###.....##............####
.....##...#####......##....##.
.#####...##...##....####...##.
.....##..##....#...##..##..##.
##...##..##.....#.##....##....
.#####...##...##..##....##.##.
..........##.##...###..###....
...........###...#..####..#...
Sample Output 4
Yes