// MARK: - コード #include using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; // const ll MOD = 998244353; // using mint = modint998244353; const int dx[8] = {0, -1, 1, 0, -1, 1, -1, 1}; const int dy[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; template istream &operator>>(istream &is, vector &v) { for (auto &e : v) is >> e; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } #define reps(i, l, r) for (std::decay_t i##_right = (r), i = (l); i < i##_right; i++) #define rep(i, n) reps(i, 0, n) template inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;} template inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;} int main() { int N, K; cin >> N >> K; vector A(N), B(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> B[i]; map mp; rep(i, N) { string s = B[i]; mp[s] = i; } bool check = true; rep(i, N) { string s = A[i]; int B_index = mp.find(s)->second; if (abs(B_index - i) % K != 0) { check = false; break; } } if (check) { cout << "Yes" << endl; } else { cout << "No" << endl; } } /* MARK: - メモ */