#include<iostream>
#include<vector>
using namespace std;
bool isMirror;
vector<int>pre,post;
void getpost(int root,int tail){
if(root>tail)return;
int i=root+1,j=tail;
//按普通情况处理
if(!isMirror){
//左子树
while(i<=tail&&pre[i]<pre[root])i++;
//右子树
while(j>root&&pre[j]>=pre[root])j--;
}else{
//左子树
while(i<=tail&&pre[i]>=pre[root])i++;
//右子树
while(j>root&&pre[j]<pre[root])j--;
}
if(i-j!=1){
return;
}
//处理左子树
getpost(root+1,j);
//处理右子树
getpost(i,tail);
post.push_back(pre[root]);
}
int main(){
int n;
cin>>n;
pre.resize(n);
for(int i=0;i<n;i++){
cin>>pre[i];
}
isMirror=false;
getpost(0,n-1);
if(post.size()!=n){
isMirror=true;
post.clear();
getpost(0,n-1);
}
if(post.size()==n){
cout<<"YES"<<endl;
cout<<post[0];
for(int i=1;i<n;i++){
cout<<" "<<post[i];
}
}else{
cout<<"NO"<<endl;
}
return 0;
}
仙桃市网站建设_网站建设公司_Banner设计_seo优化