49 lines
1.0 KiB
Java
49 lines
1.0 KiB
Java
package chelper;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import io.InputReader;
|
|
import io.OutputWriter;
|
|
import solutions.ChelperSolution;
|
|
|
|
|
|
public class TaskC extends ChelperSolution {
|
|
|
|
@Override
|
|
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
|
super.solve(testNumber, in, out);
|
|
}
|
|
|
|
@Override
|
|
public void solve(int testNumber) {
|
|
int n = in.nextInt();
|
|
int m = in.nextInt();
|
|
|
|
int[][] a = in.nextIntIntArray(n, m);
|
|
int[][] b = in.nextIntIntArray(n, m);
|
|
|
|
boolean ok = true;
|
|
|
|
for (int diag = 0; diag < n + m - 1; diag++) {
|
|
int startI = Math.min(diag, n - 1);
|
|
int startJ = Math.max(diag - startI, 0);
|
|
|
|
List<Integer> la = new ArrayList<>();
|
|
List<Integer> lb = new ArrayList<>();
|
|
for (int i = startI, j = startJ; i >= 0 && j < m; i--, j++) {
|
|
la.add(a[i][j]);
|
|
lb.add(b[i][j]);
|
|
}
|
|
|
|
Collections.sort(la);
|
|
Collections.sort(lb);
|
|
|
|
ok &= la.equals(lb);
|
|
}
|
|
|
|
out.println(ok ? "YES" : "NO");
|
|
}
|
|
}
|