func_code_string: #include <bits/stdc++.h>   using namespace std;   int a[501][501], b[501][501], i, j, n, m, k;   int main() {     vector<int> vea;     vector<int> veb;     cin >> n >> m;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) cin >> a[i][j];     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) cin >> b[i][j];     }     for (i = 1; i <= n; i++) {       j = 1;       k = i;       while (true) {         vea.push_back(a[k][j]);         veb.push_back(b[k][j]);         k--;         j++;         if (k == 0 || j == m + 1) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (j = 0; j < vea.size(); j++) {         if (vea[j] != veb[j]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     for (i = 1; i <= n; i++) {       j = m;       k = i;       while (true) {         vea.push_back(a[k][j]);         veb.push_back(b[k][j]);         k++;         j--;         if (k == n + 1 || j == 0) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (j = 0; j < vea.size(); j++) {         if (vea[j] != veb[j]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     for (j = 1; j <= m; j++) {       i = 1;       k = j;       while (true) {         vea.push_back(a[i][k]);         veb.push_back(b[i][k]);         k--;         i++;         if (k == 0 || i == n + 1) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (i = 0; i < vea.size(); i++) {         if (vea[i] != veb[i]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     for (j = m; j >= 1; j--) {       i = n;       k = j;       while (true) {         vea.push_back(a[i][k]);         veb.push_back(b[i][k]);         k++;         i--;         if (k == m + 1 || i == 0) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (i = 0; i < vea.size(); i++) {         if (vea[i] != veb[i]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     cout <<  YES ;   }   