- Time limit: 1.00 s
- Memory limit: 512 MB
You are given an matrix that contains the numbers . The number at the intersection of the -th row and -th column is . Your task is to sort the matrix by performing any of the following operations arbitrarily many times:
- Pick two rows and swap them.
- Pick two columns and swap them.
The matrix is considered sorted is for each pair cells , it holds that if . If then if . That is, sort the matrix like this:
1 2 3
4 5 6
7 8 9
Input
The first line contains a single integer : The size of the matrix.
The following lines describe the matrix: each line contains integers.
Output
Print "Yes" if the matrix can be sorted and "No" otherwise.
Constraints
Example 1
Input:
1 1
Output:
Yes
Example 2
Input:
3 6 5 4 3 2 1 9 8 7
Output:
Yes
Example 2
Input:
4 6 8 13 11 3 15 16 4 7 5 1 12 2 9 14 10
Output:
No