#include #include #include using namespace std; int T,N; int A[50505]; bool f(int id) { int x=A[id],y=A[id+1],z=A[id+2]; return(xz||x>y&&y>T; for(;T--;) { cin>>N; for(int i=0;i>A[i]; vectorX; int out=0; for(int i=0;i+3<=N;i++)if(!f(i)) { out++; X.push_back(i); X.push_back(i+1); X.push_back(i+2); } sort(X.begin(),X.end()); X.erase(unique(X.begin(),X.end()),X.end()); bool fn=false; if(X.size()<=7) { for(int i:X)for(int j=0;jch; for(int k=-2;k<=2;k++) { if(i+k>=0&&i+k+3<=N)ch.push_back(i+k); if(j+k>=0&&j+k+3<=N)ch.push_back(j+k); } sort(ch.begin(),ch.end()); ch.erase(unique(ch.begin(),ch.end()),ch.end()); int now=out; for(int k:ch)now-=!f(k); swap(A[i],A[j]); for(int k:ch)now+=!f(k); if(now==0)fn=true; swap(A[i],A[j]); } } else if(X.size()<=100) { for(int i:X)for(int j:X)if(ich; for(int k=-2;k<=2;k++) { if(i+k>=0&&i+k+3<=N)ch.push_back(i+k); if(j+k>=0&&j+k+3<=N)ch.push_back(j+k); } sort(ch.begin(),ch.end()); ch.erase(unique(ch.begin(),ch.end()),ch.end()); int now=out; for(int k:ch)now-=!f(k); swap(A[i],A[j]); for(int k:ch)now+=!f(k); if(now==0)fn=true; swap(A[i],A[j]); } } cout<<(fn?"Yes":"No")<