#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
struct Node
{
Node* lchild;
Node* rchild;
int data;
};
void insert(Node* &root,int data)
{
if(root==NULL)
{
root=new Node;
root->lchild=NULL;
root->rchild=NULL;
root->data=data;
return;
}
if(data<root->data)
insert(root->lchild,data);
else
insert(root->rchild,data);
}//建树
vector<int> temp,pre,post,prem,postm;
void preorder(Node* root,vector<int> &pre)
{
if(root==NULL)
return;
pre.push_back(root->data);
preorder(root->lchild,pre);
preorder(root->rchild,pre);
}
void postorder(Node* root,vector<int> &post)
{
if(root==NULL)
return;
postorder(root->lchild,post);
postorder(root->rchild,post);
post.push_back(root->data);
}
void premorder(Node* root,vector<int> &prem)
{
if(root==NULL)
return;
prem.push_back(root->data);
premorder(root->rchild,prem);
premorder(root->lchild,prem);
}
void postmorder(Node* root,vector<int> &postm)
{
if(root==NULL)
return;
postmorder(root->rchild,postm);
postmorder(root->lchild,postm);
postm.push_back(root->data);
}
int main()
{
int n,k;
scanf("%d",&n);
Node* root=NULL;
for(int i=0;i<n;i++)
{
scanf("%d",&k);
insert(root,k);
temp.push_back(k);
}
preorder(root,pre);
premorder(root,prem);
if(temp==pre)
{
printf("YES\n");
postorder(root,post);
for(int i=0;i<post.size();i++)
{
printf("%d",post[i]);
if(i!=post.size()-1)
{
printf(" ");
}
}
}
else if(temp==prem)
{
printf("YES\n");
postmorder(root,postm);
for(int i=0;i<postm.size();i++)
{
printf("%d",postm[i]);
if(i!=postm.size()-1)
{
printf(" ");
}
}
}
else
printf("NO\n");
system("pause");
return 0;
}