{"problem":{"name":"Same Map in the RPG World","description":{"content":"> Takahashi is developing an RPG. He has decided to write a code that checks whether two maps are equal. We have grids $A$ and $B$ with $H$ horizontal rows and $W$ vertical columns. Each cell in the ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc300_b"},"statements":[{"statement_type":"Markdown","content":"> Takahashi is developing an RPG. He has decided to write a code that checks whether two maps are equal.\n\nWe have grids $A$ and $B$ with $H$ horizontal rows and $W$ vertical columns. Each cell in the grid has a symbol `#` or `.` written on it.  \nThe symbols written on the cell at the $i$\\-th row from the top and $j$\\-th column from the left in $A$ and $B$ are denoted by $A_{i, j}$ and $B_{i, j}$, respectively.\nThe following two operations are called a **vertical shift** and **horizontal shift**.\n\n*   For each $j=1, 2, \\dots, W$, simultaneously do the following:\n    *   simultaneously replace $A_{1,j}, A_{2,j}, \\dots, A_{H-1, j}, A_{H,j}$ with $A_{2,j}, A_{3,j}, \\dots, A_{H,j}, A_{1,j}$.\n*   For each $i = 1, 2, \\dots, H$, simultaneously do the following:\n    *   simultaneously replace $A_{i,1}, A_{i,2}, \\dots, A_{i,W-1}, A_{i,W}$ with $A_{i, 2}, A_{i, 3}, \\dots, A_{i,W}, A_{i,1}$.\n\nIs there a pair of non-negative integers $(s, t)$ that satisfies the following condition? Print `Yes` if there is, and `No` otherwise.\n\n*   After applying a vertical shift $s$ times and a horizontal shift $t$ times, $A$ is equal to $B$.\n\nHere, $A$ is said to be equal to $B$ if and only if $A_{i, j} = B_{i, j}$ for all integer pairs $(i, j)$ such that $1 \\leq i \\leq H$ and $1 \\leq j \\leq W$.\n\n## Constraints\n\n*   $2 \\leq H, W \\leq 30$\n*   $A_{i,j}$ is `#` or `.`, and so is $B_{i,j}$.\n*   $H$ and $W$ are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$H$ $W$\n$A_{1,1}A_{1,2}\\dots A_{1,W}$\n$A_{2,1}A_{2,2}\\dots A_{2,W}$\n$\\vdots$\n$A_{H,1}A_{H,2}\\dots A_{H,W}$\n$B_{1,1}B_{1,2}\\dots B_{1,W}$\n$B_{2,1}B_{2,2}\\dots B_{2,W}$\n$\\vdots$\n$B_{H,1}B_{H,2}\\dots B_{H,W}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc300_b","tags":[],"sample_group":[["4 3\n..#\n...\n.#.\n...\n#..\n...\n.#.\n...","Yes\n\nBy choosing $(s, t) = (2, 1)$, the resulting $A$ is equal to $B$.  \nWe describe the procedure when $(s, t) = (2, 1)$ is chosen. Initially, $A$ is as follows.\n\n..#\n...\n.#.\n...\n\nWe first apply a vertical shift to make $A$ as follows.\n\n...\n.#.\n...\n..#\n\nThen we apply another vertical shift to make $A$ as follows.\n\n.#.\n...\n..#\n...\n\nFinally, we apply a horizontal shift to make $A$ as follows, which equals $B$.\n\n#..\n...\n.#.\n..."],["3 2\n##\n##\n#.\n..\n#.\n#.","No\n\nNo choice of $(s, t)$ makes $A$ equal $B$."],["4 5\n#####\n.#...\n.##..\n..##.\n...##\n#...#\n#####\n...#.","Yes"],["10 30\n..........##########..........\n..........####....###.....##..\n.....##....##......##...#####.\n....####...##..#####...##...##\n...##..##..##......##..##....#\n#.##....##....##...##..##.....\n..##....##.##..#####...##...##\n..###..###..............##.##.\n.#..####..#..............###..\n#..........##.................\n................#..........##.\n######....................####\n....###.....##............####\n.....##...#####......##....##.\n.#####...##...##....####...##.\n.....##..##....#...##..##..##.\n##...##..##.....#.##....##....\n.#####...##...##..##....##.##.\n..........##.##...###..###....\n...........###...#..####..#...","Yes"]],"created_at":"2026-03-03 11:01:14"}}