#abc298b. [abc298_b]Coloring Matrix
[abc298_b]Coloring Matrix
Problem Statement
You are given -by- matrices and where each element is or .
Let and denote the element at the -th row and -th column of and , respectively.
Determine whether it is possible to rotate so that for every pair of integers such that .
Here, to rotate is to perform the following operation zero or more times:
- for every pair of integers such that , simultaneously replace with .
Constraints
- Each element of and is or .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
If it is possible to rotate so that for every pair of integers such that , print Yes
; otherwise, print No
.
Sample Input 1
3
0 1 1
1 0 0
0 1 0
1 1 0
0 0 1
1 1 1
Sample Output 1
Yes
Initially, is :
0 1 1
1 0 0
0 1 0
After performing the operation once, is :
0 1 0
1 0 1
0 0 1
After performing the operation once again, is :
0 1 0
0 0 1
1 1 0
Here, for every pair of integers such that , so you should print Yes
.
Sample Input 2
2
0 0
0 0
1 1
1 1
Sample Output 2
Yes
Sample Input 3
5
0 0 1 1 0
1 0 0 1 0
0 0 1 0 1
0 1 0 1 0
0 1 0 0 1
1 1 0 0 1
0 1 1 1 0
0 0 1 1 1
1 0 1 0 1
1 1 0 1 0
Sample Output 3
No