#include #include #include #include #include struct UnionFind { std::vector par; UnionFind(const size_t n) : par(n, -1) {} int root(const size_t x) { return (par[x] < 0 ? x : par[x] = root(par[x])); } bool unite(size_t x, size_t y) { x = root(x); y = root(y); if (x == y) { return false; } if (par[x] > par[y]) { std::swap(x, y); } par[x] += par[y]; par[y] = x; return true; } inline bool same(const size_t x, const size_t y) { return root(x) == root(y); } }; int main() { int n, k; std::cin >> n >> k; UnionFind uf(n); for (int i = 0; i < n - k; i++) { uf.unite(i, i + k); } std::map pos; for (int i = 0; i < n; i++) { std::string tmp; std::cin >> tmp; pos[tmp] = i; } bool ng = false; for (int i = 0; i < n; i++) { std::string tmp; std::cin >> tmp; ng |= !uf.same(i, pos[tmp]); } std::cout << (ng ? "No" : "Yes"); }