#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
int data;
node *left,*right;
} tree;
tree*create(tree*root,int x)
{
if(!root)
{
root=new node;
root->data=x;
root->right=root->left=NULL;
return root;
}
else
{
if(x<root->data)
{
root->left=create(root->left,x);
}
else
{
root->right=create(root->right,x);
}
return root;
}
}
int first1[1010];
int first2[1010];
int cnt1=0;
int cnt2=0;
int last1[1010];
int last2[1010];
int top1=0;
int top2=0;
int a[1010];
void first1_root(tree*root)
{
if(root)
{
first1[cnt1++]=root->data;
first1_root(root->left);
first1_root(root->right);
}
}
void first2_root(tree*root)
{
if(root)
{
first2[cnt2++]=root->data;
first2_root(root->right);
first2_root(root->left);
}
}
void last1_root(tree*root)
{
if(root)
{
last1_root(root->left);
last1_root(root->right);
last1[top1++]=root->data;
}
}
void last2_root(tree*root)
{
if(root)
{
last2_root(root->right);
last2_root(root->left);
last2[top2++]=root->data;
}
}
int main()
{
tree*root;
root=NULL;
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
int x;
scanf("%d",&x);
root=create(root,x);
a[i]=x;
}
int flag1=0;
int flag2=0;
first1_root(root);
first2_root(root);
for(int i=0; i<n; i++)
{
if(a[i]!=first1[i])
{
flag1=1;
}
if(a[i]!=first2[i])
{
flag2=1;
}
}
last1_root(root);
last2_root(root);
if(flag1==1&&flag2==1)
{
printf("NO\n");
}
else
{
printf("YES\n");
if(flag1==0)
{
for(int i=0; i<top1; i++)
{
if(i==top1-1)
{
printf("%d\n",last1[i]);
}
else
{
printf("%d ",last1[i]);
}
}
}
else if(flag2==0)
{
for(int i=0; i<top2; i++)
{
if(i==top2-1)
{
printf("%d\n",last2[i]);
}
else
{
printf("%d ",last2[i]);
}
}
}
}
return 0;
}