#include<iostream>
#include<vector>
using namespace std;
int N;
vector<int> origin,post,postM,pre,preM;
struct node{
int val;
struct node *left,*right;
};
void insert(node* &root,int val){
if(root==NULL){
root=new node();
root->val=val;
root->left=root->right=NULL;
}else if(root->val<=val){
insert(root->right,val);
}else
insert(root->left,val);
}
void preOrder(node* root){
if(root==NULL) return;
pre.push_back(root->val);
preOrder(root->left);
preOrder(root->right);
}
void preMOrder(node* root){
if(root==NULL) return;
preM.push_back(root->val);
preMOrder(root->right);
preMOrder(root->left);
}
void postOrder(node* root){
if(root==NULL) return;
postOrder(root->left);
postOrder(root->right);
post.push_back(root->val);
}
void postMOrder(node *root){
if(root==NULL) return;
postMOrder(root->right);
postMOrder(root->left);
postM.push_back(root->val);
}
int main(){
node* root=NULL;
scanf("%d",&N);
origin.resize(N);
for(int i=0;i<N;i++){
scanf("%d",&origin[i]);
insert(root,origin[i]);
}
preOrder(root);
preMOrder(root);
if(pre==origin){
printf("YES\n");
postOrder(root);
for(int i=0;i<post.size();i++){
if(i!=0)
printf(" ");
printf("%d",post[i]);
}
}else if(preM==origin){
printf("YES\n");
postMOrder(root);
for(int i=0;i<postM.size();i++){
if(i!=0)
printf(" ");
printf("%d",postM[i]);
}
}else{
printf("NO\n");
}
}