problem
solution
codes
#include<cstdio>
int n, a[(int)1e5+10];
int readint(){
int op=1,x=0; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')op=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
return op*x;
}
bool check(int dir){
int cnt = 0;
for(int i = 2; i <= n; i++, dir=!dir){
if(a[i]==a[i-1])continue;
if((a[i]<a[i-1]) == dir)continue;
if(++cnt >= 2)return false;
else i++,dir=!dir;
}
return true;
}
int main(){
while(scanf("%d",&n)==1){
for(int i = 1; i <= n; i++)a[i]=readint();
printf("%s
",n<=3||check(0)||check(1)?"Yes":"No");
}
return 0;
}