#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
int preorder[N], inorder[N], postorder[N];
int n, index;
bool build(int pl, int pr, int il, int ir, int type)
{
if(il > ir) return true;
int root = preorder[pl];
bool res = true;
int k;
if(type == 1)
{
k = il;
while(inorder[k] != root && k <= ir)
k ++;
if(k > ir) return false;
}
else
{
k = ir;
while(inorder[k] != root && k >= il)
k --;
if(k < il) return false;
}
if(!build(pl + 1, pl + 1 + k - 1 - il, il, k - 1, type)) res = false;
if(!build(pl + k - il + 1, pr, k + 1, ir, type)) res = false;
postorder[index ++] = root;
return res;
}
int main()
{
cin >> n;
for(int i = 0; i < n; i ++) {
cin >> preorder[i];
inorder[i] = preorder[i];
}
sort(inorder, inorder + n);
if(!build(0, n - 1, 0, n - 1, 1)) //原树建立失败
{
index = 0;
reverse(inorder, inorder + n);
if(build(0, n - 1, 0, n - 1, 0))
{
cout << "YES" << endl;
cout << postorder[0];
for(int i = 1; i < n; i ++) cout << " " << postorder[i];
}
else cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
cout << postorder[0];
for(int i = 1; i < n; i ++) cout << " " << postorder[i];
}
return 0;
}
//build函数用while写的时候注意范围,
//while(inorder[k] != root && k <= ir) k <= ir不可以省略,否则一直执行下去