#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int pre[N], in[N];
int res[N], cnt;
int n;
bool f = true;
bool build(int il, int ir, int pl, int pr, bool reverse)
{
if (il > ir) return true;
int root = pre[pl];
int l = il, r = ir;
// 本题数据范围小,二分看不出优势
if (!reverse)
{
while (l < r)
{
int mid = l + r >> 1;
if (in[mid] >= root) r = mid;
else l = mid + 1;
}
if (in[r] != root) return false;
}
else
{
while (l < r)
{
int mid = l + r + 1 >> 1;
if (in[mid] >= root) l = mid;
else r = mid - 1;
}
if (in[r] != root) return false;
}
if (!build(il, r - 1, pl + 1, pl + 1 + (r - 1 - il), reverse)) return false;
if (!build(r + 1, ir, pl + 1 + (r - 1 - il) + 1, pr, reverse)) return false;
res[cnt++] = root;
return true;
}
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &pre[i]), in[i] = pre[i];
sort(in, in + n);
if (build(0, n - 1, 0, n - 1, false))
{
puts("YES");
printf("%d", res[0]);
for (int i = 1; i < n; i++) printf(" %d", res[i]);
puts("");
}
else
{
cnt = 0;
reverse(in, in + n);
if (build(0, n - 1, 0, n - 1, true))
{
puts("YES");
printf("%d", res[0]);
for (int i = 1; i < n; i++) printf(" %d", res[i]);
puts("");
}
else puts("NO");
}
return 0;
}