//
// Created by song on 2023/7/2.
//
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
using i64 = long long;
const i64 inf = 0x3fffffffffffffff;
int main() {
fio;
i64 n, m;
cin >> n >> m;
vector<vector<i64>> A(n + m), B(n + m);
i64 num;
for (i64 i = 0; i < n; i++) {
for (i64 j = 0; j < m; j++) {
cin >> num;
A[i + j].emplace_back(num);
}
}
for (i64 i = 0; i < n; i++) {
for (i64 j = 0; j < m; j++) {
cin >> num;
B[i + j].emplace_back(num);
}
}
bool ans = true;
for (i64 i = 0; i < n + m; i++) {
sort(A[i].begin(), A[i].end());
sort(B[i].begin(), B[i].end());
if (A[i] != B[i]) {
ans = false;
break;
}
}
cout << (ans ? "YES" : "NO") << endl;
cerr << "Time : " << (double) clock() / (double) CLOCKS_PER_SEC << "s\n";
return 0;
}
1722D - Line | 1722C - Word Game |
1722G - Even-Odd XOR | 552E - Vanya and Brackets |
933A - A Twisty Movement | 1722F - L-shapes |
1196B - Odd Sum Segments | 1325D - Ehab the Xorcist |
552B - Vanya and Books | 1722E - Counting Rectangles |
168A - Wizards and Demonstration | 168B - Wizards and Minimal Spell |
7A - Kalevitch and Chess | 912B - New Year's Eve |
1537C - Challenging Cliffs | 879B - Table Tennis |
1674E - Breaking the Wall | 1282A - Temporarily unavailable |
1366C - Palindromic Paths | 336A - Vasily the Bear and Triangle |
926A - 2-3-numbers | 276D - Little Girl and Maximum XOR |
1253C - Sweets Eating | 1047A - Little C Loves 3 I |
758D - Ability To Convert | 733A - Grasshopper And the String |
216A - Tiling with Hexagons | 1351B - Square |
1225A - Forgetting Things | 1717A - Madoka and Strange Thoughts |