#include #include #include #include using namespace std; typedef long long lint; typedef vectorvi; typedef pairpii; #define rep(i,n)for(int i=0;i<(int)(n);++i) // https://yukicoder.me/problems/3422 #define N 50000 int n; int c[N]; void f(){ cout<<"No"<=n-1)return 1; if(c[i+1]==c[i-1])return 0; return lint(c[i]-c[i+1])*(c[i]-c[i-1])>0; } // TLE int main(){ cin>>n; assert(n<=N); rep(i,n){cin>>c[i];assert(1<=c[i]&&c[i]<=n);} vi a; rep(i,n-2){ if(!kado(i+1)){ rep(j,3)a.push_back(i+j); } } assert(a.size()!=0); if(a.size()>=200)f(); rep(b,n){ rep(i,b){ if(b==i)continue; swap(c[i],c[b]); vi tt(a); rep(j,3)tt.push_back(i+j-1); rep(j,3)tt.push_back(b+j-1); int ok=1; for(int t:tt)if(!kado(t)){ok=0;break;} if(ok){cout<<"Yes"<