#include using namespace std; typedef long long ll; typedef pair PP; //#define MOD 1000000007 #define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define ALL(v) (v).begin(), (v).end() #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false int main(void){ //cin.tie(nullptr); //ios::sync_with_stdio(false); ll N,K; cin >> N >> K; vector A(N),B(N); REP(i,N){cin >> A[i];} REP(i,N){cin >> B[i];} vector sA = A,sB = B; sort(ALL(sA)); sort(ALL(sB)); if(sA!=sB){ cout << "No" << endl; return 0; } vector rB = B;reverse(ALL(rB)); if(K<=N-2){ cout << "Yes" << endl; return 0; } if(K==N){ if(A==B || A==rB){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; } ll k = -1; REP(i,N){ if(A[i]==B[0]){ k = i; } } vector cA = A; REP(i,N){ cA[i] = A[(i+k)%N]; } if(cA == B){ cout << "Yes" << endl; return 0; } k = -1; REP(i,N){ if(A[i]==rB[0]){ k = i; } } REP(i,N){ cA[i] = A[(i+k)%N]; } if(cA == rB){ cout << "Yes" << endl; return 0; } cout << "No" << endl; /*ll N = 5,K = 3; cin >> N >> K; map,ll> ind; ll now = 0; vector d(N); REP(i,N){d[i] = i;} do{ ind[d] = now; now++; }while(next_permutation(ALL(d))); queue> que; vector enqueued(now,false); REP(i,N){d[i] = i;} que.push(d); enqueued[ind[d]] = true; while(!que.empty()){ vector t = que.front(); que.pop(); for(ll l=0;l R = t; for(ll e=l;e<=r;e++){ R[e] = t[l+r-e]; } if(!enqueued[ind[R]]){ que.push(R); enqueued[ind[R]] = true; } } } } REP(i,N){d[i] = i;} ll c = 0; do{ if(enqueued[ind[d]]){ REP(i,N){ cout << d[i] << " "; } cout << endl; c++; } }while(next_permutation(ALL(d))); cout << c MM (now-c) << endl;*/ return 0; }