Matrix Problem

Time Limit
2s
Memory Limit
32768KB
Judge Program
Standard
Ratio(Solve/Submit)
12.50%(1/8)
Description:

Captain Huang comes up with an idea when she studies the linear algebra. Two matrices A and B are given, each of them has size n*m. You can perform the following operation to matrix A unlimited number of times: take any square submatrix of A and transpose it (i.e. the element of the submatrix which was in the i-th row and j-th column of the submatrix will be in the j-th row and i-th column after transposing, and the transposed submatrix itself will keep its place in the matrix A).

Your task is to check whether it is possible to transform the matrix A to the matrix B.

Input:

The first line contains two integers n andm (1<=n,m<=500) which mean the size of the matrix.

Eachof the next n lines contains m integers represent matrix A (1<=Aij<=1e9).

Each of the nextn lines contains m integers represent matrix B (1<=Bij<=1e9).

Output:

Print YES if it is possible to transform A to B and NO otherwise.

Sample Input:
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Sample Output:
YES

Submit