#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 class rollinghash{ /* Copyright (c) 2022 0214sh7 https://github.com/0214sh7/library/ */ private: static constexpr long long mod = (1LL << 61)-1; std::vector Base = {12345,10000000}; std::vector BaseInv; std::vector> BaseInvExp; static constexpr long long h = 100; long long product(long long a,long long b){ static constexpr long long m = 1LL << 31; long long a1 = a/m,a2 = a%m; long long b1 = b/m,b2 = b%m; long long r = 0 , s; r = (r + 2*a1*b1) % mod; s = (a1*b2 + b1*a2) % mod; long long s1 = s/m,s2 = s%m; s = (2*s1+m*s2) % mod; r = (r + s) % mod; r = (r + a2*b2) % mod; return r; } long long power(long long b,long long e){ long long r=1; while(e){ if(e&1){ r=product(r,b)%mod; } b=product(b,b)%mod; e >>=1; } return r; } public: std::vector S; std::vector> H,Hsum; void init(std::vector cs){ S=cs; int n=S.size(); BaseInv.resize(Base.size()); BaseInvExp.resize(Base.size()); H.resize(Base.size()); Hsum.resize(Base.size()); for(int i=0;i S){ init(S); } std::vector get(int l,int r){ std::vector R(Base.size()); for(int i=0;i instant(std::vector P){ std::vector R; for(int i=0;i connect(std::vector P,long long ps,std::vector Q,long long qs){ std::vector R; for(int i=0;i> 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; } if(K>N){ if(A==B){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; } rollinghash ROL(A); vector hB = ROL.instant(B),hrB = ROL.instant(rB); //REP(i,hB.size()){cout << hB[i] << " ";}cout << Endl; //REP(i,hB.size()){cout << hrB[i] << " ";}cout << Endl;cout << Endl; REP(i,N){ vector S = ROL.get(0,i),T = ROL.get(i,N); vector R = ROL.connect(T,N-i,S,i); //REP(i,hB.size()){cout << R[i] << " ";}cout << Endl; if(R==hB || R==hrB){ 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; }