#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } vector Zalgo(vector s){ int n=s.size(); vector a(n,0); int from=-1,last=-1; for(int i=1;i a,vector b,int n,int k) { if (a == b) { return true; } { auto v = a; auto vv = b; sort(v.begin(), v.end()); sort(vv.begin(), vv.end()); if (v != vv) return false; } if (k > n) { return false; } else if (k == n) { reverse(a.begin(), a.end()); return (a == b); } else if (k < n-1) { return true; } else { // k = n-1 vector v; for (int i = 0; i < n; ++i) { v.push_back(b[i]); } v.push_back(-1); for (int i = 0; i < n; ++i) { v.push_back(a[i]); } for (int i = 0; i < n; ++i) { v.push_back(a[i]); } v.push_back(-1); for (int i = 0; i < n; ++i) { v.push_back(a[n-1-i]); } for (int i = 0; i < n; ++i) { v.push_back(a[n-1-i]); } auto Z = Zalgo(v); for (int i = n; i < v.size(); ++i) { if (Z[i] >= n) return true; } return false; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n,k; cin >> n >> k; vector a(n),b(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { cin >> b[i]; } if (slv(a,b,n,k)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }