In the
Picasso painted the canvas using a special type of brushstroke, which he used an unknown (possibly zero) number of times. Each brushstroke consisted of the following: First, he chose a nonzero integer
Specifically, a horizontal flip reverses the order of the columns, while a vertical flip reverses the order of the rows.
You want to buy one of Picasso's masterpieces, however, it could be a fake. Given the original canvas
Constraints
Subtask 1 [30%]
Subtask 2 [70%]
No additional constraints.
Input Specification
The first line contains
The next
The last
Output Specification
Output YES
if NO
otherwise.
Sample Input 1
2 2
1 2
3 5
2 1
4 2
Sample Output 1
YES
Explanation for Sample 1
Picasso can perform
Sample Input 2
2 2
1 2
3 5
1 2
3 6
Sample Output 2
NO
Explanation for Sample 2
No sequence of moves can be performed which transforms
Sample Input 3
1 3
2 3 2
1 2 2
Sample Output 3
NO
Explanation for Sample 3
No sequence of moves can be performed which transforms
Comments